mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-11 16:17:25 +02:00
Add Prettier Formatting (#258)
* Add Prettier formatting to source files and example files, and check that Prettier formatting is maintained on PRs * Remove trailing-comma as we are using Node 6 on Circle * Use latest Node 6 LTS version in Circle * Remove unused test
This commit is contained in:
parent
0cead4b6f9
commit
65421db62e
50 changed files with 1376 additions and 1350 deletions
|
@ -5,18 +5,18 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
const fs = require("fs-extra");
|
||||
const path = require("path");
|
||||
const os = require("os");
|
||||
const Feed = require("feed");
|
||||
const fs = require('fs-extra');
|
||||
const path = require('path');
|
||||
const os = require('os');
|
||||
const Feed = require('feed');
|
||||
|
||||
const chalk = require("chalk");
|
||||
const chalk = require('chalk');
|
||||
const CWD = process.cwd();
|
||||
|
||||
const siteConfig = require(CWD + "/siteConfig.js");
|
||||
const siteConfig = require(CWD + '/siteConfig.js');
|
||||
|
||||
const blogFolder = path.resolve("../blog/");
|
||||
const blogRootURL = siteConfig.url + "/blog";
|
||||
const blogFolder = path.resolve('../blog/');
|
||||
const blogRootURL = siteConfig.url + '/blog';
|
||||
const jestImage = siteConfig.url + siteConfig.headerIcon;
|
||||
|
||||
/****************************************************************************/
|
||||
|
@ -24,40 +24,40 @@ const jestImage = siteConfig.url + siteConfig.headerIcon;
|
|||
let readMetadata;
|
||||
let Metadata;
|
||||
|
||||
readMetadata = require("./readMetadata.js");
|
||||
readMetadata = require('./readMetadata.js');
|
||||
readMetadata.generateMetadataDocs();
|
||||
Metadata = require("../core/metadata.js");
|
||||
Metadata = require('../core/metadata.js');
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
module.exports = function(type) {
|
||||
console.log("feed.js triggered...");
|
||||
console.log('feed.js triggered...');
|
||||
|
||||
type = type || "rss";
|
||||
type = type || 'rss';
|
||||
|
||||
readMetadata.generateMetadataBlog();
|
||||
const MetadataBlog = require("../core/MetadataBlog.js");
|
||||
const MetadataBlog = require('../core/MetadataBlog.js');
|
||||
|
||||
const feed = new Feed({
|
||||
title: siteConfig.title + " Blog",
|
||||
title: siteConfig.title + ' Blog',
|
||||
description:
|
||||
"The best place to stay up-to-date with the latest " +
|
||||
'The best place to stay up-to-date with the latest ' +
|
||||
siteConfig.title +
|
||||
" news and events.",
|
||||
' news and events.',
|
||||
id: blogRootURL,
|
||||
link: blogRootURL,
|
||||
image: jestImage,
|
||||
copyright: siteConfig.copyright,
|
||||
updated: new Date(MetadataBlog[0].date)
|
||||
updated: new Date(MetadataBlog[0].date),
|
||||
});
|
||||
|
||||
MetadataBlog.forEach(post => {
|
||||
const url = blogRootURL + "/" + post.path;
|
||||
let content = "";
|
||||
if (post.content.indexOf("<!--truncate-->") == -1) {
|
||||
const url = blogRootURL + '/' + post.path;
|
||||
let content = '';
|
||||
if (post.content.indexOf('<!--truncate-->') == -1) {
|
||||
content = post.content.trim().substring(0, 250);
|
||||
} else {
|
||||
let contentArr = post.content.split("<!--truncate-->");
|
||||
let contentArr = post.content.split('<!--truncate-->');
|
||||
if (contentArr.length > 0) {
|
||||
content = contentArr[0];
|
||||
}
|
||||
|
@ -69,13 +69,13 @@ module.exports = function(type) {
|
|||
author: [
|
||||
{
|
||||
name: post.author,
|
||||
link: post.authorURL
|
||||
}
|
||||
link: post.authorURL,
|
||||
},
|
||||
],
|
||||
date: new Date(post.date),
|
||||
description: content
|
||||
description: content,
|
||||
});
|
||||
});
|
||||
|
||||
return type === "rss" ? feed.rss2() : feed.atom1();
|
||||
return type === 'rss' ? feed.rss2() : feed.atom1();
|
||||
};
|
||||
|
|
|
@ -6,51 +6,51 @@
|
|||
*/
|
||||
|
||||
function execute() {
|
||||
const extractTranslations = require("../write-translations.js");
|
||||
const extractTranslations = require('../write-translations.js');
|
||||
|
||||
const CWD = process.cwd();
|
||||
const fs = require("fs-extra");
|
||||
const readMetadata = require("./readMetadata.js");
|
||||
const renderToStaticMarkup = require("react-dom/server").renderToStaticMarkup;
|
||||
const path = require("path");
|
||||
const toSlug = require("../core/toSlug.js");
|
||||
const React = require("react");
|
||||
const mkdirp = require("mkdirp");
|
||||
const glob = require("glob");
|
||||
const chalk = require("chalk");
|
||||
const Site = require("../core/Site.js");
|
||||
const siteConfig = require(CWD + "/siteConfig.js");
|
||||
const translate = require("./translate.js");
|
||||
const versionFallback = require("./versionFallback.js");
|
||||
const fs = require('fs-extra');
|
||||
const readMetadata = require('./readMetadata.js');
|
||||
const renderToStaticMarkup = require('react-dom/server').renderToStaticMarkup;
|
||||
const path = require('path');
|
||||
const toSlug = require('../core/toSlug.js');
|
||||
const React = require('react');
|
||||
const mkdirp = require('mkdirp');
|
||||
const glob = require('glob');
|
||||
const chalk = require('chalk');
|
||||
const Site = require('../core/Site.js');
|
||||
const siteConfig = require(CWD + '/siteConfig.js');
|
||||
const translate = require('./translate.js');
|
||||
const versionFallback = require('./versionFallback.js');
|
||||
|
||||
const feed = require("./feed.js");
|
||||
const sitemap = require("./sitemap.js");
|
||||
const feed = require('./feed.js');
|
||||
const sitemap = require('./sitemap.js');
|
||||
|
||||
const join = path.join;
|
||||
|
||||
const ENABLE_TRANSLATION = fs.existsSync(join(CWD, "languages.js"));
|
||||
const ENABLE_VERSIONING = fs.existsSync(join(CWD, "versions.json"));
|
||||
const ENABLE_TRANSLATION = fs.existsSync(join(CWD, 'languages.js'));
|
||||
const ENABLE_VERSIONING = fs.existsSync(join(CWD, 'versions.json'));
|
||||
|
||||
let languages;
|
||||
if (ENABLE_TRANSLATION) {
|
||||
languages = require(CWD + "/languages.js");
|
||||
languages = require(CWD + '/languages.js');
|
||||
} else {
|
||||
languages = [
|
||||
{
|
||||
enabled: true,
|
||||
name: "English",
|
||||
tag: "en"
|
||||
}
|
||||
name: 'English',
|
||||
tag: 'en',
|
||||
},
|
||||
];
|
||||
}
|
||||
// create the folder path for a file if it does not exist, then write the file
|
||||
function writeFileAndCreateFolder(file, content) {
|
||||
mkdirp.sync(file.replace(new RegExp("/[^/]*$"), ""));
|
||||
mkdirp.sync(file.replace(new RegExp('/[^/]*$'), ''));
|
||||
|
||||
fs.writeFileSync(file, content);
|
||||
}
|
||||
|
||||
const TABLE_OF_CONTENTS_TOKEN = "<AUTOGENERATED_TABLE_OF_CONTENTS>";
|
||||
const TABLE_OF_CONTENTS_TOKEN = '<AUTOGENERATED_TABLE_OF_CONTENTS>';
|
||||
|
||||
// takes the content of a doc article and returns the content with a table of
|
||||
// contents inserted
|
||||
|
@ -64,7 +64,7 @@ function execute() {
|
|||
|
||||
const tableOfContents = headers
|
||||
.map(header => ` - [${header}](#${toSlug(header)})`)
|
||||
.join("\n");
|
||||
.join('\n');
|
||||
|
||||
return rawContent.replace(TABLE_OF_CONTENTS_TOKEN, tableOfContents);
|
||||
};
|
||||
|
@ -83,7 +83,7 @@ function execute() {
|
|||
return false;
|
||||
}
|
||||
|
||||
console.log("generate.js triggered...");
|
||||
console.log('generate.js triggered...');
|
||||
|
||||
// array of tags of enabled languages
|
||||
const enabledLanguages = [];
|
||||
|
@ -92,7 +92,7 @@ function execute() {
|
|||
});
|
||||
|
||||
readMetadata.generateMetadataDocs();
|
||||
const Metadata = require("../core/metadata.js");
|
||||
const Metadata = require('../core/metadata.js');
|
||||
|
||||
// TODO: what if the project is a github org page? We should not use
|
||||
// siteConfig.projectName in this case. Otherwise a GitHub org doc URL would
|
||||
|
@ -102,30 +102,30 @@ function execute() {
|
|||
// `title`. `projectName` is only used to generate a folder, which isn't
|
||||
// needed when the project's a GitHub org page
|
||||
|
||||
const buildDir = join(CWD, "build", siteConfig.projectName);
|
||||
const buildDir = join(CWD, 'build', siteConfig.projectName);
|
||||
|
||||
// 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 = {};
|
||||
Object.keys(Metadata).forEach(id => {
|
||||
const metadata = Metadata[id];
|
||||
if (metadata.language !== "en" || metadata.original_id) {
|
||||
if (metadata.language !== 'en' || metadata.original_id) {
|
||||
return;
|
||||
}
|
||||
let htmlLink =
|
||||
siteConfig.baseUrl + metadata.permalink.replace("/next/", "/");
|
||||
if (htmlLink.includes("/docs/en/")) {
|
||||
htmlLink = htmlLink.replace("/docs/en/", "/docs/en/VERSION/");
|
||||
siteConfig.baseUrl + metadata.permalink.replace('/next/', '/');
|
||||
if (htmlLink.includes('/docs/en/')) {
|
||||
htmlLink = htmlLink.replace('/docs/en/', '/docs/en/VERSION/');
|
||||
} else {
|
||||
htmlLink = htmlLink.replace("/docs/", "/docs/VERSION/");
|
||||
htmlLink = htmlLink.replace('/docs/', '/docs/VERSION/');
|
||||
}
|
||||
mdToHtml[metadata.source] = htmlLink;
|
||||
});
|
||||
|
||||
const DocsLayout = require("../core/DocsLayout.js");
|
||||
const Redirect = require("../core/Redirect.js");
|
||||
const DocsLayout = require('../core/DocsLayout.js');
|
||||
const Redirect = require('../core/Redirect.js');
|
||||
|
||||
fs.removeSync(join(CWD, "build"));
|
||||
fs.removeSync(join(CWD, 'build'));
|
||||
|
||||
// create html files for all docs by going through all doc ids
|
||||
Object.keys(Metadata).forEach(id => {
|
||||
|
@ -133,16 +133,16 @@ function execute() {
|
|||
// determine what file to use according to its id
|
||||
let file;
|
||||
if (metadata.original_id) {
|
||||
if (ENABLE_TRANSLATION && metadata.language !== "en") {
|
||||
file = join(CWD, "translated_docs", metadata.language, metadata.source);
|
||||
if (ENABLE_TRANSLATION && metadata.language !== 'en') {
|
||||
file = join(CWD, 'translated_docs', metadata.language, metadata.source);
|
||||
} else {
|
||||
file = join(CWD, "versioned_docs", metadata.source);
|
||||
file = join(CWD, 'versioned_docs', metadata.source);
|
||||
}
|
||||
} else {
|
||||
if (metadata.language === "en") {
|
||||
file = join(CWD, "..", readMetadata.getDocsPath(), metadata.source);
|
||||
if (metadata.language === 'en') {
|
||||
file = join(CWD, '..', readMetadata.getDocsPath(), metadata.source);
|
||||
} else {
|
||||
file = join(CWD, "translated_docs", metadata.language, metadata.source);
|
||||
file = join(CWD, 'translated_docs', metadata.language, metadata.source);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -150,7 +150,7 @@ function execute() {
|
|||
return;
|
||||
}
|
||||
|
||||
let rawContent = readMetadata.extractMetadata(fs.readFileSync(file, "utf8"))
|
||||
let rawContent = readMetadata.extractMetadata(fs.readFileSync(file, 'utf8'))
|
||||
.rawContent;
|
||||
|
||||
const language = metadata.language;
|
||||
|
@ -163,36 +163,36 @@ function execute() {
|
|||
let latestVersion;
|
||||
if (ENABLE_VERSIONING) {
|
||||
latestVersion = JSON.parse(
|
||||
fs.readFileSync(join(CWD, "versions.json"), "utf8")
|
||||
fs.readFileSync(join(CWD, 'versions.json'), 'utf8')
|
||||
)[0];
|
||||
}
|
||||
|
||||
// replace any links to markdown files to their website html links
|
||||
Object.keys(mdToHtml).forEach(function(key, index) {
|
||||
let link = mdToHtml[key];
|
||||
link = link.replace("/en/", "/" + language + "/");
|
||||
link = link.replace('/en/', '/' + language + '/');
|
||||
link = link.replace(
|
||||
"/VERSION/",
|
||||
'/VERSION/',
|
||||
metadata.version && metadata.version !== latestVersion
|
||||
? "/" + metadata.version + "/"
|
||||
: "/"
|
||||
? '/' + metadata.version + '/'
|
||||
: '/'
|
||||
);
|
||||
// replace relative links without "./"
|
||||
rawContent = rawContent.replace(
|
||||
new RegExp("\\]\\(" + key, "g"),
|
||||
"](" + link
|
||||
new RegExp('\\]\\(' + key, 'g'),
|
||||
'](' + link
|
||||
);
|
||||
// replace relative links with "./"
|
||||
rawContent = rawContent.replace(
|
||||
new RegExp("\\]\\(\\./" + key, "g"),
|
||||
"](" + link
|
||||
new RegExp('\\]\\(\\./' + key, 'g'),
|
||||
'](' + link
|
||||
);
|
||||
});
|
||||
|
||||
// replace any relative links to static assets to absolute links
|
||||
rawContent = rawContent.replace(
|
||||
/\]\(assets\//g,
|
||||
"](" + siteConfig.baseUrl + "docs/assets/"
|
||||
'](' + siteConfig.baseUrl + 'docs/assets/'
|
||||
);
|
||||
|
||||
const docComp = (
|
||||
|
@ -206,7 +206,7 @@ function execute() {
|
|||
writeFileAndCreateFolder(targetFile, str);
|
||||
|
||||
// generate english page redirects when languages are enabled
|
||||
if (ENABLE_TRANSLATION && metadata.permalink.indexOf("docs/en") !== -1) {
|
||||
if (ENABLE_TRANSLATION && metadata.permalink.indexOf('docs/en') !== -1) {
|
||||
const redirectComp = (
|
||||
<Redirect
|
||||
metadata={metadata}
|
||||
|
@ -220,76 +220,75 @@ function execute() {
|
|||
// create a redirects page for doc files
|
||||
const redirectFile = join(
|
||||
buildDir,
|
||||
metadata.permalink.replace("docs/en", "docs")
|
||||
metadata.permalink.replace('docs/en', 'docs')
|
||||
);
|
||||
writeFileAndCreateFolder(redirectFile, redirectStr);
|
||||
}
|
||||
});
|
||||
|
||||
// copy docs assets if they exist
|
||||
if (fs.existsSync(join(CWD, "..", readMetadata.getDocsPath(), "assets"))) {
|
||||
if (fs.existsSync(join(CWD, '..', readMetadata.getDocsPath(), 'assets'))) {
|
||||
fs.copySync(
|
||||
join(CWD, readMetadata.getDocsPath(), "assets"),
|
||||
join(buildDir, "docs", "assets")
|
||||
join(CWD, readMetadata.getDocsPath(), 'assets'),
|
||||
join(buildDir, 'docs', 'assets')
|
||||
);
|
||||
}
|
||||
|
||||
// create html files for all blog posts (each article)
|
||||
if (fs.existsSync(join(__dirname, "..", "core", "MetadataBlog.js"))) {
|
||||
fs.removeSync(join(__dirname, "..", "core", "MetadataBlog.js"));
|
||||
if (fs.existsSync(join(__dirname, '..', 'core', 'MetadataBlog.js'))) {
|
||||
fs.removeSync(join(__dirname, '..', 'core', 'MetadataBlog.js'));
|
||||
}
|
||||
readMetadata.generateMetadataBlog();
|
||||
const MetadataBlog = require("../core/MetadataBlog.js");
|
||||
const BlogPostLayout = require("../core/BlogPostLayout.js");
|
||||
const MetadataBlog = require('../core/MetadataBlog.js');
|
||||
const BlogPostLayout = require('../core/BlogPostLayout.js');
|
||||
|
||||
let files = glob.sync(join(CWD, "blog", "**", "*.*"));
|
||||
let files = glob.sync(join(CWD, 'blog', '**', '*.*'));
|
||||
files
|
||||
.sort()
|
||||
.reverse()
|
||||
.forEach(file => {
|
||||
const extension = path.extname(file);
|
||||
if (extension !== ".md" && extension !== ".markdown") {
|
||||
if (extension !== '.md' && extension !== '.markdown') {
|
||||
return;
|
||||
}
|
||||
|
||||
// convert filename to use slashes
|
||||
const filePath = path
|
||||
.basename(file)
|
||||
.replace("-", "/")
|
||||
.replace("-", "/")
|
||||
.replace("-", "/")
|
||||
.replace(/\.md$/, ".html");
|
||||
.replace('-', '/')
|
||||
.replace('-', '/')
|
||||
.replace('-', '/')
|
||||
.replace(/\.md$/, '.html');
|
||||
const result = readMetadata.extractMetadata(
|
||||
fs.readFileSync(file, { encoding: "utf8" })
|
||||
fs.readFileSync(file, {encoding: 'utf8'})
|
||||
);
|
||||
const rawContent = result.rawContent;
|
||||
const metadata = Object.assign(
|
||||
{ path: filePath, content: rawContent },
|
||||
{path: filePath, content: rawContent},
|
||||
result.metadata
|
||||
);
|
||||
metadata.id = metadata.title;
|
||||
|
||||
let language = "en";
|
||||
let language = 'en';
|
||||
const blogPostComp = (
|
||||
<BlogPostLayout
|
||||
metadata={metadata}
|
||||
language={language}
|
||||
config={siteConfig}
|
||||
>
|
||||
config={siteConfig}>
|
||||
{rawContent}
|
||||
</BlogPostLayout>
|
||||
);
|
||||
const str = renderToStaticMarkup(blogPostComp);
|
||||
|
||||
let targetFile = join(buildDir, "blog", filePath);
|
||||
let targetFile = join(buildDir, 'blog', filePath);
|
||||
writeFileAndCreateFolder(targetFile, str);
|
||||
});
|
||||
// create html files for all blog pages (collections of article previews)
|
||||
const BlogPageLayout = require("../core/BlogPageLayout.js");
|
||||
const BlogPageLayout = require('../core/BlogPageLayout.js');
|
||||
const perPage = 10;
|
||||
for (let page = 0; page < Math.ceil(MetadataBlog.length / perPage); page++) {
|
||||
let language = "en";
|
||||
const metadata = { page: page, perPage: perPage };
|
||||
let language = 'en';
|
||||
const metadata = {page: page, perPage: perPage};
|
||||
const blogPageComp = (
|
||||
<BlogPageLayout
|
||||
metadata={metadata}
|
||||
|
@ -301,44 +300,44 @@ function execute() {
|
|||
|
||||
let targetFile = join(
|
||||
buildDir,
|
||||
"blog",
|
||||
page > 0 ? "page" + (page + 1) : "",
|
||||
"index.html"
|
||||
'blog',
|
||||
page > 0 ? 'page' + (page + 1) : '',
|
||||
'index.html'
|
||||
);
|
||||
writeFileAndCreateFolder(targetFile, str);
|
||||
}
|
||||
// create rss files for all blog pages, if there are any blog files
|
||||
if (MetadataBlog.length > 0) {
|
||||
let targetFile = join(buildDir, "blog", "feed.xml");
|
||||
let targetFile = join(buildDir, 'blog', 'feed.xml');
|
||||
writeFileAndCreateFolder(targetFile, feed());
|
||||
targetFile = join(buildDir, "blog", "atom.xml");
|
||||
writeFileAndCreateFolder(targetFile, feed("atom"));
|
||||
targetFile = join(buildDir, 'blog', 'atom.xml');
|
||||
writeFileAndCreateFolder(targetFile, feed('atom'));
|
||||
}
|
||||
|
||||
// create sitemap
|
||||
if (MetadataBlog.length > 0 && Object.keys(Metadata).length > 0) {
|
||||
let targetFile = join(buildDir, "sitemap.xml");
|
||||
let targetFile = join(buildDir, 'sitemap.xml');
|
||||
sitemap(xml => {
|
||||
writeFileAndCreateFolder(targetFile, xml);
|
||||
});
|
||||
}
|
||||
|
||||
// copy blog assets if they exist
|
||||
if (fs.existsSync(join(CWD, "blog", "assets"))) {
|
||||
fs.copySync(join(CWD, "blog", "assets"), join(buildDir, "blog", "assets"));
|
||||
if (fs.existsSync(join(CWD, 'blog', 'assets'))) {
|
||||
fs.copySync(join(CWD, 'blog', 'assets'), join(buildDir, 'blog', 'assets'));
|
||||
}
|
||||
|
||||
// copy all static files from docusaurus
|
||||
files = glob.sync(join(__dirname, "..", "static", "**"));
|
||||
files = glob.sync(join(__dirname, '..', 'static', '**'));
|
||||
files.forEach(file => {
|
||||
let targetFile = join(
|
||||
buildDir,
|
||||
// TODO: use x-platform path functions
|
||||
file.split("/static/")[1] || ""
|
||||
file.split('/static/')[1] || ''
|
||||
);
|
||||
// parse css files to replace colors according to siteConfig
|
||||
if (file.match(/\.css$/)) {
|
||||
let cssContent = fs.readFileSync(file, "utf8");
|
||||
let cssContent = fs.readFileSync(file, 'utf8');
|
||||
|
||||
if (
|
||||
!siteConfig.colors ||
|
||||
|
@ -347,80 +346,80 @@ function execute() {
|
|||
) {
|
||||
console.error(
|
||||
`${chalk.yellow(
|
||||
"Missing color configuration."
|
||||
'Missing color configuration.'
|
||||
)} Make sure siteConfig.colors includes primaryColor and secondaryColor fields.`
|
||||
);
|
||||
}
|
||||
|
||||
Object.keys(siteConfig.colors).forEach(key => {
|
||||
const color = siteConfig.colors[key];
|
||||
cssContent = cssContent.replace(new RegExp("\\$" + key, "g"), color);
|
||||
cssContent = cssContent.replace(new RegExp('\\$' + key, 'g'), color);
|
||||
});
|
||||
|
||||
mkdirp.sync(targetFile.replace(new RegExp("/[^/]*$"), ""));
|
||||
mkdirp.sync(targetFile.replace(new RegExp('/[^/]*$'), ''));
|
||||
fs.writeFileSync(targetFile, cssContent);
|
||||
} else if (!fs.lstatSync(file).isDirectory()) {
|
||||
mkdirp.sync(targetFile.replace(new RegExp("/[^/]*$"), ""));
|
||||
mkdirp.sync(targetFile.replace(new RegExp('/[^/]*$'), ''));
|
||||
fs.copySync(file, targetFile);
|
||||
}
|
||||
});
|
||||
|
||||
// copy all static files from user
|
||||
files = glob.sync(join(CWD, "static", "**"));
|
||||
files = glob.sync(join(CWD, 'static', '**'));
|
||||
files.forEach(file => {
|
||||
// parse css files to replace colors according to siteConfig
|
||||
if (file.match(/\.css$/) && !isSeparateCss(file)) {
|
||||
const mainCss = join(buildDir, "css", "main.css");
|
||||
let cssContent = fs.readFileSync(file, "utf8");
|
||||
cssContent = fs.readFileSync(mainCss, "utf8") + "\n" + cssContent;
|
||||
const mainCss = join(buildDir, 'css', 'main.css');
|
||||
let cssContent = fs.readFileSync(file, 'utf8');
|
||||
cssContent = fs.readFileSync(mainCss, 'utf8') + '\n' + cssContent;
|
||||
|
||||
Object.keys(siteConfig.colors).forEach(key => {
|
||||
const color = siteConfig.colors[key];
|
||||
cssContent = cssContent.replace(new RegExp("\\$" + key, "g"), color);
|
||||
cssContent = cssContent.replace(new RegExp('\\$' + key, 'g'), color);
|
||||
});
|
||||
|
||||
fs.writeFileSync(mainCss, cssContent);
|
||||
} else if (!fs.lstatSync(file).isDirectory()) {
|
||||
let parts = file.split("/static/");
|
||||
let parts = file.split('/static/');
|
||||
let targetFile = join(buildDir, parts[1]);
|
||||
mkdirp.sync(targetFile.replace(new RegExp("/[^/]*$"), ""));
|
||||
mkdirp.sync(targetFile.replace(new RegExp('/[^/]*$'), ''));
|
||||
fs.copySync(file, targetFile);
|
||||
}
|
||||
});
|
||||
|
||||
// compile/copy pages from user
|
||||
let pagesArr = [];
|
||||
files = glob.sync(join(CWD, "pages", "**"));
|
||||
files = glob.sync(join(CWD, 'pages', '**'));
|
||||
files.forEach(file => {
|
||||
// render .js files to strings
|
||||
if (file.match(/\.js$/)) {
|
||||
// make temp file for sake of require paths
|
||||
const parts = file.split("pages");
|
||||
let tempFile = join(__dirname, "..", "pages", parts[1]);
|
||||
const parts = file.split('pages');
|
||||
let tempFile = join(__dirname, '..', 'pages', parts[1]);
|
||||
tempFile = tempFile.replace(
|
||||
path.basename(file),
|
||||
"temp" + path.basename(file)
|
||||
'temp' + path.basename(file)
|
||||
);
|
||||
mkdirp.sync(tempFile.replace(new RegExp("/[^/]*$"), ""));
|
||||
mkdirp.sync(tempFile.replace(new RegExp('/[^/]*$'), ''));
|
||||
fs.copySync(file, tempFile);
|
||||
|
||||
const ReactComp = require(tempFile);
|
||||
|
||||
let targetFile = join(buildDir, parts[1]);
|
||||
targetFile = targetFile.replace(/\.js$/, ".html");
|
||||
targetFile = targetFile.replace(/\.js$/, '.html');
|
||||
|
||||
const regexLang = /\/pages\/(.*)\//;
|
||||
const match = regexLang.exec(file);
|
||||
const langParts = match[1].split("/");
|
||||
if (langParts.indexOf("en") !== -1) {
|
||||
const langParts = match[1].split('/');
|
||||
if (langParts.indexOf('en') !== -1) {
|
||||
// copy and compile a page for each enabled language from the English file
|
||||
for (let i = 0; i < enabledLanguages.length; i++) {
|
||||
let language = enabledLanguages[i];
|
||||
// skip conversion from english file if a file exists for this language
|
||||
if (
|
||||
language !== "en" &&
|
||||
language !== 'en' &&
|
||||
// TODO: use path functions
|
||||
fs.existsSync(file.replace("/en/", "/" + language + "/"))
|
||||
fs.existsSync(file.replace('/en/', '/' + language + '/'))
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
@ -432,13 +431,13 @@ function execute() {
|
|||
);
|
||||
writeFileAndCreateFolder(
|
||||
// TODO: use path functions
|
||||
targetFile.replace("/en/", "/" + language + "/"),
|
||||
targetFile.replace('/en/', '/' + language + '/'),
|
||||
str
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// allow for rendering of other files not in pages/en folder
|
||||
let language = "en";
|
||||
let language = 'en';
|
||||
for (let i = 0; i < langParts.length; i++) {
|
||||
if (enabledLanguages.indexOf(langParts[i]) !== -1) {
|
||||
language = langParts[i];
|
||||
|
@ -455,17 +454,17 @@ function execute() {
|
|||
fs.removeSync(tempFile);
|
||||
} else if (!fs.lstatSync(file).isDirectory()) {
|
||||
// copy other non .js files
|
||||
let parts = file.split("pages");
|
||||
let parts = file.split('pages');
|
||||
let targetFile = join(buildDir, parts[1]);
|
||||
mkdirp.sync(targetFile.replace(new RegExp("/[^/]*$"), ""));
|
||||
mkdirp.sync(targetFile.replace(new RegExp('/[^/]*$'), ''));
|
||||
fs.copySync(file, targetFile);
|
||||
}
|
||||
});
|
||||
|
||||
// copy html files in 'en' to base level as well
|
||||
files = glob.sync(join(buildDir, "en", "**"));
|
||||
files = glob.sync(join(buildDir, 'en', '**'));
|
||||
files.forEach(file => {
|
||||
let targetFile = file.replace(join(buildDir, "en"), join(buildDir));
|
||||
let targetFile = file.replace(join(buildDir, 'en'), join(buildDir));
|
||||
if (file.match(/\.html$/)) {
|
||||
fs.copySync(file, targetFile);
|
||||
}
|
||||
|
@ -473,7 +472,7 @@ function execute() {
|
|||
|
||||
// Generate CNAME file if a custom domain is specified in siteConfig
|
||||
if (siteConfig.cname) {
|
||||
let targetFile = join(buildDir, "CNAME");
|
||||
let targetFile = join(buildDir, 'CNAME');
|
||||
fs.writeFileSync(targetFile, siteConfig.cname);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,18 +7,18 @@
|
|||
|
||||
const CWD = process.cwd();
|
||||
|
||||
const Metadata = require("../core/metadata.js");
|
||||
const fs = require("fs");
|
||||
const Metadata = require('../core/metadata.js');
|
||||
const fs = require('fs');
|
||||
let languages;
|
||||
if (fs.existsSync(CWD + "/languages.js")) {
|
||||
languages = require(CWD + "/languages.js");
|
||||
if (fs.existsSync(CWD + '/languages.js')) {
|
||||
languages = require(CWD + '/languages.js');
|
||||
} else {
|
||||
languages = [
|
||||
{
|
||||
enabled: true,
|
||||
name: "English",
|
||||
tag: "en"
|
||||
}
|
||||
name: 'English',
|
||||
tag: 'en',
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -57,8 +57,14 @@ function readCategories(sidebar) {
|
|||
if (!articles[metadata.next]) {
|
||||
throw new Error(
|
||||
metadata.version
|
||||
? `Improper sidebars file for version ${metadata.version}, document with id '${metadata.next}' not found. Make sure that all documents with ids specified in this version's sidebar file exist and that no ids are repeated.`
|
||||
: `Improper sidebars.json file, document with id '${metadata.next}' not found. Make sure that documents with the ids specified in sidebars.json exist and that no ids are repeated.`
|
||||
? `Improper sidebars file for version ${
|
||||
metadata.version
|
||||
}, document with id '${
|
||||
metadata.next
|
||||
}' not found. Make sure that all documents with ids specified in this version's sidebar file exist and that no ids are repeated.`
|
||||
: `Improper sidebars.json file, document with id '${
|
||||
metadata.next
|
||||
}' not found. Make sure that documents with the ids specified in sidebars.json exist and that no ids are repeated.`
|
||||
);
|
||||
}
|
||||
previous[articles[metadata.next].id] = metadata.id;
|
||||
|
@ -85,7 +91,7 @@ function readCategories(sidebar) {
|
|||
currentCategory && categories.push(currentCategory);
|
||||
currentCategory = {
|
||||
name: metadata.category,
|
||||
links: []
|
||||
links: [],
|
||||
};
|
||||
}
|
||||
currentCategory.links.push(metadata);
|
||||
|
|
|
@ -7,28 +7,26 @@
|
|||
|
||||
const CWD = process.cwd();
|
||||
|
||||
const path = require("path");
|
||||
const fs = require("fs");
|
||||
const glob = require("glob");
|
||||
const chalk = require("chalk");
|
||||
const siteConfig = require(CWD + "/siteConfig.js");
|
||||
const versionFallback = require("./versionFallback.js");
|
||||
const escapeStringRegexp = require("escape-string-regexp");
|
||||
|
||||
const ENABLE_VERSIONING = fs.existsSync(CWD + "/versions.json");
|
||||
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const glob = require('glob');
|
||||
const chalk = require('chalk');
|
||||
const siteConfig = require(CWD + '/siteConfig.js');
|
||||
const versionFallback = require('./versionFallback.js');
|
||||
const escapeStringRegexp = require('escape-string-regexp');
|
||||
|
||||
const ENABLE_VERSIONING = fs.existsSync(CWD + '/versions.json');
|
||||
|
||||
let languages;
|
||||
if (fs.existsSync(CWD + "/languages.js")) {
|
||||
languages = require(CWD + "/languages.js");
|
||||
if (fs.existsSync(CWD + '/languages.js')) {
|
||||
languages = require(CWD + '/languages.js');
|
||||
} else {
|
||||
languages = [
|
||||
{
|
||||
enabled: true,
|
||||
name: "English",
|
||||
tag: "en"
|
||||
}
|
||||
name: 'English',
|
||||
tag: 'en',
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -39,15 +37,13 @@ if (fs.existsSync(CWD + "/languages.js")) {
|
|||
// All .md docs still (currently) must be in one flat directory hierarchy.
|
||||
// e.g., docs/whereDocsReallyExist/*.md (all .md files in this dir)
|
||||
function getDocsPath() {
|
||||
return siteConfig.customDocsPath
|
||||
? siteConfig.customDocsPath
|
||||
: "docs";
|
||||
return siteConfig.customDocsPath ? siteConfig.customDocsPath : 'docs';
|
||||
}
|
||||
// returns map from id to object containing sidebar ordering info
|
||||
function readSidebar() {
|
||||
let allSidebars;
|
||||
if (fs.existsSync(CWD + "/sidebars.json")) {
|
||||
allSidebars = require(CWD + "/sidebars.json");
|
||||
if (fs.existsSync(CWD + '/sidebars.json')) {
|
||||
allSidebars = require(CWD + '/sidebars.json');
|
||||
} else {
|
||||
allSidebars = {};
|
||||
}
|
||||
|
@ -76,7 +72,7 @@ function readSidebar() {
|
|||
previous: previous,
|
||||
next: next,
|
||||
sidebar: sidebar,
|
||||
category: categoryOrder[i]
|
||||
category: categoryOrder[i],
|
||||
};
|
||||
}
|
||||
});
|
||||
|
@ -85,19 +81,19 @@ function readSidebar() {
|
|||
|
||||
// split markdown header
|
||||
function splitHeader(content) {
|
||||
const lines = content.split("\n");
|
||||
if (lines[0] !== "---") {
|
||||
const lines = content.split('\n');
|
||||
if (lines[0] !== '---') {
|
||||
return {};
|
||||
}
|
||||
let i = 1;
|
||||
for (; i < lines.length - 1; ++i) {
|
||||
if (lines[i] === "---") {
|
||||
if (lines[i] === '---') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return {
|
||||
header: lines.slice(1, i + 1).join("\n"),
|
||||
content: lines.slice(i + 1).join("\n")
|
||||
header: lines.slice(1, i + 1).join('\n'),
|
||||
content: lines.slice(i + 1).join('\n'),
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -106,31 +102,33 @@ function extractMetadata(content) {
|
|||
const metadata = {};
|
||||
const both = splitHeader(content);
|
||||
if (Object.keys(both).length === 0) {
|
||||
return { metadata, rawContent: content };
|
||||
return {metadata, rawContent: content};
|
||||
}
|
||||
const lines = both.header.split("\n");
|
||||
const lines = both.header.split('\n');
|
||||
for (let i = 0; i < lines.length - 1; ++i) {
|
||||
const keyvalue = lines[i].split(":");
|
||||
const keyvalue = lines[i].split(':');
|
||||
const key = keyvalue[0].trim();
|
||||
let value = keyvalue
|
||||
.slice(1)
|
||||
.join(":")
|
||||
.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
|
||||
function processMetadata(file) {
|
||||
const result = extractMetadata(fs.readFileSync(file, "utf8"));
|
||||
const result = extractMetadata(fs.readFileSync(file, 'utf8'));
|
||||
|
||||
let regexSubFolder = new RegExp("/" + escapeStringRegexp(getDocsPath()) + "\/(.*)\/.*/");
|
||||
let regexSubFolder = new RegExp(
|
||||
'/' + escapeStringRegexp(getDocsPath()) + '/(.*)/.*/'
|
||||
);
|
||||
|
||||
let language = "en";
|
||||
let language = 'en';
|
||||
const match = regexSubFolder.exec(file);
|
||||
if (match) {
|
||||
language = match[1];
|
||||
|
@ -143,7 +141,7 @@ function processMetadata(file) {
|
|||
if (!metadata.id) {
|
||||
metadata.id = path.basename(file, path.extname(file));
|
||||
}
|
||||
if (metadata.id.includes("/")) {
|
||||
if (metadata.id.includes('/')) {
|
||||
throw new Error('Document id cannot include "/".');
|
||||
}
|
||||
if (!metadata.title) {
|
||||
|
@ -151,26 +149,26 @@ function processMetadata(file) {
|
|||
}
|
||||
|
||||
if (languages.length === 1 && !siteConfig.useEnglishUrl) {
|
||||
metadata.permalink = "docs/" + metadata.id + ".html";
|
||||
metadata.permalink = 'docs/' + metadata.id + '.html';
|
||||
} else {
|
||||
metadata.permalink = "docs/" + language + "/" + metadata.id + ".html";
|
||||
metadata.permalink = 'docs/' + language + '/' + metadata.id + '.html';
|
||||
}
|
||||
|
||||
if (ENABLE_VERSIONING) {
|
||||
metadata.version = "next";
|
||||
metadata.version = 'next';
|
||||
if (languages.length === 1 && !siteConfig.useEnglishUrl) {
|
||||
metadata.permalink = metadata.permalink.replace("docs/", "docs/next/");
|
||||
metadata.permalink = metadata.permalink.replace('docs/', 'docs/next/');
|
||||
} else {
|
||||
metadata.permalink = metadata.permalink.replace(
|
||||
"docs/" + language + "/",
|
||||
"docs/" + language + "/next/"
|
||||
'docs/' + language + '/',
|
||||
'docs/' + language + '/next/'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// change ids previous, next
|
||||
metadata.localized_id = metadata.id;
|
||||
metadata.id = language + "-" + metadata.id;
|
||||
metadata.id = language + '-' + metadata.id;
|
||||
metadata.language = language;
|
||||
|
||||
const order = readSidebar();
|
||||
|
@ -182,20 +180,20 @@ function processMetadata(file) {
|
|||
|
||||
if (order[id].next) {
|
||||
metadata.next_id = order[id].next;
|
||||
metadata.next = language + "-" + order[id].next;
|
||||
metadata.next = language + '-' + order[id].next;
|
||||
}
|
||||
if (order[id].previous) {
|
||||
metadata.previous_id = order[id].previous;
|
||||
metadata.previous = language + "-" + order[id].previous;
|
||||
metadata.previous = language + '-' + order[id].previous;
|
||||
}
|
||||
}
|
||||
|
||||
return { metadata, rawContent: rawContent };
|
||||
return {metadata, rawContent: rawContent};
|
||||
}
|
||||
|
||||
// process metadata for all docs and save into core/metadata.js
|
||||
function generateMetadataDocs() {
|
||||
console.log("Generating Metadata for Docs....");
|
||||
console.log('Generating Metadata for Docs....');
|
||||
|
||||
let order;
|
||||
try {
|
||||
|
@ -216,13 +214,13 @@ function generateMetadataDocs() {
|
|||
const defaultMetadatas = {};
|
||||
|
||||
// metadata for english files
|
||||
let files = glob.sync(CWD + "/../" + getDocsPath() + "/**");
|
||||
let files = glob.sync(CWD + '/../' + getDocsPath() + '/**');
|
||||
files.forEach(file => {
|
||||
let language = "en";
|
||||
let language = 'en';
|
||||
|
||||
const extension = path.extname(file);
|
||||
|
||||
if (extension === ".md" || extension === ".markdown") {
|
||||
if (extension === '.md' || extension === '.markdown') {
|
||||
const res = processMetadata(file);
|
||||
|
||||
if (!res) {
|
||||
|
@ -235,36 +233,36 @@ function generateMetadataDocs() {
|
|||
// these will get replaced if/when the localized file is downloaded from crowdin
|
||||
enabledLanguages
|
||||
.filter(currentLanguage => {
|
||||
return currentLanguage != "en";
|
||||
return currentLanguage != 'en';
|
||||
})
|
||||
.map(currentLanguage => {
|
||||
let baseMetadata = Object.assign({}, metadata);
|
||||
baseMetadata["id"] = baseMetadata["id"]
|
||||
baseMetadata['id'] = baseMetadata['id']
|
||||
.toString()
|
||||
.replace(/^en-/, currentLanguage + "-");
|
||||
if (baseMetadata["permalink"])
|
||||
baseMetadata["permalink"] = baseMetadata["permalink"]
|
||||
.replace(/^en-/, currentLanguage + '-');
|
||||
if (baseMetadata['permalink'])
|
||||
baseMetadata['permalink'] = baseMetadata['permalink']
|
||||
.toString()
|
||||
.replace(/^docs\/en\//, "docs/" + currentLanguage + "/");
|
||||
if (baseMetadata["next"])
|
||||
baseMetadata["next"] = baseMetadata["next"]
|
||||
.replace(/^docs\/en\//, 'docs/' + currentLanguage + '/');
|
||||
if (baseMetadata['next'])
|
||||
baseMetadata['next'] = baseMetadata['next']
|
||||
.toString()
|
||||
.replace(/^en-/, currentLanguage + "-");
|
||||
if (baseMetadata["previous"])
|
||||
baseMetadata["previous"] = baseMetadata["previous"]
|
||||
.replace(/^en-/, currentLanguage + '-');
|
||||
if (baseMetadata['previous'])
|
||||
baseMetadata['previous'] = baseMetadata['previous']
|
||||
.toString()
|
||||
.replace(/^en-/, currentLanguage + "-");
|
||||
baseMetadata["language"] = currentLanguage;
|
||||
defaultMetadatas[baseMetadata["id"]] = baseMetadata;
|
||||
.replace(/^en-/, currentLanguage + '-');
|
||||
baseMetadata['language'] = currentLanguage;
|
||||
defaultMetadatas[baseMetadata['id']] = baseMetadata;
|
||||
});
|
||||
Object.assign(metadatas, defaultMetadatas);
|
||||
}
|
||||
});
|
||||
|
||||
// metadata for non-english docs
|
||||
files = glob.sync(CWD + "/translated_docs/**");
|
||||
files = glob.sync(CWD + '/translated_docs/**');
|
||||
files.forEach(file => {
|
||||
let language = "en";
|
||||
let language = 'en';
|
||||
const match = regexSubFolder.exec(file);
|
||||
if (match) {
|
||||
language = match[1];
|
||||
|
@ -276,7 +274,7 @@ function generateMetadataDocs() {
|
|||
|
||||
const extension = path.extname(file);
|
||||
|
||||
if (extension === ".md" || extension === ".markdown") {
|
||||
if (extension === '.md' || extension === '.markdown') {
|
||||
const res = processMetadata(file);
|
||||
if (!res) {
|
||||
return;
|
||||
|
@ -295,17 +293,17 @@ function generateMetadataDocs() {
|
|||
metadata.category = order[id].category;
|
||||
if (order[id].next) {
|
||||
metadata.next_id = order[id].next.replace(
|
||||
"version-" + metadata.version + "-",
|
||||
""
|
||||
'version-' + metadata.version + '-',
|
||||
''
|
||||
);
|
||||
metadata.next = metadata.language + "-" + order[id].next;
|
||||
metadata.next = metadata.language + '-' + order[id].next;
|
||||
}
|
||||
if (order[id].previous) {
|
||||
metadata.previous_id = order[id].previous.replace(
|
||||
"version-" + metadata.version + "-",
|
||||
""
|
||||
'version-' + metadata.version + '-',
|
||||
''
|
||||
);
|
||||
metadata.previous = metadata.language + "-" + order[id].previous;
|
||||
metadata.previous = metadata.language + '-' + order[id].previous;
|
||||
}
|
||||
}
|
||||
metadatas[metadata.id] = metadata;
|
||||
|
@ -319,7 +317,7 @@ function generateMetadataDocs() {
|
|||
metadatas[metadata].previous_title =
|
||||
metadatas[metadatas[metadata].previous].title;
|
||||
} else {
|
||||
metadatas[metadata].previous_title = "Previous";
|
||||
metadatas[metadata].previous_title = 'Previous';
|
||||
}
|
||||
}
|
||||
if (metadatas[metadata].next) {
|
||||
|
@ -327,19 +325,19 @@ function generateMetadataDocs() {
|
|||
metadatas[metadata].next_title =
|
||||
metadatas[metadatas[metadata].next].title;
|
||||
} else {
|
||||
metadatas[metadata].next_title = "Next";
|
||||
metadatas[metadata].next_title = 'Next';
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
fs.writeFileSync(
|
||||
__dirname + "/../core/metadata.js",
|
||||
"/**\n" +
|
||||
" * @generated\n" +
|
||||
" */\n" +
|
||||
"module.exports = " +
|
||||
__dirname + '/../core/metadata.js',
|
||||
'/**\n' +
|
||||
' * @generated\n' +
|
||||
' */\n' +
|
||||
'module.exports = ' +
|
||||
JSON.stringify(metadatas, null, 2) +
|
||||
";"
|
||||
';'
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -347,11 +345,11 @@ function generateMetadataDocs() {
|
|||
function generateMetadataBlog() {
|
||||
const metadatas = [];
|
||||
|
||||
let files = glob.sync(CWD + "/blog/**/*.*");
|
||||
let files = glob.sync(CWD + '/blog/**/*.*');
|
||||
if (!files || files.length == 0) {
|
||||
console.error(
|
||||
`${chalk.yellow(
|
||||
CWD + "/blog/ appears to be empty"
|
||||
CWD + '/blog/ appears to be empty'
|
||||
)} Make sure you've put your blog files in your Docusaurus 'website' folder.`
|
||||
);
|
||||
}
|
||||
|
@ -360,7 +358,7 @@ function generateMetadataBlog() {
|
|||
.reverse()
|
||||
.forEach(file => {
|
||||
const extension = path.extname(file);
|
||||
if (extension !== ".md" && extension !== ".markdown") {
|
||||
if (extension !== '.md' && extension !== '.markdown') {
|
||||
return;
|
||||
}
|
||||
// Transform
|
||||
|
@ -369,16 +367,14 @@ function generateMetadataBlog() {
|
|||
// 2015/08/13/blog-post-name-0-5.html
|
||||
const filePath = path
|
||||
.basename(file)
|
||||
.replace("-", "/")
|
||||
.replace("-", "/")
|
||||
.replace("-", "/")
|
||||
.replace(/\.md$/, ".html");
|
||||
const result = extractMetadata(
|
||||
fs.readFileSync(file, { encoding: "utf8" })
|
||||
);
|
||||
.replace('-', '/')
|
||||
.replace('-', '/')
|
||||
.replace('-', '/')
|
||||
.replace(/\.md$/, '.html');
|
||||
const result = extractMetadata(fs.readFileSync(file, {encoding: 'utf8'}));
|
||||
const rawContent = result.rawContent;
|
||||
const metadata = Object.assign(
|
||||
{ path: filePath, content: rawContent },
|
||||
{path: filePath, content: rawContent},
|
||||
result.metadata
|
||||
);
|
||||
|
||||
|
@ -388,27 +384,27 @@ function generateMetadataBlog() {
|
|||
let filePathDateArr = path
|
||||
.basename(file)
|
||||
.toString()
|
||||
.split("-");
|
||||
.split('-');
|
||||
metadata.date = new Date(
|
||||
filePathDateArr[0] +
|
||||
"-" +
|
||||
'-' +
|
||||
filePathDateArr[1] +
|
||||
"-" +
|
||||
'-' +
|
||||
filePathDateArr[2] +
|
||||
"T06:00:00.000Z"
|
||||
'T06:00:00.000Z'
|
||||
);
|
||||
|
||||
metadatas.push(metadata);
|
||||
});
|
||||
|
||||
fs.writeFileSync(
|
||||
__dirname + "/../core/MetadataBlog.js",
|
||||
"/**\n" +
|
||||
" * @generated\n" +
|
||||
" */\n" +
|
||||
"module.exports = " +
|
||||
__dirname + '/../core/MetadataBlog.js',
|
||||
'/**\n' +
|
||||
' * @generated\n' +
|
||||
' */\n' +
|
||||
'module.exports = ' +
|
||||
JSON.stringify(metadatas, null, 2) +
|
||||
";"
|
||||
';'
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -418,5 +414,5 @@ module.exports = {
|
|||
extractMetadata,
|
||||
processMetadata,
|
||||
generateMetadataDocs,
|
||||
generateMetadataBlog
|
||||
generateMetadataBlog,
|
||||
};
|
||||
|
|
|
@ -7,30 +7,30 @@
|
|||
*/
|
||||
|
||||
function execute(port) {
|
||||
const extractTranslations = require("../write-translations.js");
|
||||
const extractTranslations = require('../write-translations.js');
|
||||
|
||||
const translation = require("./translation.js");
|
||||
const express = require("express");
|
||||
const React = require("react");
|
||||
const request = require("request");
|
||||
const renderToStaticMarkup = require("react-dom/server").renderToStaticMarkup;
|
||||
const fs = require("fs-extra");
|
||||
const os = require("os");
|
||||
const path = require("path");
|
||||
const toSlug = require("../core/toSlug.js");
|
||||
const mkdirp = require("mkdirp");
|
||||
const glob = require("glob");
|
||||
const chalk = require("chalk");
|
||||
const translate = require("./translate.js");
|
||||
const versionFallback = require("./versionFallback");
|
||||
const translation = require('./translation.js');
|
||||
const express = require('express');
|
||||
const React = require('react');
|
||||
const request = require('request');
|
||||
const renderToStaticMarkup = require('react-dom/server').renderToStaticMarkup;
|
||||
const fs = require('fs-extra');
|
||||
const os = require('os');
|
||||
const path = require('path');
|
||||
const toSlug = require('../core/toSlug.js');
|
||||
const mkdirp = require('mkdirp');
|
||||
const glob = require('glob');
|
||||
const chalk = require('chalk');
|
||||
const translate = require('./translate.js');
|
||||
const versionFallback = require('./versionFallback');
|
||||
|
||||
const feed = require("./feed.js");
|
||||
const sitemap = require("./sitemap.js");
|
||||
const feed = require('./feed.js');
|
||||
const sitemap = require('./sitemap.js');
|
||||
// const sitemap = require("sitemap");
|
||||
|
||||
const CWD = process.cwd();
|
||||
const ENABLE_TRANSLATION = fs.existsSync(CWD + "/languages.js");
|
||||
const ENABLE_VERSIONING = fs.existsSync(CWD + "/versions.json");
|
||||
const ENABLE_TRANSLATION = fs.existsSync(CWD + '/languages.js');
|
||||
const ENABLE_VERSIONING = fs.existsSync(CWD + '/versions.json');
|
||||
|
||||
// remove a module and child modules from require cache, so server does not have
|
||||
// to be restarted
|
||||
|
@ -56,39 +56,39 @@ function execute(port) {
|
|||
|
||||
/****************************************************************************/
|
||||
|
||||
let readMetadata = require("./readMetadata.js");
|
||||
let readMetadata = require('./readMetadata.js');
|
||||
let Metadata;
|
||||
let MetadataBlog;
|
||||
let siteConfig;
|
||||
|
||||
function reloadMetadata() {
|
||||
removeModuleAndChildrenFromCache("./readMetadata.js");
|
||||
removeModuleAndChildrenFromCache('./readMetadata.js');
|
||||
readMetadata.generateMetadataDocs();
|
||||
removeModuleAndChildrenFromCache("../core/metadata.js");
|
||||
Metadata = require("../core/metadata.js");
|
||||
removeModuleAndChildrenFromCache('../core/metadata.js');
|
||||
Metadata = require('../core/metadata.js');
|
||||
}
|
||||
|
||||
function reloadMetadataBlog() {
|
||||
if (fs.existsSync(__dirname + "/../core/MetadataBlog.js")) {
|
||||
removeModuleAndChildrenFromCache("../core/MetadataBlog.js");
|
||||
fs.removeSync(__dirname + "/../core/MetadataBlog.js");
|
||||
if (fs.existsSync(__dirname + '/../core/MetadataBlog.js')) {
|
||||
removeModuleAndChildrenFromCache('../core/MetadataBlog.js');
|
||||
fs.removeSync(__dirname + '/../core/MetadataBlog.js');
|
||||
}
|
||||
readMetadata.generateMetadataBlog();
|
||||
MetadataBlog = require("../core/MetadataBlog.js");
|
||||
MetadataBlog = require('../core/MetadataBlog.js');
|
||||
}
|
||||
|
||||
function reloadSiteConfig() {
|
||||
removeModuleAndChildrenFromCache(CWD + "/siteConfig.js");
|
||||
siteConfig = require(CWD + "/siteConfig.js");
|
||||
removeModuleAndChildrenFromCache(CWD + '/siteConfig.js');
|
||||
siteConfig = require(CWD + '/siteConfig.js');
|
||||
|
||||
if (siteConfig.highlight && siteConfig.highlight.hljs) {
|
||||
siteConfig.highlight.hljs(require("highlight.js"));
|
||||
siteConfig.highlight.hljs(require('highlight.js'));
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
const TABLE_OF_CONTENTS_TOKEN = "<AUTOGENERATED_TABLE_OF_CONTENTS>";
|
||||
const TABLE_OF_CONTENTS_TOKEN = '<AUTOGENERATED_TABLE_OF_CONTENTS>';
|
||||
|
||||
const insertTableOfContents = rawContent => {
|
||||
const regexp = /\n###\s+(`.*`.*)\n/g;
|
||||
|
@ -100,7 +100,7 @@ function execute(port) {
|
|||
|
||||
const tableOfContents = headers
|
||||
.map(header => ` - [${header}](#${toSlug(header)})`)
|
||||
.join("\n");
|
||||
.join('\n');
|
||||
|
||||
return rawContent.replace(TABLE_OF_CONTENTS_TOKEN, tableOfContents);
|
||||
};
|
||||
|
@ -121,7 +121,7 @@ function execute(port) {
|
|||
|
||||
/****************************************************************************/
|
||||
|
||||
console.log("server.js triggered...");
|
||||
console.log('server.js triggered...');
|
||||
|
||||
reloadMetadata();
|
||||
reloadMetadataBlog();
|
||||
|
@ -132,7 +132,7 @@ function execute(port) {
|
|||
const app = express();
|
||||
|
||||
app.get(/docs\/.*html$/, (req, res, next) => {
|
||||
let url = req.path.toString().replace(siteConfig.baseUrl, "");
|
||||
let url = req.path.toString().replace(siteConfig.baseUrl, '');
|
||||
|
||||
// links is a map from a permalink to an id for each document
|
||||
let links = {};
|
||||
|
@ -146,15 +146,15 @@ function execute(port) {
|
|||
const mdToHtml = {};
|
||||
Object.keys(Metadata).forEach(id => {
|
||||
const metadata = Metadata[id];
|
||||
if (metadata.language !== "en" || metadata.original_id) {
|
||||
if (metadata.language !== 'en' || metadata.original_id) {
|
||||
return;
|
||||
}
|
||||
let htmlLink =
|
||||
siteConfig.baseUrl + metadata.permalink.replace("/next/", "/");
|
||||
if (htmlLink.includes("/docs/en/")) {
|
||||
htmlLink = htmlLink.replace("/docs/en/", "/docs/en/VERSION/");
|
||||
siteConfig.baseUrl + metadata.permalink.replace('/next/', '/');
|
||||
if (htmlLink.includes('/docs/en/')) {
|
||||
htmlLink = htmlLink.replace('/docs/en/', '/docs/en/VERSION/');
|
||||
} else {
|
||||
htmlLink = htmlLink.replace("/docs/", "/docs/VERSION/");
|
||||
htmlLink = htmlLink.replace('/docs/', '/docs/VERSION/');
|
||||
}
|
||||
mdToHtml[metadata.source] = htmlLink;
|
||||
});
|
||||
|
@ -169,18 +169,19 @@ function execute(port) {
|
|||
// determine what file to use according to its id
|
||||
let file;
|
||||
if (metadata.original_id) {
|
||||
if (ENABLE_TRANSLATION && metadata.language !== "en") {
|
||||
if (ENABLE_TRANSLATION && metadata.language !== 'en') {
|
||||
file =
|
||||
CWD + "/translated_docs/" + metadata.language + "/" + metadata.source;
|
||||
CWD + '/translated_docs/' + metadata.language + '/' + metadata.source;
|
||||
} else {
|
||||
file = CWD + "/versioned_docs/" + metadata.source;
|
||||
file = CWD + '/versioned_docs/' + metadata.source;
|
||||
}
|
||||
} else {
|
||||
if (metadata.language === "en") {
|
||||
file = CWD + "/../" + readMetadata.getDocsPath() + "/" + metadata.source;
|
||||
if (metadata.language === 'en') {
|
||||
file =
|
||||
CWD + '/../' + readMetadata.getDocsPath() + '/' + metadata.source;
|
||||
} else {
|
||||
file =
|
||||
CWD + "/translated_docs/" + metadata.language + "/" + metadata.source;
|
||||
CWD + '/translated_docs/' + metadata.language + '/' + metadata.source;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -189,7 +190,7 @@ function execute(port) {
|
|||
return;
|
||||
}
|
||||
|
||||
let rawContent = readMetadata.extractMetadata(fs.readFileSync(file, "utf8"))
|
||||
let rawContent = readMetadata.extractMetadata(fs.readFileSync(file, 'utf8'))
|
||||
.rawContent;
|
||||
|
||||
// generate table of contents if appropriate
|
||||
|
@ -200,46 +201,46 @@ function execute(port) {
|
|||
let latestVersion;
|
||||
if (ENABLE_VERSIONING) {
|
||||
latestVersion = JSON.parse(
|
||||
fs.readFileSync(CWD + "/versions.json", "utf8")
|
||||
fs.readFileSync(CWD + '/versions.json', 'utf8')
|
||||
)[0];
|
||||
}
|
||||
|
||||
// replace any links to markdown files to their website html links
|
||||
Object.keys(mdToHtml).forEach(function(key, index) {
|
||||
let link = mdToHtml[key];
|
||||
link = link.replace("/en/", "/" + language + "/");
|
||||
link = link.replace('/en/', '/' + language + '/');
|
||||
link = link.replace(
|
||||
"/VERSION/",
|
||||
'/VERSION/',
|
||||
metadata.version && metadata.version !== latestVersion
|
||||
? "/" + metadata.version + "/"
|
||||
: "/"
|
||||
? '/' + metadata.version + '/'
|
||||
: '/'
|
||||
);
|
||||
// replace relative links without "./"
|
||||
rawContent = rawContent.replace(
|
||||
new RegExp("\\]\\(" + key, "g"),
|
||||
"](" + link
|
||||
new RegExp('\\]\\(' + key, 'g'),
|
||||
'](' + link
|
||||
);
|
||||
// replace relative links with "./"
|
||||
rawContent = rawContent.replace(
|
||||
new RegExp("\\]\\(\\./" + key, "g"),
|
||||
"](" + link
|
||||
new RegExp('\\]\\(\\./' + key, 'g'),
|
||||
'](' + link
|
||||
);
|
||||
});
|
||||
|
||||
// replace any relative links to static assets to absolute links
|
||||
rawContent = rawContent.replace(
|
||||
/\]\(assets\//g,
|
||||
"](" + siteConfig.baseUrl + "docs/assets/"
|
||||
'](' + siteConfig.baseUrl + 'docs/assets/'
|
||||
);
|
||||
|
||||
removeModuleAndChildrenFromCache("../core/DocsLayout.js");
|
||||
const DocsLayout = require("../core/DocsLayout.js");
|
||||
removeModuleAndChildrenFromCache('../core/DocsLayout.js');
|
||||
const DocsLayout = require('../core/DocsLayout.js');
|
||||
|
||||
let Doc;
|
||||
if (metadata.layout && siteConfig.layouts[metadata.layout]) {
|
||||
Doc = siteConfig.layouts[metadata.layout]({
|
||||
React,
|
||||
MarkdownBlock: require("../core/MarkdownBlock.js")
|
||||
MarkdownBlock: require('../core/MarkdownBlock.js'),
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -256,38 +257,38 @@ function execute(port) {
|
|||
res.send(renderToStaticMarkup(docComp));
|
||||
});
|
||||
|
||||
app.get("/sitemap.xml", function(req, res) {
|
||||
res.set("Content-Type", "application/xml");
|
||||
app.get('/sitemap.xml', function(req, res) {
|
||||
res.set('Content-Type', 'application/xml');
|
||||
|
||||
sitemap(xml => {
|
||||
res.send(xml);
|
||||
});
|
||||
});
|
||||
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"));
|
||||
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"));
|
||||
res.send(feed('rss'));
|
||||
});
|
||||
|
||||
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"));
|
||||
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"));
|
||||
res.send(feed('rss'));
|
||||
});
|
||||
|
||||
// handle all requests for blog pages and posts
|
||||
app.get(/blog\/.*html$/, (req, res) => {
|
||||
// generate all of the blog pages
|
||||
removeModuleAndChildrenFromCache("../core/BlogPageLayout.js");
|
||||
const BlogPageLayout = require("../core/BlogPageLayout.js");
|
||||
removeModuleAndChildrenFromCache('../core/BlogPageLayout.js');
|
||||
const BlogPageLayout = require('../core/BlogPageLayout.js');
|
||||
const blogPages = {};
|
||||
// make blog pages with 10 posts per page
|
||||
const perPage = 10;
|
||||
|
@ -296,8 +297,8 @@ function execute(port) {
|
|||
page < Math.ceil(MetadataBlog.length / perPage);
|
||||
page++
|
||||
) {
|
||||
let language = "en";
|
||||
const metadata = { page: page, perPage: perPage };
|
||||
let language = 'en';
|
||||
const metadata = {page: page, perPage: perPage};
|
||||
const blogPageComp = (
|
||||
<BlogPageLayout
|
||||
metadata={metadata}
|
||||
|
@ -307,46 +308,46 @@ function execute(port) {
|
|||
);
|
||||
const str = renderToStaticMarkup(blogPageComp);
|
||||
|
||||
let path = (page > 0 ? "page" + (page + 1) : "") + "/index.html";
|
||||
let path = (page > 0 ? 'page' + (page + 1) : '') + '/index.html';
|
||||
blogPages[path] = str;
|
||||
}
|
||||
|
||||
let parts = req.path.toString().split("blog/");
|
||||
let parts = req.path.toString().split('blog/');
|
||||
// send corresponding blog page if appropriate
|
||||
if (parts[1] === "index.html") {
|
||||
res.send(blogPages["/index.html"]);
|
||||
} else if (parts[1].endsWith("/index.html")) {
|
||||
if (parts[1] === 'index.html') {
|
||||
res.send(blogPages['/index.html']);
|
||||
} else if (parts[1].endsWith('/index.html')) {
|
||||
res.send(blogPages[parts[1]]);
|
||||
} else if (parts[1].match(/page([0-9]+)/)) {
|
||||
if (parts[1].endsWith("/")) {
|
||||
res.send(blogPages[parts[1] + "index.html"]);
|
||||
if (parts[1].endsWith('/')) {
|
||||
res.send(blogPages[parts[1] + 'index.html']);
|
||||
} else {
|
||||
res.send(blogPages[parts[1] + "/index.html"]);
|
||||
res.send(blogPages[parts[1] + '/index.html']);
|
||||
}
|
||||
} else {
|
||||
// else send corresponding blog post
|
||||
let file = parts[1];
|
||||
file = file.replace(/\.html$/, ".md");
|
||||
file = file.replace(new RegExp("/", "g"), "-");
|
||||
file = CWD + "/blog/" + file;
|
||||
file = file.replace(/\.html$/, '.md');
|
||||
file = file.replace(new RegExp('/', 'g'), '-');
|
||||
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(
|
||||
/\]\(assets\//g,
|
||||
"](" + siteConfig.baseUrl + "blog/assets/"
|
||||
'](' + 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;
|
||||
|
||||
let language = "en";
|
||||
removeModuleAndChildrenFromCache("../core/BlogPostLayout.js");
|
||||
const BlogPostLayout = require("../core/BlogPostLayout.js");
|
||||
let language = 'en';
|
||||
removeModuleAndChildrenFromCache('../core/BlogPostLayout.js');
|
||||
const BlogPostLayout = require('../core/BlogPostLayout.js');
|
||||
|
||||
const blogPostComp = (
|
||||
<BlogPostLayout
|
||||
|
@ -361,44 +362,44 @@ function execute(port) {
|
|||
});
|
||||
|
||||
// handle all other main pages
|
||||
app.get("*.html", (req, res, next) => {
|
||||
app.get('*.html', (req, res, next) => {
|
||||
// look for user provided html file first
|
||||
let htmlFile = req.path.toString().replace(siteConfig.baseUrl, "");
|
||||
htmlFile = CWD + "/pages/" + htmlFile;
|
||||
let htmlFile = req.path.toString().replace(siteConfig.baseUrl, '');
|
||||
htmlFile = CWD + '/pages/' + htmlFile;
|
||||
if (
|
||||
fs.existsSync(htmlFile) ||
|
||||
fs.existsSync(
|
||||
(htmlFile = htmlFile.replace(
|
||||
path.basename(htmlFile),
|
||||
"en/" + path.basename(htmlFile)
|
||||
'en/' + path.basename(htmlFile)
|
||||
))
|
||||
)
|
||||
) {
|
||||
res.send(fs.readFileSync(htmlFile, { encoding: "utf8" }));
|
||||
res.send(fs.readFileSync(htmlFile, {encoding: 'utf8'}));
|
||||
return;
|
||||
}
|
||||
|
||||
// look for user provided react file either in specified path or in path for english files
|
||||
let file = req.path.toString().replace(/\.html$/, ".js");
|
||||
file = file.replace(siteConfig.baseUrl, "");
|
||||
let userFile = CWD + "/pages/" + file;
|
||||
let file = req.path.toString().replace(/\.html$/, '.js');
|
||||
file = file.replace(siteConfig.baseUrl, '');
|
||||
let userFile = CWD + '/pages/' + file;
|
||||
|
||||
let language = "en";
|
||||
let language = 'en';
|
||||
const regexLang = /(.*)\/.*\.html$/;
|
||||
const match = regexLang.exec(req.path);
|
||||
const parts = match[1].split("/");
|
||||
const parts = match[1].split('/');
|
||||
const enabledLangTags = [];
|
||||
for (let i = 0; i < translation["languages"].length; i++) {
|
||||
enabledLangTags.push(translation["languages"][i].tag);
|
||||
for (let i = 0; i < translation['languages'].length; i++) {
|
||||
enabledLangTags.push(translation['languages'][i].tag);
|
||||
}
|
||||
for (let i = 0; i < parts.length; i++) {
|
||||
if (enabledLangTags.indexOf(parts[i]) !== -1) {
|
||||
language = parts[i];
|
||||
}
|
||||
}
|
||||
let englishFile = CWD + "/pages/" + file;
|
||||
if (language !== "en") {
|
||||
englishFile = englishFile.replace("/" + language + "/", "/en/");
|
||||
let englishFile = CWD + '/pages/' + file;
|
||||
if (language !== 'en') {
|
||||
englishFile = englishFile.replace('/' + language + '/', '/en/');
|
||||
}
|
||||
|
||||
// check for: a file for the page, an english file for page with unspecified language, or an
|
||||
|
@ -408,26 +409,26 @@ function execute(port) {
|
|||
fs.existsSync(
|
||||
(userFile = userFile.replace(
|
||||
path.basename(userFile),
|
||||
"en/" + path.basename(userFile)
|
||||
'en/' + path.basename(userFile)
|
||||
))
|
||||
) ||
|
||||
fs.existsSync((userFile = englishFile))
|
||||
) {
|
||||
// copy into docusaurus so require paths work
|
||||
let parts = userFile.split("pages/");
|
||||
let tempFile = __dirname + "/../pages/" + parts[1];
|
||||
let parts = userFile.split('pages/');
|
||||
let tempFile = __dirname + '/../pages/' + parts[1];
|
||||
tempFile = tempFile.replace(
|
||||
path.basename(file),
|
||||
"temp" + path.basename(file)
|
||||
'temp' + path.basename(file)
|
||||
);
|
||||
mkdirp.sync(tempFile.replace(new RegExp("/[^/]*$"), ""));
|
||||
mkdirp.sync(tempFile.replace(new RegExp('/[^/]*$'), ''));
|
||||
fs.copySync(userFile, tempFile);
|
||||
|
||||
// render into a string
|
||||
removeModuleAndChildrenFromCache(tempFile);
|
||||
const ReactComp = require(tempFile);
|
||||
removeModuleAndChildrenFromCache("../core/Site.js");
|
||||
const Site = require("../core/Site.js");
|
||||
removeModuleAndChildrenFromCache('../core/Site.js');
|
||||
const Site = require('../core/Site.js');
|
||||
translate.setLanguage(language);
|
||||
const str = renderToStaticMarkup(
|
||||
<Site language={language} config={siteConfig}>
|
||||
|
@ -448,18 +449,18 @@ function execute(port) {
|
|||
app.get(/main\.css$/, (req, res) => {
|
||||
const mainCssPath =
|
||||
__dirname +
|
||||
"/../static/" +
|
||||
req.path.toString().replace(siteConfig.baseUrl, "/");
|
||||
let cssContent = fs.readFileSync(mainCssPath, { encoding: "utf8" });
|
||||
'/../static/' +
|
||||
req.path.toString().replace(siteConfig.baseUrl, '/');
|
||||
let cssContent = fs.readFileSync(mainCssPath, {encoding: 'utf8'});
|
||||
|
||||
let files = glob.sync(CWD + "/static/**/*.css");
|
||||
let files = glob.sync(CWD + '/static/**/*.css');
|
||||
|
||||
files.forEach(file => {
|
||||
if (isSeparateCss(file)) {
|
||||
return;
|
||||
}
|
||||
cssContent =
|
||||
cssContent + "\n" + fs.readFileSync(file, { encoding: "utf8" });
|
||||
cssContent + '\n' + fs.readFileSync(file, {encoding: 'utf8'});
|
||||
});
|
||||
|
||||
if (
|
||||
|
@ -469,14 +470,14 @@ function execute(port) {
|
|||
) {
|
||||
console.error(
|
||||
`${chalk.yellow(
|
||||
"Missing color configuration."
|
||||
'Missing color configuration.'
|
||||
)} Make sure siteConfig.colors includes primaryColor and secondaryColor fields.`
|
||||
);
|
||||
}
|
||||
|
||||
Object.keys(siteConfig.colors).forEach(key => {
|
||||
const color = siteConfig.colors[key];
|
||||
cssContent = cssContent.replace(new RegExp("\\$" + key, "g"), color);
|
||||
cssContent = cssContent.replace(new RegExp('\\$' + key, 'g'), color);
|
||||
});
|
||||
|
||||
res.send(cssContent);
|
||||
|
@ -484,22 +485,22 @@ function execute(port) {
|
|||
|
||||
// serve static assets from these locations
|
||||
app.use(
|
||||
siteConfig.baseUrl + "docs/assets/",
|
||||
express.static(CWD + "/../" + readMetadata.getDocsPath() + "/assets")
|
||||
siteConfig.baseUrl + 'docs/assets/',
|
||||
express.static(CWD + '/../' + readMetadata.getDocsPath() + '/assets')
|
||||
);
|
||||
app.use(
|
||||
siteConfig.baseUrl + "blog/assets/",
|
||||
express.static(CWD + "/blog/assets")
|
||||
siteConfig.baseUrl + 'blog/assets/',
|
||||
express.static(CWD + '/blog/assets')
|
||||
);
|
||||
app.use(siteConfig.baseUrl, express.static(CWD + "/static"));
|
||||
app.use(siteConfig.baseUrl, express.static(__dirname + "/../static"));
|
||||
app.use(siteConfig.baseUrl, express.static(CWD + '/static'));
|
||||
app.use(siteConfig.baseUrl, express.static(__dirname + '/../static'));
|
||||
|
||||
// "redirect" requests to pages ending with "/" or no extension so that
|
||||
// request to "...blog" returns same result as "...blog/index.html"
|
||||
app.get(/\/[^\.]*\/?$/, (req, res) => {
|
||||
if (req.path.toString().endsWith("/")) {
|
||||
if (req.path.toString().endsWith('/')) {
|
||||
request.get(
|
||||
"http://localhost:" + port + req.path + "index.html",
|
||||
'http://localhost:' + port + req.path + 'index.html',
|
||||
(err, response, body) => {
|
||||
if (!err) {
|
||||
res.send(body);
|
||||
|
@ -508,7 +509,7 @@ function execute(port) {
|
|||
);
|
||||
} else {
|
||||
request.get(
|
||||
"http://localhost:" + port + req.path + "/index.html",
|
||||
'http://localhost:' + port + req.path + '/index.html',
|
||||
(err, response, body) => {
|
||||
if (!err) {
|
||||
res.send(body);
|
||||
|
@ -519,8 +520,8 @@ function execute(port) {
|
|||
});
|
||||
|
||||
app.listen(port);
|
||||
console.log("listening on port: " + port);
|
||||
console.log("Open http://localhost:" + port + "/");
|
||||
console.log('listening on port: ' + port);
|
||||
console.log('Open http://localhost:' + port + '/');
|
||||
}
|
||||
|
||||
module.exports = execute;
|
||||
|
|
|
@ -5,21 +5,21 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
const fs = require("fs-extra");
|
||||
const path = require("path");
|
||||
const os = require("os");
|
||||
const Feed = require("feed");
|
||||
const fs = require('fs-extra');
|
||||
const path = require('path');
|
||||
const os = require('os');
|
||||
const Feed = require('feed');
|
||||
|
||||
const chalk = require("chalk");
|
||||
const glob = require("glob");
|
||||
const chalk = require('chalk');
|
||||
const glob = require('glob');
|
||||
const CWD = process.cwd();
|
||||
|
||||
const sitemap = require("sitemap");
|
||||
const sitemap = require('sitemap');
|
||||
|
||||
const siteConfig = require(CWD + "/siteConfig.js");
|
||||
const siteConfig = require(CWD + '/siteConfig.js');
|
||||
|
||||
const blogFolder = path.resolve("../blog/");
|
||||
const blogRootURL = siteConfig.url + "/blog";
|
||||
const blogFolder = path.resolve('../blog/');
|
||||
const blogRootURL = siteConfig.url + '/blog';
|
||||
const jestImage = siteConfig.url + siteConfig.headerIcon;
|
||||
|
||||
/****************************************************************************/
|
||||
|
@ -28,32 +28,33 @@ let readMetadata;
|
|||
let Metadata;
|
||||
let MetadataBlog;
|
||||
|
||||
readMetadata = require("./readMetadata.js");
|
||||
readMetadata = require('./readMetadata.js');
|
||||
readMetadata.generateMetadataDocs();
|
||||
Metadata = require("../core/metadata.js");
|
||||
Metadata = require('../core/metadata.js');
|
||||
readMetadata.generateMetadataBlog();
|
||||
MetadataBlog = require("../core/MetadataBlog.js");
|
||||
|
||||
MetadataBlog = require('../core/MetadataBlog.js');
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
module.exports = function(callback) {
|
||||
console.log("sitemap.js triggered...");
|
||||
console.log('sitemap.js triggered...');
|
||||
|
||||
let urls = [];
|
||||
|
||||
let files = glob.sync(CWD + "/pages/en/**/*.js");
|
||||
let files = glob.sync(CWD + '/pages/en/**/*.js');
|
||||
|
||||
// English-only is the default.
|
||||
let enabledLanguages = [{
|
||||
enabled: true,
|
||||
name: "English",
|
||||
tag: "en"
|
||||
}];
|
||||
let enabledLanguages = [
|
||||
{
|
||||
enabled: true,
|
||||
name: 'English',
|
||||
tag: 'en',
|
||||
},
|
||||
];
|
||||
|
||||
// If we have a languages.js file, get all the enabled languages in there
|
||||
if (fs.existsSync(CWD + "/languages.js")) {
|
||||
let languages = require(CWD + "/languages.js");
|
||||
if (fs.existsSync(CWD + '/languages.js')) {
|
||||
let languages = require(CWD + '/languages.js');
|
||||
enabledLanguages = languages.filter(lang => {
|
||||
return lang.enabled == true;
|
||||
});
|
||||
|
@ -61,43 +62,50 @@ module.exports = function(callback) {
|
|||
|
||||
// create a url mapping to all the enabled languages files
|
||||
files.map(file => {
|
||||
let url = file.split("/pages/en")[1];
|
||||
url = url.replace(/\.js$/, ".html");
|
||||
let url = file.split('/pages/en')[1];
|
||||
url = url.replace(/\.js$/, '.html');
|
||||
let links = enabledLanguages.map(lang => {
|
||||
let langUrl = lang.tag + url;
|
||||
return { lang: lang.tag, url: langUrl };
|
||||
return {lang: lang.tag, url: langUrl};
|
||||
});
|
||||
urls.push({ url, changefreq: "weekly", priority: 0.5, links });
|
||||
urls.push({url, changefreq: 'weekly', priority: 0.5, links});
|
||||
});
|
||||
|
||||
let htmlFiles = glob.sync(CWD + "/pages/**/*.html");
|
||||
let htmlFiles = glob.sync(CWD + '/pages/**/*.html');
|
||||
|
||||
MetadataBlog.map(blog => {
|
||||
urls.push({
|
||||
url: "/blog/" + blog.path,
|
||||
changefreq: "weekly",
|
||||
priority: 0.3
|
||||
url: '/blog/' + blog.path,
|
||||
changefreq: 'weekly',
|
||||
priority: 0.3,
|
||||
});
|
||||
});
|
||||
|
||||
Object.keys(Metadata).filter(key => Metadata[key].language === "en").map(key => {
|
||||
let doc = Metadata[key];
|
||||
let links = enabledLanguages.map(lang => {
|
||||
let langUrl = doc.permalink.replace("docs/en/", `docs/${lang.tag}/`);
|
||||
return { lang: lang.tag, url: langUrl };
|
||||
Object.keys(Metadata)
|
||||
.filter(key => Metadata[key].language === 'en')
|
||||
.map(key => {
|
||||
let doc = Metadata[key];
|
||||
let links = enabledLanguages.map(lang => {
|
||||
let langUrl = doc.permalink.replace('docs/en/', `docs/${lang.tag}/`);
|
||||
return {lang: lang.tag, url: langUrl};
|
||||
});
|
||||
urls.push({
|
||||
url: doc.permalink,
|
||||
changefreq: 'hourly',
|
||||
priority: 1.0,
|
||||
links,
|
||||
});
|
||||
});
|
||||
urls.push({ url: doc.permalink, changefreq: "hourly", priority: 1.0, links });
|
||||
});
|
||||
|
||||
const sm = sitemap.createSitemap({
|
||||
hostname: siteConfig.url,
|
||||
cacheTime: 600 * 1000, // 600 sec - cache purge period
|
||||
urls: urls
|
||||
urls: urls,
|
||||
});
|
||||
|
||||
sm.toXML((err, xml) => {
|
||||
if (err) {
|
||||
return "An error has occured.";
|
||||
return 'An error has occured.';
|
||||
}
|
||||
callback(xml);
|
||||
});
|
||||
|
|
|
@ -8,40 +8,40 @@
|
|||
/* replaces translate tags with calls to translate function */
|
||||
|
||||
module.exports = function translatePlugin(babel) {
|
||||
const { types: t } = babel;
|
||||
const {types: t} = babel;
|
||||
|
||||
return {
|
||||
visitor: {
|
||||
JSXElement(path) {
|
||||
if (path.node.openingElement.name.name !== "translate") {
|
||||
if (path.node.openingElement.name.name !== 'translate') {
|
||||
return;
|
||||
}
|
||||
/* assume translate element only has one child which is the text */
|
||||
const text = path.node.children[0].value.trim().replace(/\s+/g, " ");
|
||||
let description = "no description given";
|
||||
const text = path.node.children[0].value.trim().replace(/\s+/g, ' ');
|
||||
let description = 'no description given';
|
||||
const attributes = path.node.openingElement.attributes;
|
||||
for (let i = 0; i < attributes.length; i++) {
|
||||
if (attributes[i].name.name === "desc") {
|
||||
if (attributes[i].name.name === 'desc') {
|
||||
description = attributes[i].value.value;
|
||||
}
|
||||
}
|
||||
/* use an expression container if inside a jsxelement */
|
||||
if (path.findParent(path => true).node.type === "JSXElement") {
|
||||
if (path.findParent(path => true).node.type === 'JSXElement') {
|
||||
path.replaceWith(
|
||||
t.jSXExpressionContainer(
|
||||
t.callExpression(t.identifier("translate"), [
|
||||
t.stringLiteral(text + "|" + description)
|
||||
t.callExpression(t.identifier('translate'), [
|
||||
t.stringLiteral(text + '|' + description),
|
||||
])
|
||||
)
|
||||
);
|
||||
} else {
|
||||
path.replaceWith(
|
||||
t.callExpression(t.identifier("translate"), [
|
||||
t.stringLiteral(text + "|" + description)
|
||||
t.callExpression(t.identifier('translate'), [
|
||||
t.stringLiteral(text + '|' + description),
|
||||
])
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
};
|
||||
|
|
|
@ -5,21 +5,21 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
const translation = require("./translation.js");
|
||||
const translation = require('./translation.js');
|
||||
|
||||
let language = "en";
|
||||
let language = 'en';
|
||||
|
||||
/* handle escaped characters that get converted into json strings */
|
||||
function parseEscapeSequences(str) {
|
||||
return str
|
||||
.replace(new RegExp("\\\\n", "g"), "\n")
|
||||
.replace(new RegExp("\\\\b", "g"), "\b")
|
||||
.replace(new RegExp("\\\\f", "g"), "\f")
|
||||
.replace(new RegExp("\\\\r", "g"), "\r")
|
||||
.replace(new RegExp("\\\\t", "g"), "\t")
|
||||
.replace(new RegExp("\\\\'", "g"), "'")
|
||||
.replace(new RegExp('\\\\"', "g"), '"')
|
||||
.replace(new RegExp("\\\\", "g"), "\\");
|
||||
.replace(new RegExp('\\\\n', 'g'), '\n')
|
||||
.replace(new RegExp('\\\\b', 'g'), '\b')
|
||||
.replace(new RegExp('\\\\f', 'g'), '\f')
|
||||
.replace(new RegExp('\\\\r', 'g'), '\r')
|
||||
.replace(new RegExp('\\\\t', 'g'), '\t')
|
||||
.replace(new RegExp("\\\\'", 'g'), "'")
|
||||
.replace(new RegExp('\\\\"', 'g'), '"')
|
||||
.replace(new RegExp('\\\\', 'g'), '\\');
|
||||
}
|
||||
|
||||
function setLanguage(lang) {
|
||||
|
@ -29,14 +29,14 @@ function setLanguage(lang) {
|
|||
function translate(str) {
|
||||
if (
|
||||
!translation[language] ||
|
||||
!translation[language]["pages-strings"] ||
|
||||
!translation[language]["pages-strings"][str]
|
||||
!translation[language]['pages-strings'] ||
|
||||
!translation[language]['pages-strings'][str]
|
||||
) {
|
||||
// if a translated string doesn't exist, but english does then fallback
|
||||
if (
|
||||
translation["en"] &&
|
||||
translation["en"]["pages-strings"] &&
|
||||
translation["en"]["pages-strings"][str]
|
||||
translation['en'] &&
|
||||
translation['en']['pages-strings'] &&
|
||||
translation['en']['pages-strings'][str]
|
||||
) {
|
||||
console.error(
|
||||
"Could not find a string translation in '" +
|
||||
|
@ -46,7 +46,7 @@ function translate(str) {
|
|||
"'. Using English version instead."
|
||||
);
|
||||
|
||||
return parseEscapeSequences(translation["en"]["pages-strings"][str]);
|
||||
return parseEscapeSequences(translation['en']['pages-strings'][str]);
|
||||
}
|
||||
throw new Error(
|
||||
"Text that you've identified for translation ('" +
|
||||
|
@ -54,10 +54,10 @@ function translate(str) {
|
|||
"') hasn't been added to the global list in 'en.json'. To solve this problem run 'yarn write-translations'."
|
||||
);
|
||||
}
|
||||
return parseEscapeSequences(translation[language]["pages-strings"][str]);
|
||||
return parseEscapeSequences(translation[language]['pages-strings'][str]);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
setLanguage: setLanguage,
|
||||
translate: translate
|
||||
translate: translate,
|
||||
};
|
||||
|
|
|
@ -8,35 +8,35 @@
|
|||
// translation object contains all translations for each string in 18n/en.json
|
||||
|
||||
const CWD = process.cwd();
|
||||
const fs = require("fs");
|
||||
const glob = require("glob");
|
||||
const path = require("path");
|
||||
const fs = require('fs');
|
||||
const glob = require('glob');
|
||||
const path = require('path');
|
||||
|
||||
let languages;
|
||||
if (fs.existsSync(CWD + "/languages.js")) {
|
||||
languages = require(CWD + "/languages.js");
|
||||
if (fs.existsSync(CWD + '/languages.js')) {
|
||||
languages = require(CWD + '/languages.js');
|
||||
} else {
|
||||
languages = [
|
||||
{
|
||||
enabled: true,
|
||||
name: "English",
|
||||
tag: "en"
|
||||
}
|
||||
name: 'English',
|
||||
tag: 'en',
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
const enabledLanguages = languages.filter(lang => lang.enabled);
|
||||
|
||||
const translation = { languages: enabledLanguages };
|
||||
const translation = {languages: enabledLanguages};
|
||||
|
||||
const files = glob.sync(CWD + "/i18n/**");
|
||||
const files = glob.sync(CWD + '/i18n/**');
|
||||
const langRegex = /\/i18n\/(.*)\.json$/;
|
||||
|
||||
console.log("Loading translation files...");
|
||||
console.log('Loading translation files...');
|
||||
|
||||
files.forEach(file => {
|
||||
const extension = path.extname(file);
|
||||
if (extension === ".json") {
|
||||
if (extension === '.json') {
|
||||
const match = langRegex.exec(file);
|
||||
const language = match[1];
|
||||
translation[language] = require(file);
|
||||
|
|
|
@ -6,32 +6,32 @@
|
|||
*/
|
||||
|
||||
const CWD = process.cwd();
|
||||
const glob = require("glob");
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const assert = require("assert");
|
||||
const glob = require('glob');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const assert = require('assert');
|
||||
|
||||
const siteConfig = require(CWD + "/siteConfig.js");
|
||||
const siteConfig = require(CWD + '/siteConfig.js');
|
||||
|
||||
const ENABLE_TRANSLATION = fs.existsSync(CWD + "/languages.js");
|
||||
const ENABLE_TRANSLATION = fs.existsSync(CWD + '/languages.js');
|
||||
|
||||
let versions;
|
||||
if (fs.existsSync(CWD + "/versions.json")) {
|
||||
versions = require(CWD + "/versions.json");
|
||||
if (fs.existsSync(CWD + '/versions.json')) {
|
||||
versions = require(CWD + '/versions.json');
|
||||
} else {
|
||||
versions = [];
|
||||
}
|
||||
|
||||
let languages;
|
||||
if (fs.existsSync(CWD + "/languages.js")) {
|
||||
languages = require(CWD + "/languages.js");
|
||||
if (fs.existsSync(CWD + '/languages.js')) {
|
||||
languages = require(CWD + '/languages.js');
|
||||
} else {
|
||||
languages = [
|
||||
{
|
||||
enabled: true,
|
||||
name: "English",
|
||||
tag: "en"
|
||||
}
|
||||
name: 'English',
|
||||
tag: 'en',
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -40,16 +40,16 @@ if (fs.existsSync(CWD + "/languages.js")) {
|
|||
// included to prevent cyclical dependency with readMetadata.js
|
||||
|
||||
function splitHeader(content) {
|
||||
const lines = content.split("\n");
|
||||
const lines = content.split('\n');
|
||||
let i = 1;
|
||||
for (; i < lines.length - 1; ++i) {
|
||||
if (lines[i] === "---") {
|
||||
if (lines[i] === '---') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return {
|
||||
header: lines.slice(1, i + 1).join("\n"),
|
||||
content: lines.slice(i + 1).join("\n")
|
||||
header: lines.slice(1, i + 1).join('\n'),
|
||||
content: lines.slice(i + 1).join('\n'),
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -59,27 +59,27 @@ function extractMetadata(content) {
|
|||
const both = splitHeader(content);
|
||||
// if no content returned, then that means there was no header, and both.header is the content
|
||||
if (!both.content) {
|
||||
return { metadata, rawContent: both.header };
|
||||
return {metadata, rawContent: both.header};
|
||||
}
|
||||
const lines = both.header.split("\n");
|
||||
const lines = both.header.split('\n');
|
||||
for (let i = 0; i < lines.length - 1; ++i) {
|
||||
const keyvalue = lines[i].split(":");
|
||||
const keyvalue = lines[i].split(':');
|
||||
const key = keyvalue[0].trim();
|
||||
let value = keyvalue
|
||||
.slice(1)
|
||||
.join(":")
|
||||
.join(':')
|
||||
.trim();
|
||||
try {
|
||||
value = JSON.parse(value);
|
||||
} catch (e) {}
|
||||
metadata[key] = value;
|
||||
}
|
||||
return { metadata, rawContent: both.content };
|
||||
return {metadata, rawContent: both.content};
|
||||
}
|
||||
|
||||
/*****************************************************************/
|
||||
|
||||
const versionFolder = CWD + "/versioned_docs/";
|
||||
const versionFolder = CWD + '/versioned_docs/';
|
||||
|
||||
// available stores doc ids of documents that are available for
|
||||
// each version
|
||||
|
@ -87,39 +87,47 @@ const available = {};
|
|||
// versionFiles is used to keep track of what file to use with a
|
||||
// given version/id of a document
|
||||
const versionFiles = {};
|
||||
let files = glob.sync(versionFolder + "**");
|
||||
let files = glob.sync(versionFolder + '**');
|
||||
files.forEach(file => {
|
||||
const ext = path.extname(file);
|
||||
if (ext !== ".md" && ext !== ".markdown") {
|
||||
if (ext !== '.md' && ext !== '.markdown') {
|
||||
return;
|
||||
}
|
||||
const res = extractMetadata(fs.readFileSync(file, "utf8"));
|
||||
const res = extractMetadata(fs.readFileSync(file, 'utf8'));
|
||||
const metadata = res.metadata;
|
||||
|
||||
if (!metadata.original_id) {
|
||||
console.error(
|
||||
`No 'original_id' field found in ${file}. Perhaps you forgot to add it when importing prior versions of your docs?`
|
||||
`No 'original_id' field found in ${
|
||||
file
|
||||
}. Perhaps you forgot to add it when importing prior versions of your docs?`
|
||||
);
|
||||
throw new Error(
|
||||
`No 'original_id' field found in ${file}. Perhaps you forgot to add it when importing prior versions of your docs?`
|
||||
`No 'original_id' field found in ${
|
||||
file
|
||||
}. Perhaps you forgot to add it when importing prior versions of your docs?`
|
||||
);
|
||||
}
|
||||
if (!metadata.id) {
|
||||
console.error(`No 'id' field found in ${file}.`);
|
||||
throw new Error(`No 'id' field found in ${file}.`);
|
||||
} else if (metadata.id.indexOf("version-") === -1) {
|
||||
} else if (metadata.id.indexOf('version-') === -1) {
|
||||
console.error(
|
||||
`The 'id' field in ${file} is missing the expected 'version-XX-' prefix. Perhaps you forgot to add it when importing prior versions of your docs?`
|
||||
`The 'id' field in ${
|
||||
file
|
||||
} is missing the expected 'version-XX-' prefix. Perhaps you forgot to add it when importing prior versions of your docs?`
|
||||
);
|
||||
throw new Error(
|
||||
`The 'id' field in ${file} is missing the expected 'version-XX-' prefix. Perhaps you forgot to add it when importing prior versions of your docs?`
|
||||
`The 'id' field in ${
|
||||
file
|
||||
} is missing the expected 'version-XX-' prefix. Perhaps you forgot to add it when importing prior versions of your docs?`
|
||||
);
|
||||
}
|
||||
|
||||
if (!(metadata.original_id in available)) {
|
||||
available[metadata.original_id] = new Set();
|
||||
}
|
||||
const version = metadata.id.split("-")[1];
|
||||
const version = metadata.id.split('-')[1];
|
||||
available[metadata.original_id].add(version);
|
||||
|
||||
if (!(version in versionFiles)) {
|
||||
|
@ -133,7 +141,9 @@ files.forEach(file => {
|
|||
function docVersion(id, req_version) {
|
||||
if (!available[id]) {
|
||||
throw new Error(
|
||||
`Document with id '${id}' was requested but no document with that id could be located.`
|
||||
`Document with id '${
|
||||
id
|
||||
}' was requested but no document with that id could be located.`
|
||||
);
|
||||
}
|
||||
// iterate through versions until a version less than or equal to the requested
|
||||
|
@ -179,40 +189,40 @@ function diffLatestDoc(file, id) {
|
|||
}
|
||||
|
||||
return (
|
||||
extractMetadata(fs.readFileSync(latestFile, "utf8")).rawContent.trim() !==
|
||||
extractMetadata(fs.readFileSync(file, "utf8")).rawContent.trim()
|
||||
extractMetadata(fs.readFileSync(latestFile, 'utf8')).rawContent.trim() !==
|
||||
extractMetadata(fs.readFileSync(file, 'utf8')).rawContent.trim()
|
||||
);
|
||||
}
|
||||
|
||||
// return metadata for a versioned file given the file, its version (requested),
|
||||
// the version of the file to be used, and its language
|
||||
function processVersionMetadata(file, version, useVersion, language) {
|
||||
const metadata = extractMetadata(fs.readFileSync(file, "utf8")).metadata;
|
||||
metadata.source = "version-" + useVersion + "/" + path.basename(file);
|
||||
const metadata = extractMetadata(fs.readFileSync(file, 'utf8')).metadata;
|
||||
metadata.source = 'version-' + useVersion + '/' + path.basename(file);
|
||||
|
||||
const latestVersion = versions[0];
|
||||
|
||||
if (!ENABLE_TRANSLATION && !siteConfig.useEnglishUrl) {
|
||||
metadata.permalink =
|
||||
"docs/" +
|
||||
(version !== latestVersion ? version + "/" : "") +
|
||||
'docs/' +
|
||||
(version !== latestVersion ? version + '/' : '') +
|
||||
metadata.original_id +
|
||||
".html";
|
||||
'.html';
|
||||
} else {
|
||||
metadata.permalink =
|
||||
"docs/" +
|
||||
'docs/' +
|
||||
language +
|
||||
"/" +
|
||||
(version !== latestVersion ? version + "/" : "") +
|
||||
'/' +
|
||||
(version !== latestVersion ? version + '/' : '') +
|
||||
metadata.original_id +
|
||||
".html";
|
||||
'.html';
|
||||
}
|
||||
metadata.id = metadata.id.replace(
|
||||
"version-" + useVersion + "-",
|
||||
"version-" + version + "-"
|
||||
'version-' + useVersion + '-',
|
||||
'version-' + version + '-'
|
||||
);
|
||||
metadata.localized_id = metadata.id;
|
||||
metadata.id = language + "-" + metadata.id;
|
||||
metadata.id = language + '-' + metadata.id;
|
||||
metadata.language = language;
|
||||
metadata.version = version;
|
||||
|
||||
|
@ -269,14 +279,16 @@ function sidebarVersion(req_version) {
|
|||
}
|
||||
if (
|
||||
fs.existsSync(
|
||||
CWD + "/versioned_sidebars/version-" + versions[i] + "-sidebars.json"
|
||||
CWD + '/versioned_sidebars/version-' + versions[i] + '-sidebars.json'
|
||||
)
|
||||
) {
|
||||
return versions[i];
|
||||
}
|
||||
}
|
||||
throw new Error(
|
||||
`No sidebar file available to use for version ${req_version}. Verify that 'version-${req_version}-sidebars.json' exists.`
|
||||
`No sidebar file available to use for version ${
|
||||
req_version
|
||||
}. Verify that 'version-${req_version}-sidebars.json' exists.`
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -290,11 +302,11 @@ function diffLatestSidebar() {
|
|||
|
||||
const version = sidebarVersion(latest);
|
||||
const latestSidebar =
|
||||
CWD + "/versioned_sidebars/version-" + version + "-sidebars.json";
|
||||
CWD + '/versioned_sidebars/version-' + version + '-sidebars.json';
|
||||
if (!fs.existsSync(latestSidebar)) {
|
||||
return true;
|
||||
}
|
||||
const currentSidebar = CWD + "/sidebars.json";
|
||||
const currentSidebar = CWD + '/sidebars.json';
|
||||
// if no current sidebar file, return false so no sidebar file gets copied
|
||||
if (!fs.existsSync(currentSidebar)) {
|
||||
return false;
|
||||
|
@ -303,10 +315,10 @@ function diffLatestSidebar() {
|
|||
// compare for equality between latest version sidebar with version prefixes
|
||||
// stripped and current sidebar
|
||||
return (
|
||||
JSON.stringify(JSON.parse(fs.readFileSync(latestSidebar, "utf8"))).replace(
|
||||
new RegExp("version-" + version + "-", "g"),
|
||||
""
|
||||
) !== JSON.stringify(JSON.parse(fs.readFileSync(currentSidebar, "utf8")))
|
||||
JSON.stringify(JSON.parse(fs.readFileSync(latestSidebar, 'utf8'))).replace(
|
||||
new RegExp('version-' + version + '-', 'g'),
|
||||
''
|
||||
) !== JSON.stringify(JSON.parse(fs.readFileSync(currentSidebar, 'utf8')))
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -319,12 +331,12 @@ function sidebarData() {
|
|||
const sidebar = JSON.parse(
|
||||
fs
|
||||
.readFileSync(
|
||||
CWD + "/versioned_sidebars/version-" + version + "-sidebars.json",
|
||||
"utf8"
|
||||
CWD + '/versioned_sidebars/version-' + version + '-sidebars.json',
|
||||
'utf8'
|
||||
)
|
||||
.replace(
|
||||
new RegExp("version-" + version + "-", "g"),
|
||||
"version-" + versions[i] + "-"
|
||||
new RegExp('version-' + version + '-', 'g'),
|
||||
'version-' + versions[i] + '-'
|
||||
)
|
||||
);
|
||||
Object.assign(allSidebars, sidebar);
|
||||
|
@ -339,5 +351,5 @@ module.exports = {
|
|||
docData,
|
||||
sidebarVersion,
|
||||
diffLatestSidebar,
|
||||
sidebarData
|
||||
sidebarData,
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue