mirror of
https://github.com/facebook/docusaurus.git
synced 2025-04-29 02:08:36 +02:00
2 bug fixes (#98)
* Merge fix * Updating lock file. * Bug fix for rss feed truncation... * Fixes infinite recursive loop for #89 * Removed use of module cache invalidator from feed.js * Replaced 'latest' babel presets with 'env' * Ignore temp build folder * Adding back new truncation logic for RSS * Updating yarn lock
This commit is contained in:
parent
f26db92a46
commit
3b5db4bbf8
10 changed files with 507 additions and 433 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -6,6 +6,7 @@ website/translated_docs
|
||||||
website/build/
|
website/build/
|
||||||
website/yarn.lock
|
website/yarn.lock
|
||||||
website/node_modules
|
website/node_modules
|
||||||
|
lib/pages/
|
||||||
|
|
||||||
website/i18n/*
|
website/i18n/*
|
||||||
!website/i18n/en.json
|
!website/i18n/en.json
|
||||||
|
|
|
@ -24,10 +24,10 @@ const siteConfig = {
|
||||||
baseUrl: "/test-site/" /* base url for your project */,
|
baseUrl: "/test-site/" /* base url for your project */,
|
||||||
projectName: "test-site",
|
projectName: "test-site",
|
||||||
headerLinks: [
|
headerLinks: [
|
||||||
{doc: "doc1", label: "Docs"},
|
{ doc: "doc1", label: "Docs" },
|
||||||
{doc: "doc4", label: "API"},
|
{ doc: "doc4", label: "API" },
|
||||||
{page: "help", label: "Help"},
|
{ page: "help", label: "Help" },
|
||||||
{blog: true, label: "Blog"}
|
{ blog: true, label: "Blog" }
|
||||||
],
|
],
|
||||||
users,
|
users,
|
||||||
/* path to images for header/footer */
|
/* path to images for header/footer */
|
||||||
|
|
|
@ -10,10 +10,10 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
require("babel-register")({
|
require("babel-register")({
|
||||||
babelrc: false,
|
babelrc: false,
|
||||||
only: [__dirname, process.cwd() + "/core"],
|
only: [__dirname, process.cwd() + "/core"],
|
||||||
plugins: [require("./server/translate-plugin.js")],
|
plugins: [require("./server/translate-plugin.js")],
|
||||||
presets: ["react", "latest"]
|
presets: ["react", "env"]
|
||||||
});
|
});
|
||||||
|
|
||||||
// initial check that required files are present
|
// initial check that required files are present
|
||||||
|
@ -22,10 +22,10 @@ const fs = require("fs");
|
||||||
const CWD = process.cwd();
|
const CWD = process.cwd();
|
||||||
|
|
||||||
if (!fs.existsSync(CWD + "/siteConfig.js")) {
|
if (!fs.existsSync(CWD + "/siteConfig.js")) {
|
||||||
console.error(
|
console.error(
|
||||||
chalk.red("Error: No siteConfig.js file found in website folder!")
|
chalk.red("Error: No siteConfig.js file found in website folder!")
|
||||||
);
|
);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// generate all static html files
|
// generate all static html files
|
||||||
|
|
0
lib/generate-feed.js
Normal file → Executable file
0
lib/generate-feed.js
Normal file → Executable file
|
@ -26,48 +26,17 @@ const jestImage = siteConfig.url + siteConfig.headerIcon;
|
||||||
let readMetadata;
|
let readMetadata;
|
||||||
let Metadata;
|
let Metadata;
|
||||||
|
|
||||||
function reloadMetadata() {
|
readMetadata = require("./readMetadata.js");
|
||||||
removeFromCache("./readMetadata.js");
|
readMetadata.generateDocsMetadata();
|
||||||
readMetadata = require("./readMetadata.js");
|
Metadata = require("../core/metadata.js");
|
||||||
readMetadata.generateDocsMetadata();
|
|
||||||
removeFromCache("../core/metadata.js");
|
|
||||||
Metadata = require("../core/metadata.js");
|
|
||||||
}
|
|
||||||
|
|
||||||
/****************************************************************************/
|
/****************************************************************************/
|
||||||
|
|
||||||
// remove a module and child modules from require cache, so server does not have
|
|
||||||
// to be restarted
|
|
||||||
const removeFromCache = moduleName => {
|
|
||||||
let mod = require.resolve(moduleName);
|
|
||||||
if (mod && (mod = require.cache[mod])) {
|
|
||||||
(function traverse(mod) {
|
|
||||||
mod.children.forEach(child => {
|
|
||||||
traverse(child);
|
|
||||||
});
|
|
||||||
delete require.cache[mod.id];
|
|
||||||
})(mod);
|
|
||||||
}
|
|
||||||
|
|
||||||
Object.keys(module.constructor._pathCache).forEach(function(cacheKey) {
|
|
||||||
if (cacheKey.indexOf(moduleName) > 0) {
|
|
||||||
delete module.constructor._pathCache[cacheKey];
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
reloadMetadata();
|
|
||||||
|
|
||||||
module.exports = function(type) {
|
module.exports = function(type) {
|
||||||
console.log("feed.js triggered...");
|
console.log("feed.js triggered...");
|
||||||
|
|
||||||
type = type || "rss";
|
type = type || "rss";
|
||||||
|
|
||||||
removeFromCache(CWD + "/siteConfig.js");
|
|
||||||
if (fs.existsSync(__dirname + "/../core/MetadataBlog.js")) {
|
|
||||||
removeFromCache("../core/MetadataBlog.js");
|
|
||||||
fs.removeSync(__dirname + "/../core/MetadataBlog.js");
|
|
||||||
}
|
|
||||||
readMetadata.generateBlogMetadata();
|
readMetadata.generateBlogMetadata();
|
||||||
const MetadataBlog = require("../core/MetadataBlog.js");
|
const MetadataBlog = require("../core/MetadataBlog.js");
|
||||||
|
|
||||||
|
@ -87,11 +56,14 @@ module.exports = function(type) {
|
||||||
MetadataBlog.forEach(post => {
|
MetadataBlog.forEach(post => {
|
||||||
const url = blogRootURL + "/" + post.path;
|
const url = blogRootURL + "/" + post.path;
|
||||||
let content = "";
|
let content = "";
|
||||||
let contentArr = post.content.split("<!--truncate-->");
|
if (post.content.indexOf("<!--truncate-->") == -1) {
|
||||||
if (contentArr.length > 0) {
|
content = post.content.trim().substring(0, 250);
|
||||||
content = contentArr[0];
|
} else {
|
||||||
|
let contentArr = post.content.split("<!--truncate-->");
|
||||||
|
if (contentArr.length > 0) {
|
||||||
|
content = contentArr[0];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
content = content.trim().substring(0, 250);
|
|
||||||
|
|
||||||
feed.addItem({
|
feed.addItem({
|
||||||
title: post.title,
|
title: post.title,
|
||||||
|
|
|
@ -33,17 +33,19 @@ function execute(port) {
|
||||||
|
|
||||||
// remove a module and child modules from require cache, so server does not have
|
// remove a module and child modules from require cache, so server does not have
|
||||||
// to be restarted
|
// to be restarted
|
||||||
function removeFromCache(moduleName) {
|
function removeModuleAndChildrenFromCache(moduleName) {
|
||||||
let mod = require.resolve(moduleName);
|
let mod = require.resolve(moduleName);
|
||||||
if (mod && (mod = require.cache[mod])) {
|
if (mod && (mod = require.cache[mod])) {
|
||||||
(function traverse(mod) {
|
mod.children.forEach(child => {
|
||||||
mod.children.forEach(child => {
|
delete require.cache[child.id];
|
||||||
traverse(child);
|
removeModulePathFromCache(mod.id);
|
||||||
});
|
});
|
||||||
delete require.cache[mod.id];
|
delete require.cache[mod.id];
|
||||||
})(mod);
|
removeModulePathFromCache(mod.id);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function removeModulePathFromCache(moduleName) {
|
||||||
Object.keys(module.constructor._pathCache).forEach(function(cacheKey) {
|
Object.keys(module.constructor._pathCache).forEach(function(cacheKey) {
|
||||||
if (cacheKey.indexOf(moduleName) > 0) {
|
if (cacheKey.indexOf(moduleName) > 0) {
|
||||||
delete module.constructor._pathCache[cacheKey];
|
delete module.constructor._pathCache[cacheKey];
|
||||||
|
@ -57,10 +59,10 @@ function execute(port) {
|
||||||
let Metadata;
|
let Metadata;
|
||||||
|
|
||||||
function reloadMetadata() {
|
function reloadMetadata() {
|
||||||
removeFromCache("./readMetadata.js");
|
removeModuleAndChildrenFromCache("./readMetadata.js");
|
||||||
readMetadata = require("./readMetadata.js");
|
readMetadata = require("./readMetadata.js");
|
||||||
readMetadata.generateDocsMetadata();
|
readMetadata.generateDocsMetadata();
|
||||||
removeFromCache("../core/metadata.js");
|
removeModuleAndChildrenFromCache("../core/metadata.js");
|
||||||
Metadata = require("../core/metadata.js");
|
Metadata = require("../core/metadata.js");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,7 +107,7 @@ function execute(port) {
|
||||||
|
|
||||||
// handle all requests for document pages
|
// handle all requests for document pages
|
||||||
const app = express().get(/docs\/.*html$/, (req, res, next) => {
|
const app = express().get(/docs\/.*html$/, (req, res, next) => {
|
||||||
removeFromCache(CWD + "/siteConfig.js");
|
removeModuleAndChildrenFromCache(CWD + "/siteConfig.js");
|
||||||
siteConfig = require(CWD + "/siteConfig.js");
|
siteConfig = require(CWD + "/siteConfig.js");
|
||||||
|
|
||||||
let url = req.path.toString().replace(siteConfig.baseUrl, "");
|
let url = req.path.toString().replace(siteConfig.baseUrl, "");
|
||||||
|
@ -210,7 +212,7 @@ function execute(port) {
|
||||||
"](" + siteConfig.baseUrl + "docs/assets/"
|
"](" + siteConfig.baseUrl + "docs/assets/"
|
||||||
);
|
);
|
||||||
|
|
||||||
removeFromCache("../core/DocsLayout.js");
|
removeModuleAndChildrenFromCache("../core/DocsLayout.js");
|
||||||
const DocsLayout = require("../core/DocsLayout.js");
|
const DocsLayout = require("../core/DocsLayout.js");
|
||||||
const docComp = (
|
const docComp = (
|
||||||
<DocsLayout metadata={metadata} language={language} config={siteConfig}>
|
<DocsLayout metadata={metadata} language={language} config={siteConfig}>
|
||||||
|
@ -233,17 +235,17 @@ function execute(port) {
|
||||||
|
|
||||||
// handle all requests for blog pages and posts
|
// handle all requests for blog pages and posts
|
||||||
app.get(/blog\/.*html$/, (req, res) => {
|
app.get(/blog\/.*html$/, (req, res) => {
|
||||||
removeFromCache(CWD + "/siteConfig.js");
|
removeModuleAndChildrenFromCache(CWD + "/siteConfig.js");
|
||||||
siteConfig = require(CWD + "/siteConfig.js");
|
siteConfig = require(CWD + "/siteConfig.js");
|
||||||
if (fs.existsSync(__dirname + "/../core/MetadataBlog.js")) {
|
if (fs.existsSync(__dirname + "/../core/MetadataBlog.js")) {
|
||||||
removeFromCache("../core/MetadataBlog.js");
|
removeModuleAndChildrenFromCache("../core/MetadataBlog.js");
|
||||||
fs.removeSync(__dirname + "/../core/MetadataBlog.js");
|
fs.removeSync(__dirname + "/../core/MetadataBlog.js");
|
||||||
}
|
}
|
||||||
readMetadata.generateBlogMetadata();
|
readMetadata.generateBlogMetadata();
|
||||||
const MetadataBlog = require("../core/MetadataBlog.js");
|
const MetadataBlog = require("../core/MetadataBlog.js");
|
||||||
|
|
||||||
// generate all of the blog pages
|
// generate all of the blog pages
|
||||||
removeFromCache("../core/BlogPageLayout.js");
|
removeModuleAndChildrenFromCache("../core/BlogPageLayout.js");
|
||||||
const BlogPageLayout = require("../core/BlogPageLayout.js");
|
const BlogPageLayout = require("../core/BlogPageLayout.js");
|
||||||
const blogPages = {};
|
const blogPages = {};
|
||||||
// make blog pages with 10 posts per page
|
// make blog pages with 10 posts per page
|
||||||
|
@ -254,7 +256,7 @@ function execute(port) {
|
||||||
page++
|
page++
|
||||||
) {
|
) {
|
||||||
let language = "en";
|
let language = "en";
|
||||||
const metadata = {page: page, perPage: perPage};
|
const metadata = { page: page, perPage: perPage };
|
||||||
const blogPageComp = (
|
const blogPageComp = (
|
||||||
<BlogPageLayout
|
<BlogPageLayout
|
||||||
metadata={metadata}
|
metadata={metadata}
|
||||||
|
@ -288,7 +290,7 @@ function execute(port) {
|
||||||
file = CWD + "/blog/" + file;
|
file = CWD + "/blog/" + file;
|
||||||
|
|
||||||
const result = readMetadata.extractMetadata(
|
const result = readMetadata.extractMetadata(
|
||||||
fs.readFileSync(file, {encoding: "utf8"})
|
fs.readFileSync(file, { encoding: "utf8" })
|
||||||
);
|
);
|
||||||
let rawContent = result.rawContent;
|
let rawContent = result.rawContent;
|
||||||
rawContent = rawContent.replace(
|
rawContent = rawContent.replace(
|
||||||
|
@ -296,13 +298,13 @@ function execute(port) {
|
||||||
"](" + siteConfig.baseUrl + "blog/assets/"
|
"](" + siteConfig.baseUrl + "blog/assets/"
|
||||||
);
|
);
|
||||||
const metadata = Object.assign(
|
const metadata = Object.assign(
|
||||||
{path: req.path.toString().split("blog/")[1], content: rawContent},
|
{ path: req.path.toString().split("blog/")[1], content: rawContent },
|
||||||
result.metadata
|
result.metadata
|
||||||
);
|
);
|
||||||
metadata.id = metadata.title;
|
metadata.id = metadata.title;
|
||||||
|
|
||||||
let language = "en";
|
let language = "en";
|
||||||
removeFromCache("../core/BlogPostLayout.js");
|
removeModuleAndChildrenFromCache("../core/BlogPostLayout.js");
|
||||||
const BlogPostLayout = require("../core/BlogPostLayout.js");
|
const BlogPostLayout = require("../core/BlogPostLayout.js");
|
||||||
|
|
||||||
const blogPostComp = (
|
const blogPostComp = (
|
||||||
|
@ -320,7 +322,7 @@ function execute(port) {
|
||||||
|
|
||||||
// handle all other main pages
|
// handle all other main pages
|
||||||
app.get("*.html", (req, res, next) => {
|
app.get("*.html", (req, res, next) => {
|
||||||
removeFromCache(CWD + "/siteConfig.js");
|
removeModuleAndChildrenFromCache(CWD + "/siteConfig.js");
|
||||||
siteConfig = require(CWD + "/siteConfig.js");
|
siteConfig = require(CWD + "/siteConfig.js");
|
||||||
|
|
||||||
// look for user provided html file first
|
// look for user provided html file first
|
||||||
|
@ -335,7 +337,7 @@ function execute(port) {
|
||||||
))
|
))
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
res.send(fs.readFileSync(htmlFile, {encoding: "utf8"}));
|
res.send(fs.readFileSync(htmlFile, { encoding: "utf8" }));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -385,9 +387,9 @@ function execute(port) {
|
||||||
fs.copySync(userFile, tempFile);
|
fs.copySync(userFile, tempFile);
|
||||||
|
|
||||||
// render into a string
|
// render into a string
|
||||||
removeFromCache(tempFile);
|
removeModuleAndChildrenFromCache(tempFile);
|
||||||
const ReactComp = require(tempFile);
|
const ReactComp = require(tempFile);
|
||||||
removeFromCache("../core/Site.js");
|
removeModuleAndChildrenFromCache("../core/Site.js");
|
||||||
const Site = require("../core/Site.js");
|
const Site = require("../core/Site.js");
|
||||||
translate.setLanguage(language);
|
translate.setLanguage(language);
|
||||||
const str = renderToStaticMarkup(
|
const str = renderToStaticMarkup(
|
||||||
|
@ -411,7 +413,7 @@ function execute(port) {
|
||||||
__dirname +
|
__dirname +
|
||||||
"/../static/" +
|
"/../static/" +
|
||||||
req.path.toString().replace(siteConfig.baseUrl, "/");
|
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");
|
let files = glob.sync(CWD + "/static/**/*.css");
|
||||||
|
|
||||||
|
@ -420,7 +422,7 @@ function execute(port) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
cssContent =
|
cssContent =
|
||||||
cssContent + "\n" + fs.readFileSync(file, {encoding: "utf8"});
|
cssContent + "\n" + fs.readFileSync(file, { encoding: "utf8" });
|
||||||
});
|
});
|
||||||
|
|
||||||
if (
|
if (
|
||||||
|
|
|
@ -10,10 +10,10 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
require("babel-register")({
|
require("babel-register")({
|
||||||
babelrc: false,
|
babelrc: false,
|
||||||
only: [__dirname, process.cwd() + "/core"],
|
only: [__dirname, process.cwd() + "/core"],
|
||||||
plugins: [require("./server/translate-plugin.js")],
|
plugins: [require("./server/translate-plugin.js")],
|
||||||
presets: ["react", "latest"]
|
presets: ["react", "env"]
|
||||||
});
|
});
|
||||||
|
|
||||||
// initial check that required files are present
|
// initial check that required files are present
|
||||||
|
@ -22,10 +22,10 @@ const fs = require("fs");
|
||||||
const CWD = process.cwd();
|
const CWD = process.cwd();
|
||||||
|
|
||||||
if (!fs.existsSync(CWD + "/siteConfig.js")) {
|
if (!fs.existsSync(CWD + "/siteConfig.js")) {
|
||||||
console.error(
|
console.error(
|
||||||
chalk.red("Error: No siteConfig.js file found in website folder!")
|
chalk.red("Error: No siteConfig.js file found in website folder!")
|
||||||
);
|
);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
const program = require("commander");
|
const program = require("commander");
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
{
|
{
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"babel-preset-latest": "^6.24.1",
|
"babel-preset-env": "^1.6.0",
|
||||||
"babel-preset-react": "^6.24.1",
|
|
||||||
"babel-register": "^6.24.1",
|
"babel-register": "^6.24.1",
|
||||||
"babel-traverse": "^6.25.0",
|
"babel-traverse": "^6.25.0",
|
||||||
"babylon": "^6.17.4",
|
"babylon": "^6.17.4",
|
||||||
"chalk": "^2.1.0",
|
"chalk": "^2.1.0",
|
||||||
"classnames": "^2.2.5",
|
"classnames": "^2.2.5",
|
||||||
"commander": "^2.11.0",
|
"commander": "^2.11.0",
|
||||||
|
"crowdin-cli": "^0.3.0",
|
||||||
"diff": "^3.3.0",
|
"diff": "^3.3.0",
|
||||||
"express": "^4.15.3",
|
"express": "^4.15.3",
|
||||||
"feed": "^1.1.0",
|
"feed": "^1.1.0",
|
||||||
|
@ -26,9 +26,6 @@
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/facebookexperimental/Docusaurus.git"
|
"url": "https://github.com/facebookexperimental/Docusaurus.git"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
|
||||||
"jest": "^21.2.0"
|
|
||||||
},
|
|
||||||
"bin": {
|
"bin": {
|
||||||
"docusaurus-start": "./lib/start-server.js",
|
"docusaurus-start": "./lib/start-server.js",
|
||||||
"docusaurus-build": "./lib/build-files.js",
|
"docusaurus-build": "./lib/build-files.js",
|
||||||
|
|
|
@ -40,10 +40,10 @@ const siteConfig = {
|
||||||
editUrl:
|
editUrl:
|
||||||
"https://github.com/facebookexperimental/docusaurus/edit/master/docs/",
|
"https://github.com/facebookexperimental/docusaurus/edit/master/docs/",
|
||||||
headerLinks: [
|
headerLinks: [
|
||||||
{doc: "installation", label: "Docs"},
|
{ doc: "installation", label: "Docs" },
|
||||||
{page: "help", label: "Help"},
|
{ page: "help", label: "Help" },
|
||||||
{blog: true, label: "Blog"},
|
{ blog: true, label: "Blog" },
|
||||||
{languages: false},
|
{ languages: false },
|
||||||
{
|
{
|
||||||
href: "https://github.com/facebookexperimental/docusaurus",
|
href: "https://github.com/facebookexperimental/docusaurus",
|
||||||
label: "GitHub"
|
label: "GitHub"
|
||||||
|
|
Loading…
Add table
Reference in a new issue