Adds sitemap.xml. Adds 'Help Translate' to translatable strings. Error messages and fn name cleanups. (#136)

* added a note about needing more than one language to be enabled to allow for a drop down

* Removing debug statements

* Add 'Help Translate' to translatable strings, improves error messages around missing translated strings, calls write-translations on some routes

* Adds sitemap.xml to live server and build. Versioning not supported. -- Also did some file name and module cache cleanups.
This commit is contained in:
Eric Nakagawa 2017-10-18 12:55:58 -07:00 committed by Joel Marcey
parent 30eea17a24
commit bcba05ae03
19 changed files with 495 additions and 245 deletions

View file

@ -92,20 +92,23 @@ function extractMetadata(content) {
const metadata = {};
const both = splitHeader(content);
if (both === false) {
return {metadata, rawContent: content};
return { metadata, rawContent: content };
}
const lines = both.header.split("\n");
for (let i = 0; i < lines.length - 1; ++i) {
const keyvalue = lines[i].split(":");
const key = keyvalue[0].trim();
let value = keyvalue.slice(1).join(":").trim();
let value = keyvalue
.slice(1)
.join(":")
.trim();
try {
value = JSON.parse(value);
} catch (e) {}
metadata[key] = value;
}
return {metadata, rawContent: both.content};
return { metadata, rawContent: both.content };
}
// process the metadata for a document found in the docs folder
@ -174,11 +177,11 @@ function processMetadata(file) {
}
}
return {metadata, rawContent: rawContent};
return { metadata, rawContent: rawContent };
}
// process metadata for all docs and save into core/metadata.js
function generateDocsMetadata() {
function generateMetadataDocs() {
const order = readSidebar();
const regexSubFolder = /translated_docs\/(.*)\/.*/;
@ -269,7 +272,7 @@ function generateDocsMetadata() {
}
// process metadata for blog posts and save into core/MetadataBlog.js
function generateBlogMetadata() {
function generateMetadataBlog() {
const metadatas = [];
let files = glob.sync(CWD + "/blog/**/*.*");
@ -280,44 +283,52 @@ function generateBlogMetadata() {
)} Make sure you've put your blog files in your Docusaurus 'website' folder.`
);
}
files.sort().reverse().forEach(file => {
const extension = path.extname(file);
if (extension !== ".md" && extension !== ".markdown") {
return;
}
// Transform
// 2015-08-13-blog-post-name-0.5.md
// into
// 2015/08/13/blog-post-name-0-5.html
const filePath = path
.basename(file)
.replace("-", "/")
.replace("-", "/")
.replace("-", "/")
.replace(/\./g, "-")
.replace(/\-md$/, ".html");
const result = extractMetadata(fs.readFileSync(file, {encoding: "utf8"}));
const rawContent = result.rawContent;
const metadata = Object.assign(
{path: filePath, content: rawContent},
result.metadata
);
files
.sort()
.reverse()
.forEach(file => {
const extension = path.extname(file);
if (extension !== ".md" && extension !== ".markdown") {
return;
}
// Transform
// 2015-08-13-blog-post-name-0.5.md
// into
// 2015/08/13/blog-post-name-0-5.html
const filePath = path
.basename(file)
.replace("-", "/")
.replace("-", "/")
.replace("-", "/")
.replace(/\./g, "-")
.replace(/\-md$/, ".html");
const result = extractMetadata(
fs.readFileSync(file, { encoding: "utf8" })
);
const rawContent = result.rawContent;
const metadata = Object.assign(
{ path: filePath, content: rawContent },
result.metadata
);
metadata.id = metadata.title;
metadata.id = metadata.title;
// Extract, YYYY, MM, DD from the file name
let filePathDateArr = path.basename(file).toString().split("-");
metadata.date = new Date(
filePathDateArr[0] +
"-" +
filePathDateArr[1] +
"-" +
filePathDateArr[2] +
"T06:00:00.000Z"
);
// Extract, YYYY, MM, DD from the file name
let filePathDateArr = path
.basename(file)
.toString()
.split("-");
metadata.date = new Date(
filePathDateArr[0] +
"-" +
filePathDateArr[1] +
"-" +
filePathDateArr[2] +
"T06:00:00.000Z"
);
metadatas.push(metadata);
});
metadatas.push(metadata);
});
fs.writeFileSync(
__dirname + "/../core/MetadataBlog.js",
@ -334,6 +345,6 @@ module.exports = {
readSidebar,
extractMetadata,
processMetadata,
generateDocsMetadata,
generateBlogMetadata
generateMetadataDocs,
generateMetadataBlog
};