Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/templates/html.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
<body>
<div class="container">
<header>
<p>
<a href="index.html">Back to index</a>
</p>
<p>
<span class="badge {{state}}">{{state}}</span>
<span class="url">{{quicklink}}</span>
Expand Down
33 changes: 33 additions & 0 deletions src/templates/index.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="css/style.css">
<script type="text/javascript" src="lib/jquery.js"></script>
<script type="text/javascript" src="lib/jquery.emoji.js"></script>
<title>Offline Issues</title>
</head>
<body>
<div class="container">
{{#repositories}}
<div class="repository">
<header>
<h1>{{name}}</h1>
</header>
<div class="issues">
{{#issues}}
<div class="issue">
<a href="{{offlineUrl}}.html">
<h2>{{title}}</h2>
</a>
<span class="badge {{state}}">{{state}}</span>
<a class="person" href="https://github.com/{{created_by}}">{{created_by}}</a>
<time>{{created_at}}</time>
</div>
{{/issues}}
</div>
</div>
{{/repositories}}
</div>
</body>
</html>
75 changes: 71 additions & 4 deletions src/writehtml.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,86 @@ 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)
var source = fs.readFileSync(path.join(__dirname, '/templates/html.hbs'))
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) {
Expand Down
19 changes: 19 additions & 0 deletions static/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}