mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-24 13:38:02 +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
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue