RSS/ATOM Feed added, Prism changes, and global Copyright notice. (#94)

* Add Reason support to Prism.js

* Add XML/ATOM feed. Generates for both localhost and build script. Adds meta links to feeds to all html files.

* Updated /core/Footer.js to pull from siteConfig
This commit is contained in:
Eric Nakagawa 2017-09-27 12:49:09 -07:00 committed by Joel Marcey
parent 92ce92ee59
commit dc835770a0
15 changed files with 285 additions and 39 deletions

View file

@ -23,6 +23,8 @@ function execute(port) {
const translate = require("./translate.js");
const versionFallback = require("./versionFallback");
const feed = require("./feed.js");
const CWD = process.cwd();
const ENABLE_TRANSLATION = fs.existsSync(CWD + "/languages.js");
const ENABLE_VERSIONING = fs.existsSync(CWD + "/versions.json");
@ -116,7 +118,7 @@ function execute(port) {
const metadata = Metadata[id];
links[metadata.permalink] = id;
});
// mdToHtml is a map from a markdown file name to its html link, used to
// change relative markdown links that work on GitHub into actual site links
const mdToHtml = {};
@ -219,6 +221,16 @@ function execute(port) {
res.send(renderToStaticMarkup(docComp));
});
app.get(/blog\/.*xml$/, (req, res) => {
res.set("Content-Type", "application/rss+xml");
let parts = req.path.toString().split("blog/");
if (parts[1].toLowerCase() == "atom.xml") {
res.send(feed("atom"));
return;
}
res.send(feed("rss"));
});
// handle all requests for blog pages and posts
app.get(/blog\/.*html$/, (req, res) => {
removeFromCache(CWD + "/siteConfig.js");
@ -242,7 +254,7 @@ function execute(port) {
page++
) {
let language = "en";
const metadata = { page: page, perPage: perPage };
const metadata = {page: page, perPage: perPage};
const blogPageComp = (
<BlogPageLayout
metadata={metadata}
@ -276,7 +288,7 @@ function execute(port) {
file = CWD + "/blog/" + file;
const result = readMetadata.extractMetadata(
fs.readFileSync(file, { encoding: "utf8" })
fs.readFileSync(file, {encoding: "utf8"})
);
let rawContent = result.rawContent;
rawContent = rawContent.replace(
@ -284,7 +296,7 @@ function execute(port) {
"](" + siteConfig.baseUrl + "blog/assets/"
);
const metadata = Object.assign(
{ path: req.path.toString().split("blog/")[1], content: rawContent },
{path: req.path.toString().split("blog/")[1], content: rawContent},
result.metadata
);
metadata.id = metadata.title;
@ -323,7 +335,7 @@ function execute(port) {
))
)
) {
res.send(fs.readFileSync(htmlFile, { encoding: "utf8" }));
res.send(fs.readFileSync(htmlFile, {encoding: "utf8"}));
return;
}
@ -350,7 +362,7 @@ function execute(port) {
englishFile = englishFile.replace("/" + language + "/", "/en/");
}
// check for: a file for the page, an english file for page with unspecified language,
// check for: a file for the page, an english file for page with unspecified language,
// english file for the page
if (
fs.existsSync(userFile) ||
@ -399,7 +411,7 @@ function execute(port) {
__dirname +
"/../static/" +
req.path.toString().replace(siteConfig.baseUrl, "/");
let cssContent = fs.readFileSync(mainCssPath, { encoding: "utf8" });
let cssContent = fs.readFileSync(mainCssPath, {encoding: "utf8"});
let files = glob.sync(CWD + "/static/**/*.css");
@ -408,7 +420,7 @@ function execute(port) {
return;
}
cssContent =
cssContent + "\n" + fs.readFileSync(file, { encoding: "utf8" });
cssContent + "\n" + fs.readFileSync(file, {encoding: "utf8"});
});
if (