diff --git a/package.json b/package.json new file mode 100644 index 0000000..a77a7cf --- /dev/null +++ b/package.json @@ -0,0 +1,16 @@ +{ + "name": "exam", + "version": "1.0.0", + "description": "exam project", + "main": "./source/app.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "jiajiangxu", + "license": "ISC", + "dependencies": { + "ect": "^0.5.9", + "express": "^4.12.4", + "octonode": "^0.6.17" + } +} diff --git a/source/app.js b/source/app.js new file mode 100644 index 0000000..6e13ec7 --- /dev/null +++ b/source/app.js @@ -0,0 +1,59 @@ +// express +var express = require('express'); +var app = express(); + +// ect +var ect = require('ect')({ + watch: true, + root: __dirname + '/views', + ext: '.html' +}); + +// octonode +var github = require('octonode'); + +// constant +var PORT = 80; +var REPO = 'joyent/node'; + +// create ghrepo object +var client = github.client(); +var ghrepo = client.repo(REPO); + +// initialize app +app.engine('html', ect.render); +app.set('view engine', 'html'); +app.set('views', __dirname + '/views'); + +// middleware +app.use('/public', express.static(__dirname + '/public')); + +// // +app.get('/', function (req, res) { + ghrepo.commits(function (err, commits) { + if (err) { + console.log(err); + return; + } + res.render('commits', {title: 'commits', commits: commits}); + }); +}); + +// get author +app.get('/authors', function (req, res) { + ghrepo.contributors(function (err, contributors) { + if (err) { + console.log(err); + return; + } + res.render('contributors', {title: 'authors', contributors: contributors}); + }); +}); + +app.get('*', function (req, res) { + res.send('404'); +}) + +app.listen(PORT); + +console.log('server started at port 80'); diff --git a/source/public/css.css b/source/public/css.css new file mode 100644 index 0000000..c7ed2cb --- /dev/null +++ b/source/public/css.css @@ -0,0 +1,27 @@ +table{ + border-collapse:collapse; +} + +table td{ + border:1px solid #000; + background:#ccc; + padding:3px 10px; +} + +.light{ + color:#e6f1f6; +} + +.nav a{ + padding:0 10px; +} + +.author{ + margin:10px; +} + +.author img{ + width:45px; + border-radius:4px; + vertical-align:middle; +} \ No newline at end of file diff --git a/source/views/commits.html b/source/views/commits.html new file mode 100644 index 0000000..29fc519 --- /dev/null +++ b/source/views/commits.html @@ -0,0 +1,35 @@ + + +
+ <% include 'head' %> + + + <% include 'nav' %> +| sha | +author | +committer | +
|---|---|---|
| <%- commit.sha.substr -6 %> | +<%- commit.commit.author.name %> | +<%- commit.commit.committer.name %> | +
Commit is empty
+ <% end %> + + \ No newline at end of file diff --git a/source/views/head.html b/source/views/head.html new file mode 100644 index 0000000..8f7d385 --- /dev/null +++ b/source/views/head.html @@ -0,0 +1,3 @@ + +