Skip to content

Commit 775ae03

Browse files
committed
Generate blog posts from project CHANGELOG file
1 parent 99194ac commit 775ae03

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-0
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"uglify-js": "2.4.x"
1818
},
1919
"oddwebPlugins": [
20+
"plugins/changelog.js",
2021
"core/blog",
2122
"plugins/minify.js",
2223
"plugins/variables.js"

plugins/changelog.js

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/**
2+
* @file - Generate a blog posts for each non-empty entry in the JSHint
3+
* project's `CHANGELOG.md` file.
4+
*/
5+
"use strict";
6+
var fs = require("fs");
7+
8+
var antonDepartureDate = new Date(2014, 6, 22);
9+
var headerPattern = new RegExp([
10+
'^#+',
11+
// Version:
12+
'\\[([^\\]]+)\\]',
13+
// URL:
14+
'\\(([^\\)]+)\\)',
15+
// Date:
16+
'\\(([^\\)]+)\\)'
17+
].join('\\s*'), 'gm');
18+
var anchorPattern = /^<a\s+name\b[^>]*><\/a>$/gim;
19+
20+
module.exports = function (site, handlebars) {
21+
var changelog = fs.readFileSync(
22+
"res/jshint/CHANGELOG.md", { encoding: "utf-8" }
23+
);
24+
25+
var match;
26+
var releases = [];
27+
28+
// Remove anchors
29+
changelog = changelog.replace(anchorPattern, "");
30+
31+
while (match = headerPattern.exec(changelog)) {
32+
releases.push({
33+
version: match[1],
34+
url: match[2],
35+
date: match[3],
36+
headingStart: match.index,
37+
headingEnd: match.index + match[0].length
38+
});
39+
}
40+
41+
releases.forEach(function(release, idx) {
42+
var until;
43+
44+
if (idx < releases.length - 1) {
45+
until = releases[idx + 1].headingStart;
46+
} else {
47+
until = changelog.length;
48+
}
49+
50+
release.content = changelog.slice(release.headingEnd, until).trim();
51+
});
52+
53+
releases.forEach(function(release) {
54+
var slug;
55+
56+
// Do not generate posts for releases with no associated release notes
57+
if (!release.content) {
58+
return;
59+
}
60+
61+
slug = "release-" + release.version.replace(/[^a-z0-9_-]+/gi, "-");
62+
63+
site.pages.push({
64+
meta: {
65+
template: "blog.html",
66+
blog: true,
67+
title: "New Release: " + release.version,
68+
date: release.date,
69+
url: "/blog/" + release.date + "/" + slug,
70+
path: "blog/" + release.date + "/" + slug + "/index.html",
71+
author: new Date(release.date) < antonDepartureDate ?
72+
"Anton Kovalyov" : "The JSHint team",
73+
type: "md"
74+
},
75+
data: release.content
76+
});
77+
});
78+
79+
return site;
80+
};

0 commit comments

Comments
 (0)