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