diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3c3629e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/index.js b/index.js new file mode 100644 index 0000000..69459f5 --- /dev/null +++ b/index.js @@ -0,0 +1,27 @@ +var express = require('express') +var logfmt = require('logfmt') +var translate = require('wikipedia-translator') +var wikipedias = require('wikipedias') +var app = express() + +app.configure(function() { + if (process.env.NODE_ENV !== "test") app.use(logfmt.requestLogger()); + app.use(app.router); + app.use('/', express.static('public')); + app.set('view engine', 'jade'); +}); + +app.get('/', function(req, res) { + res.render('index'); +}); + +app.get('/search', function(req, res) { + translate(req.query.q, function(err, translation) { + // res.json(translation); + translation.wikipedias = wikipedias; + console.log(wikipedias); + res.render('search', translation); + }) +}); + +app.listen(process.env.PORT || 5000) \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..edc9104 --- /dev/null +++ b/package.json @@ -0,0 +1,38 @@ +{ + "name": "translator", + "version": "0.0.0", + "description": "A website/webservice for displaying wikipedia word translations", + "main": "index.js", + "scripts": { + "start": "nodemon index.js", + "test": "mocha" + }, + "repository": { + "type": "git", + "url": "https://github.com/zeke/translator.git" + }, + "keywords": [ + "translation", + "words", + "language", + "scraping", + "wikipedia" + ], + "author": "zeke", + "license": "MIT", + "bugs": { + "url": "https://github.com/zeke/translator/issues" + }, + "homepage": "https://github.com/zeke/translator", + "devDependencies": { + "should": "~2.1.1", + "mocha": "~1.17.0" + }, + "dependencies": { + "logfmt": "~0.18.1", + "jade": "~1.1.4", + "express": "~3.4.7", + "wikipedia-translator": "~0.1.0", + "wikipedias": "~0.1.1" + } +} diff --git a/public/styles.css b/public/styles.css new file mode 100644 index 0000000..638b9a0 --- /dev/null +++ b/public/styles.css @@ -0,0 +1,57 @@ +*, *:before, *:after { + -moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box; + } + +body { + font-family: 'PT Sans', sans-serif; + /*font-family: "helvetica neue", helvetica;*/ + font-weight: bold; + margin: 0; + padding: 0; +} + +section { + padding: 20px; +} + +ul.translations { + margin: 0; + padding: 0; + list-style: none; +} + +ul.translations > li { + margin: 0; + padding: 20px 10px; + width: 280px; + float: left; +} + +a { + color: green; + text-decoration: none; +} + +h1 { + font-size: 72px; + margin: 0; + padding: 0; + line-height: 1.5; +} + +h2 { + line-height: 1; + font-size: 24px; + margin: 0; + padding: 0; +} + +span.lang { + line-height: 1; + display: block; + opacity: 0.5; + font-size: 14px; +} + + + diff --git a/views/index.jade b/views/index.jade new file mode 100644 index 0000000..820fa12 --- /dev/null +++ b/views/index.jade @@ -0,0 +1,5 @@ +extends layout + +block content + + h1 Wikipedia Translator \ No newline at end of file diff --git a/views/layout.jade b/views/layout.jade new file mode 100644 index 0000000..10ee12e --- /dev/null +++ b/views/layout.jade @@ -0,0 +1,13 @@ +doctype html +html + head + title Wikipedia Translator + link(rel='stylesheet', type='text/css', href='/styles.css') + link(href='//fonts.googleapis.com/css?family=PT+Sans:400,700' rel='stylesheet' type='text/css') + + script(src='https://code.jquery.com/jquery-2.0.3.min.js') + block head + + body + section + block content \ No newline at end of file diff --git a/views/search.jade b/views/search.jade new file mode 100644 index 0000000..ee37512 --- /dev/null +++ b/views/search.jade @@ -0,0 +1,13 @@ +extends layout + +block content + + h1= query + + ul.translations + each t in translations + li + h2 + a(href=t.href)= t.word + if wikipedias[t.lang] + span.lang= wikipedias[t.lang].language \ No newline at end of file