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..8582f2d --- /dev/null +++ b/src/templates/index.hbs @@ -0,0 +1,33 @@ + + + + + + + + Offline Issues + + +

+ {{#repositories}} +
+
+

{{name}}

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

{{title}}

+
+ {{state}} + {{created_by}} + +
+ {{/issues}} +
+
+ {{/repositories}} +
+ + diff --git a/src/writehtml.js b/src/writehtml.js index 3726251..c0d879e 100644 --- a/src/writehtml.js +++ b/src/writehtml.js @@ -30,8 +30,18 @@ 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) + }) + + cb(null, 'Wrote html files.') +} + +// Writers +function writeIssues (issues, cb) { issues.forEach(function (issue) { issue = parseBody(issue) var filename = repoDetails(issue.url) @@ -39,10 +49,67 @@ 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 (repositories, cb) { + var source = fs.readFileSync(path.join(__dirname, '/templates/index.hbs')) + var template = handlebars.compile(source.toString()) + + repositories.forEach(function (repository) { + repository.issues.forEach(function (issue) { + issue.offlineUrl = repoDetails(issue.url) + }) + }) + + var result = template({ repositories: repositories }) + fs.writeFile('html/index.html', result, function (err) { + if (err) return cb(err, 'Error writing HTML index file.') + }) +} + +// 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 } function repoDetails (issue) { diff --git a/static/css/style.css b/static/css/style.css index 5fb7487..9089781 100644 --- a/static/css/style.css +++ b/static/css/style.css @@ -85,3 +85,22 @@ 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; +}