From 17eb2e6f7bb00db2f501e37f53ffaf8f64111760 Mon Sep 17 00:00:00 2001 From: Nate Bailey Date: Tue, 25 Oct 2016 18:18:40 -0700 Subject: [PATCH 1/3] Add index page generation to HTML writer --- src/templates/html.hbs | 3 +++ src/templates/index.hbs | 29 +++++++++++++++++++++++++++++ src/writehtml.js | 33 +++++++++++++++++++++++++++++++-- static/css/style.css | 13 +++++++++++++ 4 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 src/templates/index.hbs diff --git a/src/templates/html.hbs b/src/templates/html.hbs index a37739b..88c8135 100644 --- a/src/templates/html.hbs +++ b/src/templates/html.hbs @@ -10,6 +10,9 @@
+

+ Back to index +

{{state}} {{quicklink}} diff --git a/src/templates/index.hbs b/src/templates/index.hbs new file mode 100644 index 0000000..a7532db --- /dev/null +++ b/src/templates/index.hbs @@ -0,0 +1,29 @@ + + + + + + + + {{title}} + + +

+
+

{{title}}

+
+
+ {{#issues}} +
+ +

{{title}}

+
+ {{state}} + {{created_by}} + +
+ {{/issues}} +
+
+ + diff --git a/src/writehtml.js b/src/writehtml.js index 3726251..645932f 100644 --- a/src/writehtml.js +++ b/src/writehtml.js @@ -32,6 +32,13 @@ module.exports = function writehtml (options, cb) { var issues = fs.readFileSync('comments.json') issues = JSON.parse(issues) + + writeIssues(issues, cb) + writeIndex(issues, cb) + cb(null, 'Wrote html files.') +} + +function writeIssues (issues, cb) { issues.forEach(function (issue) { issue = parseBody(issue) var filename = repoDetails(issue.url) @@ -39,10 +46,32 @@ module.exports = function writehtml (options, cb) { var template = handlebars.compile(source.toString()) var result = template(issue) fs.writeFile('html/' + filename + '.html', result, function (err) { - if (err) return cb(err, 'Error writing HTML file.') + if (err) return cb(err, 'Error writing HTML issue file.') }) }) - cb(null, 'Wrote html files.') +} + +function writeIndex (issues, cb) { + var source = fs.readFileSync(path.join(__dirname, '/templates/index.hbs')) + var template = handlebars.compile(source.toString()) + + issues.forEach(function (issue) { + issue.offlineUrl = repoDetails(issue.url) + }) + + var result = template({ + issues: issues, + title: repoName(issues) + }) + fs.writeFile('html/index.html', result, function (err) { + if (err) return cb(err, 'Error writing HTML index file.') + }) +} + +function repoName (issues) { + var a = issues[0].url.split('/') + var name = a[3] + '-' + a[4] + return name } function repoDetails (issue) { diff --git a/static/css/style.css b/static/css/style.css index 5fb7487..900272c 100644 --- a/static/css/style.css +++ b/static/css/style.css @@ -85,3 +85,16 @@ time { .badge.closed { background: #c00; } .badge.open { background: #5c5; } + +.issues { + margin-top: 40px; +} + +.issue { + border-bottom: 1px solid #e0e0e0; + padding-bottom: 20px; +} + +.issue:last-child { + border-bottom: none; +} From 0bffc993403038be205242897a1a74e645cc8e9b Mon Sep 17 00:00:00 2001 From: Nate Bailey Date: Wed, 26 Oct 2016 09:47:45 -0700 Subject: [PATCH 2/3] Format index page title to match Github style --- src/writehtml.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/writehtml.js b/src/writehtml.js index 645932f..05bf655 100644 --- a/src/writehtml.js +++ b/src/writehtml.js @@ -70,7 +70,7 @@ function writeIndex (issues, cb) { function repoName (issues) { var a = issues[0].url.split('/') - var name = a[3] + '-' + a[4] + var name = a[3] + '/' + a[4] return name } From ab4e1b0c2724187a65b54be306db0630de046bd0 Mon Sep 17 00:00:00 2001 From: Nate Bailey Date: Wed, 26 Oct 2016 10:43:05 -0700 Subject: [PATCH 3/3] Add support for multiple repositories on index age --- src/templates/index.hbs | 32 ++++++++++++--------- src/writehtml.js | 64 ++++++++++++++++++++++++++++++++--------- static/css/style.css | 10 +++++-- 3 files changed, 77 insertions(+), 29 deletions(-) diff --git a/src/templates/index.hbs b/src/templates/index.hbs index a7532db..8582f2d 100644 --- a/src/templates/index.hbs +++ b/src/templates/index.hbs @@ -5,25 +5,29 @@ - {{title}} + Offline Issues
-
-

{{title}}

-
-
- {{#issues}} -
- -

{{title}}

-
- {{state}} - {{created_by}} - + {{#repositories}} +
+
+

{{name}}

+
+
+ {{#issues}} +
+ +

{{title}}

+
+ {{state}} + {{created_by}} + +
+ {{/issues}}
- {{/issues}}
+ {{/repositories}}
diff --git a/src/writehtml.js b/src/writehtml.js index 05bf655..c0d879e 100644 --- a/src/writehtml.js +++ b/src/writehtml.js @@ -30,14 +30,17 @@ module.exports = function writehtml (options, cb) { }) } - var issues = fs.readFileSync('comments.json') - issues = JSON.parse(issues) + var repositories = getRepositories() + + writeIndex(repositories, cb) + repositories.forEach(function (repository) { + writeIssues(repository.issues, cb) + }) - writeIssues(issues, cb) - writeIndex(issues, cb) cb(null, 'Wrote html files.') } +// Writers function writeIssues (issues, cb) { issues.forEach(function (issue) { issue = parseBody(issue) @@ -51,25 +54,60 @@ function writeIssues (issues, cb) { }) } -function writeIndex (issues, cb) { +function writeIndex (repositories, cb) { var source = fs.readFileSync(path.join(__dirname, '/templates/index.hbs')) var template = handlebars.compile(source.toString()) - issues.forEach(function (issue) { - issue.offlineUrl = repoDetails(issue.url) + repositories.forEach(function (repository) { + repository.issues.forEach(function (issue) { + issue.offlineUrl = repoDetails(issue.url) + }) }) - var result = template({ - issues: issues, - title: repoName(issues) - }) + var result = template({ repositories: repositories }) fs.writeFile('html/index.html', result, function (err) { if (err) return cb(err, 'Error writing HTML index file.') }) } -function repoName (issues) { - var a = issues[0].url.split('/') +// Parsers +function getRepositories () { + var comments = getComments() + var repositories = [] // Array of repository objects + var repositoryNames = {} // Index of repositories (name => index) + comments.forEach(function (comment) { + var name = repoName(comment) + // Initialize a repo object if necessary + if (!(name in repositoryNames)) { + repositoryNames[name] = repositories.length + repositories.push({ + name: name, + issues: [] + }) + } + // Push the comment into the repo's issue array + var repositoryIndex = repositoryNames[name] + repositories[repositoryIndex].issues.push(comment) + }) + return repositories +} + +function getComments() { + var rawComments = fs.readFileSync('comments.json') + var parsedComments = JSON.parse(rawComments) + var comments = [] // Returnable array of comments + var commentsIndex = {} // Used to determine uniqueness + parsedComments.forEach(function (comment) { + if (comment.id in commentsIndex) return + commentsIndex[comment.id] = true + comments.push(comment) + }) + return comments +} + +// Helpers +function repoName (comment) { + var a = comment.url.split('/') var name = a[3] + '/' + a[4] return name } diff --git a/static/css/style.css b/static/css/style.css index 900272c..9089781 100644 --- a/static/css/style.css +++ b/static/css/style.css @@ -86,15 +86,21 @@ time { .badge.closed { background: #c00; } .badge.open { background: #5c5; } +.repositories {} +.repository { + margin-bottom: 60px; +} +.repository:last-child { + margin-bottom: 0; +} + .issues { margin-top: 40px; } - .issue { border-bottom: 1px solid #e0e0e0; padding-bottom: 20px; } - .issue:last-child { border-bottom: none; }