1 | const config = require('./config'); |
2 | const template = require('./templates'); |
3 | const git = require('./git'); |
4 |
|
5 | function index() { |
6 | let repoListings = ''; |
7 | for (name in config.repositories) { |
8 | let repository = config.repositories[name]; |
9 |
|
10 | let commit = git.getLatestCommit(repository.location, repository.branch); |
11 | let stats = `${commit.hash.substring(0,7)} (${repository.branch}/${commit.number})`; |
12 | let commitTime = new Date(commit.date); |
13 | let date = commitTime.toLocaleDateString('en-US', {month:'short',day:'numeric',year:'numeric',hour:'numeric',minute:'numeric',second:'numeric'}) + ' (latest commit)'; |
14 |
|
15 | let latest = template(config.templates.inline_commit, {'name': name, 'hash': commit.hash, 'shorthash': stats, 'date': date, 'subject': commit.subject, 'author': commit.author, 'email': commit.email}); |
16 | let listing = template(config.templates.inline_repository, {'name': name, 'description': repository.description, 'github': repository.github, 'latest': latest}); |
17 |
|
18 | repoListings += listing; |
19 | } |
20 | return template(config.templates.index, {'repositories': repoListings}); |
21 | } |
22 |
|
23 | function repository(repo, page) { |
24 | let commits = git.listCommits(config.repositories[repo].location, config.repositories[repo].branch, page); |
25 | let commitList = ''; |
26 | let lastDate = ""; |
27 | for (i in commits) { |
28 | let commit = commits[i]; |
29 |
|
30 | let stats = `${commit.hash.substring(0,7)} (${repository.branch}/${commit.number})`; |
31 | let commitTime = new Date(commit.date); |
32 | let date = commitTime.toLocaleDateString('en-US', {month:'short',day:'numeric',year:'numeric',hour:'numeric',minute:'numeric',second:'numeric'}); |
33 |
|
34 | let inline = template(config.templates.inline_commit, {'name': repo, 'hash': commit.hash, 'shorthash': stats, 'date': date, 'subject': commit.subject, 'author': commit.author, 'email': commit.email}); |
35 |
|
36 | let dayString = commitTime.toLocaleDateString("en-US", {month:"long",day:"numeric",year:"numeric"}); |
37 | if (dayString != lastDate) { |
38 | lastDate = dayString; |
39 | commitList += "<h2 class=\"date category\">" + dayString + "</h2>"; |
40 | } |
41 | commitList += inline; |
42 | } |
43 | return template(config.templates.repository, {'repo': repo, 'commits': commitList}); |
44 | } |
45 |
|
46 | module.exports = { |
47 | index: index, |
48 | repository: repository |
49 | } |
50 |
|