mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-09 23:27:28 +02:00
ESLintify Part 3 (#846)
* ESLintify Part 3 * ESLintify Part 3 * ESLintify Part 3
This commit is contained in:
parent
5ac2cee658
commit
a7a214fb3a
54 changed files with 435 additions and 497 deletions
|
@ -49,7 +49,7 @@ function execute(port, options) {
|
|||
|
||||
function removeModulePathFromCache(moduleName) {
|
||||
/* eslint-disable no-underscore-dangle */
|
||||
Object.keys(module.constructor._pathCache).forEach(function(cacheKey) {
|
||||
Object.keys(module.constructor._pathCache).forEach(cacheKey => {
|
||||
if (cacheKey.indexOf(moduleName) > 0) {
|
||||
delete module.constructor._pathCache[cacheKey];
|
||||
}
|
||||
|
@ -149,7 +149,7 @@ function execute(port, options) {
|
|||
// Start LiveReload server.
|
||||
process.env.NODE_ENV = 'development';
|
||||
const server = tinylr();
|
||||
server.listen(constants.LIVE_RELOAD_PORT, function() {
|
||||
server.listen(constants.LIVE_RELOAD_PORT, () => {
|
||||
console.log(
|
||||
'LiveReload server started on port %d',
|
||||
constants.LIVE_RELOAD_PORT
|
||||
|
@ -159,13 +159,13 @@ function execute(port, options) {
|
|||
// gaze watches some specified dirs and triggers a callback when they change.
|
||||
gaze(
|
||||
[
|
||||
'../' + readMetadata.getDocsPath() + '/**/*', // docs
|
||||
`../${readMetadata.getDocsPath()}/**/*`, // docs
|
||||
'**/*', // website
|
||||
'!node_modules/**/*', // node_modules
|
||||
],
|
||||
function() {
|
||||
// Listen for all kinds of file changes - modified/added/deleted.
|
||||
this.on('all', function() {
|
||||
this.on('all', () => {
|
||||
// Notify LiveReload clients that there's a change.
|
||||
// Typically, LiveReload will only refresh the changed paths,
|
||||
// so we use / here to force a full-page reload.
|
||||
|
@ -252,29 +252,29 @@ function execute(port, options) {
|
|||
Object.keys(mdToHtml).forEach(key => {
|
||||
let link = mdToHtml[key];
|
||||
link = utils.getPath(link, siteConfig.cleanUrl);
|
||||
link = link.replace('/en/', '/' + language + '/');
|
||||
link = link.replace('/en/', `/${language}/`);
|
||||
link = link.replace(
|
||||
'/VERSION/',
|
||||
metadata.version && metadata.version !== defaultVersion
|
||||
? '/' + 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');
|
||||
|
@ -357,7 +357,7 @@ function execute(port, options) {
|
|||
);
|
||||
const str = renderToStaticMarkupWithDoctype(blogPageComp);
|
||||
|
||||
const pagePath = (page > 0 ? 'page' + (page + 1) : '') + '/index.html';
|
||||
const pagePath = `${page > 0 ? `page${page + 1}` : ''}/index.html`;
|
||||
blogPages[pagePath] = str;
|
||||
}
|
||||
|
||||
|
@ -369,9 +369,9 @@ function execute(port, options) {
|
|||
res.send(blogPages[parts[1]]);
|
||||
} else if (parts[1].match(/page([0-9]+)/)) {
|
||||
if (parts[1].endsWith('/')) {
|
||||
res.send(blogPages[parts[1] + 'index.html']);
|
||||
res.send(blogPages[`${parts[1]}index.html`]);
|
||||
} else {
|
||||
res.send(blogPages[parts[1] + '/index.html']);
|
||||
res.send(blogPages[`${parts[1]}/index.html`]);
|
||||
}
|
||||
} else {
|
||||
// send corresponding blog post. Ex: request to "blog/test/index.html" or
|
||||
|
@ -396,7 +396,7 @@ function execute(port, options) {
|
|||
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},
|
||||
|
@ -478,7 +478,7 @@ function execute(port, options) {
|
|||
}
|
||||
let englishFile = join(CWD, 'pages', file);
|
||||
if (language && language !== 'en') {
|
||||
englishFile = englishFile.replace(sep + language + sep, sep + 'en' + sep);
|
||||
englishFile = englishFile.replace(sep + language + sep, `${sep}en${sep}`);
|
||||
}
|
||||
|
||||
// check for: a file for the page, an english file for page with unspecified language, or an
|
||||
|
@ -488,17 +488,17 @@ function execute(port, options) {
|
|||
fs.existsSync(
|
||||
(userFile = userFile.replace(
|
||||
path.basename(userFile),
|
||||
'en' + sep + path.basename(userFile)
|
||||
`en${sep}${path.basename(userFile)}`
|
||||
))
|
||||
) ||
|
||||
fs.existsSync((userFile = englishFile))
|
||||
) {
|
||||
// copy into docusaurus so require paths work
|
||||
const userFileParts = userFile.split('pages' + sep);
|
||||
const userFileParts = userFile.split(`pages${sep}`);
|
||||
let tempFile = join(__dirname, '..', 'pages', userFileParts[1]);
|
||||
tempFile = tempFile.replace(
|
||||
path.basename(file),
|
||||
'temp' + path.basename(file)
|
||||
`temp${path.basename(file)}`
|
||||
);
|
||||
mkdirp.sync(path.dirname(tempFile));
|
||||
fs.copySync(userFile, tempFile);
|
||||
|
@ -544,8 +544,9 @@ function execute(port, options) {
|
|||
if (isSeparateCss(file)) {
|
||||
return;
|
||||
}
|
||||
cssContent =
|
||||
cssContent + '\n' + fs.readFileSync(file, {encoding: 'utf8'});
|
||||
cssContent = `${cssContent}\n${fs.readFileSync(file, {
|
||||
encoding: 'utf8',
|
||||
})}`;
|
||||
});
|
||||
|
||||
if (
|
||||
|
@ -562,16 +563,16 @@ function execute(port, options) {
|
|||
|
||||
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);
|
||||
});
|
||||
|
||||
if (siteConfig.fonts) {
|
||||
Object.keys(siteConfig.fonts).forEach(key => {
|
||||
const fontString = siteConfig.fonts[key]
|
||||
.map(font => '"' + font + '"')
|
||||
.map(font => `"${font}"`)
|
||||
.join(', ');
|
||||
cssContent = cssContent.replace(
|
||||
new RegExp('\\$' + key, 'g'),
|
||||
new RegExp(`\\$${key}`, 'g'),
|
||||
fontString
|
||||
);
|
||||
});
|
||||
|
@ -597,11 +598,11 @@ function execute(port, options) {
|
|||
// for example, request to "blog" returns "blog/index.html" or "blog.html"
|
||||
app.get(noExtRouting(), (req, res, next) => {
|
||||
const slash = req.path.toString().endsWith('/') ? '' : '/';
|
||||
const requestUrl = 'http://localhost:' + port + req.path;
|
||||
requestFile(requestUrl + slash + 'index.html', res, () => {
|
||||
const requestUrl = `http://localhost:${port}${req.path}`;
|
||||
requestFile(`${requestUrl + slash}index.html`, res, () => {
|
||||
requestFile(
|
||||
slash === '/'
|
||||
? requestUrl + '.html'
|
||||
? `${requestUrl}.html`
|
||||
: requestUrl.replace(/\/$/, '.html'),
|
||||
res,
|
||||
next
|
||||
|
@ -616,7 +617,7 @@ function execute(port, options) {
|
|||
next();
|
||||
return;
|
||||
}
|
||||
requestFile('http://localhost:' + port + req.path + '.html', res, next);
|
||||
requestFile(`http://localhost:${port}${req.path}.html`, res, next);
|
||||
});
|
||||
|
||||
if (options.watch) startLiveReload();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue