mirror of
https://github.com/facebook/docusaurus.git
synced 2025-04-30 18:58:36 +02:00
chore(v2): generic styling improvements
This commit is contained in:
parent
c46a894a01
commit
b33de00a32
16 changed files with 109 additions and 109 deletions
|
@ -25,10 +25,10 @@ async function loadBlog({blogDir, env, siteConfig}) {
|
|||
|
||||
const {baseUrl} = siteConfig;
|
||||
|
||||
/* Prepare metadata container */
|
||||
// Prepare metadata container.
|
||||
const blogMetadatas = [];
|
||||
|
||||
/* the language for each blog page */
|
||||
// Language for each blog page.
|
||||
const defaultLangTag = idx(env, ['translation', 'defaultLanguage', 'tag']);
|
||||
|
||||
await Promise.all(
|
||||
|
@ -58,13 +58,13 @@ async function loadBlog({blogDir, env, siteConfig}) {
|
|||
);
|
||||
blogMetadatas.sort((a, b) => a.date - b.date);
|
||||
|
||||
// blogpage handling. Example: `/blog`, `/blog/page1`, `/blog/page2`
|
||||
// Blog page handling. Example: `/blog`, `/blog/page1`, `/blog/page2`
|
||||
const perPage = 10;
|
||||
const numOfBlog = blogMetadatas.length;
|
||||
const numberOfPage = Math.ceil(numOfBlog / perPage);
|
||||
const basePageUrl = path.join(baseUrl, 'blog');
|
||||
|
||||
/* eslint-disable */
|
||||
// eslint-disable-next-line
|
||||
for (let page = 0; page < numberOfPage; page++) {
|
||||
blogMetadatas.push({
|
||||
permalink: normalizeUrl([
|
||||
|
|
|
@ -19,7 +19,7 @@ async function loadDocs({siteDir, docsDir, env, siteConfig}) {
|
|||
// @tested - build the docs ordering such as next, previous, category and sidebar
|
||||
const order = createOrder(docsSidebars);
|
||||
|
||||
/* Settle versions & translations from environment */
|
||||
// Settle versions & translations from environment.
|
||||
const translationEnabled = idx(env, ['translation', 'enabled']);
|
||||
const enabledLanguages =
|
||||
translationEnabled && idx(env, ['translation', 'enabledLanguages']);
|
||||
|
@ -30,19 +30,17 @@ async function loadDocs({siteDir, docsDir, env, siteConfig}) {
|
|||
const versions =
|
||||
(versioningEnabled && idx(env, ['versioning', 'versions'])) || [];
|
||||
|
||||
/* Prepare metadata container */
|
||||
// Prepare metadata container.
|
||||
const docsMetadatas = {};
|
||||
|
||||
/* metadata for default docs files */
|
||||
// Metadata for default docs files.
|
||||
const docsFiles = await globby(['**/*.md'], {
|
||||
cwd: docsDir,
|
||||
});
|
||||
await Promise.all(
|
||||
docsFiles.map(async source => {
|
||||
/*
|
||||
Do not allow reserved version/ translated folder name in 'docs'
|
||||
e.g: 'docs/version-1.0.0/' should not be allowed as it can cause unwanted bug
|
||||
*/
|
||||
// Do not allow reserved version/ translated folder name in 'docs'
|
||||
// e.g: 'docs/version-1.0.0/' should not be allowed as it can cause unwanted bug
|
||||
const subFolder = getSubFolder(path.resolve(docsDir, source), docsDir);
|
||||
const versionsFolders = versions.map(version => `version-${version}`);
|
||||
if ([...enabledLangTags, ...versionsFolders].includes(subFolder)) {
|
||||
|
@ -60,7 +58,7 @@ async function loadDocs({siteDir, docsDir, env, siteConfig}) {
|
|||
}),
|
||||
);
|
||||
|
||||
/* metadata for non-default-language docs */
|
||||
// Metadata for non-default-language docs.
|
||||
if (translationEnabled) {
|
||||
const translatedDir = path.join(siteDir, 'translated_docs');
|
||||
const translatedFiles = await globby(['**/*.md'], {
|
||||
|
@ -93,7 +91,7 @@ async function loadDocs({siteDir, docsDir, env, siteConfig}) {
|
|||
);
|
||||
}
|
||||
|
||||
/* metadata for versioned docs */
|
||||
// Metadata for versioned docs.
|
||||
if (versioningEnabled) {
|
||||
const versionedDir = path.join(siteDir, 'versioned_docs');
|
||||
const versionedFiles = await globby(['**/*.md'], {
|
||||
|
@ -113,7 +111,7 @@ async function loadDocs({siteDir, docsDir, env, siteConfig}) {
|
|||
);
|
||||
}
|
||||
|
||||
/* Get the titles of the previous and next ids so that we can use them */
|
||||
// Get the titles of the previous and next ids so that we can use them.
|
||||
Object.keys(docsMetadatas).forEach(currentID => {
|
||||
const previousID = idx(docsMetadatas, [currentID, 'previous']);
|
||||
if (previousID) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/**
|
||||
/*
|
||||
* Copyright (c) 2017-present, Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
|
@ -11,6 +11,7 @@ const {getSubFolder, idx, parse, normalizeUrl} = require('../utils');
|
|||
|
||||
function getLanguage(filepath, refDir, env) {
|
||||
const translationEnabled = idx(env, ['translation', 'enabled']);
|
||||
|
||||
if (translationEnabled) {
|
||||
const detectedLangTag = getSubFolder(filepath, refDir);
|
||||
const enabledLanguages = idx(env, ['translation', 'enabledLanguages']);
|
||||
|
@ -19,18 +20,22 @@ function getLanguage(filepath, refDir, env) {
|
|||
if (langTags.includes(detectedLangTag)) {
|
||||
return detectedLangTag;
|
||||
}
|
||||
|
||||
const defaultLanguage = idx(env, ['translation', 'defaultLanguage']);
|
||||
if (defaultLanguage && defaultLanguage.tag) {
|
||||
return defaultLanguage.tag;
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
function getVersion(filepath, refDir, env) {
|
||||
const versioningEnabled = idx(env, ['versioning', 'enabled']);
|
||||
|
||||
if (versioningEnabled) {
|
||||
const subFolder = getSubFolder(filepath, refDir);
|
||||
|
||||
if (subFolder) {
|
||||
const detectedVersion = subFolder.replace(/^version-/, '');
|
||||
const versions = idx(env, ['versioning', 'versions']) || [];
|
||||
|
@ -38,9 +43,11 @@ function getVersion(filepath, refDir, env) {
|
|||
return detectedVersion;
|
||||
}
|
||||
}
|
||||
|
||||
return 'next';
|
||||
}
|
||||
return undefined;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
module.exports = async function processMetadata(
|
||||
|
@ -54,7 +61,7 @@ module.exports = async function processMetadata(
|
|||
const fileString = await fs.readFile(filepath, 'utf-8');
|
||||
const {metadata} = parse(fileString);
|
||||
|
||||
/* default id is the file name */
|
||||
// Default id is the file name.
|
||||
if (!metadata.id) {
|
||||
metadata.id = path.basename(source, path.extname(source));
|
||||
}
|
||||
|
@ -62,17 +69,17 @@ module.exports = async function processMetadata(
|
|||
throw new Error('Document id cannot include "/".');
|
||||
}
|
||||
|
||||
/* default title is the id */
|
||||
// Default title is the id.
|
||||
if (!metadata.title) {
|
||||
metadata.title = metadata.id;
|
||||
}
|
||||
|
||||
/* language */
|
||||
// Language.
|
||||
const language = getLanguage(filepath, refDir, env);
|
||||
metadata.language = language;
|
||||
const langPart = (language && `${language}/`) || '';
|
||||
|
||||
/* version */
|
||||
// Version.
|
||||
const defaultLangTag = idx(env, ['translation', 'defaultLanguage', 'tag']);
|
||||
let versionRefDir = refDir;
|
||||
if (language && language !== defaultLangTag) {
|
||||
|
@ -84,10 +91,8 @@ module.exports = async function processMetadata(
|
|||
const versionPart =
|
||||
(version && version !== latestVersion && `${version}/`) || '';
|
||||
|
||||
/*
|
||||
Convert temporarily metadata.id to the form of dirname/id without version/lang prefix
|
||||
ex: file `versioned_docs/version-1.0.0/en/foo/bar.md` with id `version-1.0.0-bar` => `foo/bar`
|
||||
*/
|
||||
// Convert temporarily metadata.id to the form of dirname/id without version/lang prefix.
|
||||
// e.g.: file `versioned_docs/version-1.0.0/en/foo/bar.md` with id `version-1.0.0-bar` => `foo/bar`
|
||||
if (language) {
|
||||
metadata.id = metadata.id.replace(new RegExp(`^${language}-`), '');
|
||||
}
|
||||
|
@ -112,19 +117,15 @@ module.exports = async function processMetadata(
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
The docs absolute file source
|
||||
e.g: `/end/docs/hello.md` or `/end/website/versioned_docs/version-1.0.0/hello.md`
|
||||
*/
|
||||
// The docs absolute file source.
|
||||
// e.g: `/end/docs/hello.md` or `/end/website/versioned_docs/version-1.0.0/hello.md`
|
||||
metadata.source = path.join(refDir, source);
|
||||
|
||||
/* Build the permalink */
|
||||
// Build the permalink.
|
||||
const {baseUrl, docsUrl} = siteConfig;
|
||||
|
||||
/*
|
||||
if user has own custom permalink defined in frontmatter
|
||||
e.g: :baseUrl:docsUrl/:langPart/:versionPart/endiliey/:id
|
||||
*/
|
||||
// If user has own custom permalink defined in frontmatter
|
||||
// e.g: :baseUrl:docsUrl/:langPart/:versionPart/endiliey/:id
|
||||
if (metadata.permalink) {
|
||||
metadata.permalink = path.resolve(
|
||||
metadata.permalink
|
||||
|
@ -144,20 +145,20 @@ module.exports = async function processMetadata(
|
|||
]);
|
||||
}
|
||||
|
||||
/* if version */
|
||||
// If version.
|
||||
if (version && version !== 'next') {
|
||||
metadata.id = `version-${version}-${metadata.id}`;
|
||||
}
|
||||
|
||||
/* save localized id before adding language on it */
|
||||
// Save localized id before adding language on it.
|
||||
metadata.localized_id = metadata.id;
|
||||
|
||||
/* if language */
|
||||
// If language.
|
||||
if (language) {
|
||||
metadata.id = `${language}-${metadata.id}`;
|
||||
}
|
||||
|
||||
/* Determine order */
|
||||
// Determine order.
|
||||
const id = metadata.localized_id;
|
||||
if (order[id]) {
|
||||
metadata.sidebar = order[id].sidebar;
|
||||
|
@ -172,5 +173,6 @@ module.exports = async function processMetadata(
|
|||
metadata.previous = (language ? `${language}-` : '') + order[id].previous;
|
||||
}
|
||||
}
|
||||
|
||||
return metadata;
|
||||
};
|
||||
|
|
|
@ -5,8 +5,7 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
// build the docs meta such as next, previous, category and sidebar
|
||||
|
||||
// Build the docs meta such as next, previous, category and sidebar.
|
||||
module.exports = function createOrder(allSidebars = {}) {
|
||||
const order = {};
|
||||
|
||||
|
@ -28,7 +27,7 @@ module.exports = function createOrder(allSidebars = {}) {
|
|||
break;
|
||||
case 'ref':
|
||||
case 'link':
|
||||
// refs and links should not be shown in navigation
|
||||
// Refs and links should not be shown in navigation.
|
||||
break;
|
||||
case 'doc':
|
||||
ids.push(item.id);
|
||||
|
|
|
@ -11,7 +11,7 @@ const {idx} = require('./utils');
|
|||
const loadConfig = require('./config');
|
||||
|
||||
module.exports = function loadEnv({siteDir, siteConfig}) {
|
||||
// Translation
|
||||
// Translation.
|
||||
const translation = {
|
||||
enabled: false,
|
||||
enabledLanguages: [],
|
||||
|
@ -23,31 +23,32 @@ module.exports = function loadEnv({siteDir, siteConfig}) {
|
|||
if (fs.existsSync(languagesFile)) {
|
||||
const languages = require(languagesFile); // eslint-disable-line
|
||||
|
||||
/* Enabled languages */
|
||||
// Enabled languages.
|
||||
const enabledLanguages = languages.filter(lang => lang.enabled);
|
||||
if (!enabledLanguages || enabledLanguages.length === 0) {
|
||||
throw new Error(`Please at least enable one language in 'languages.js'`);
|
||||
}
|
||||
translation.enabledLanguages = enabledLanguages;
|
||||
|
||||
/* Default Language */
|
||||
// Default language.
|
||||
const {defaultLanguage: defaultLanguageTag} = siteConfig;
|
||||
const defaultLanguage = enabledLanguages.find(
|
||||
lang => lang.tag === defaultLanguageTag,
|
||||
);
|
||||
|
||||
if (!defaultLanguage) {
|
||||
throw new Error(
|
||||
`Please set a default language in ${
|
||||
loadConfig.configFileName
|
||||
} which is enabled in 'languages.js'`,
|
||||
} which is enabled in languages.js`,
|
||||
);
|
||||
}
|
||||
translation.defaultLanguage = defaultLanguage;
|
||||
|
||||
translation.defaultLanguage = defaultLanguage;
|
||||
translation.enabled = true;
|
||||
}
|
||||
|
||||
// Versioning
|
||||
// Versioning.
|
||||
const versioning = {
|
||||
enabled: false,
|
||||
latestVersion: null,
|
||||
|
|
|
@ -16,18 +16,18 @@ const {generate} = require('./utils');
|
|||
const genRoutesConfig = require('./routes');
|
||||
|
||||
module.exports = async function load(siteDir) {
|
||||
// @tested - siteConfig
|
||||
// Site Config - @tested
|
||||
const siteConfig = loadConfig.loadConfig(siteDir);
|
||||
await generate(
|
||||
loadConfig.configFileName,
|
||||
`export default ${JSON.stringify(siteConfig, null, 2)};`,
|
||||
);
|
||||
|
||||
// @tested - env
|
||||
// Env - @tested
|
||||
const env = loadEnv({siteDir, siteConfig});
|
||||
await generate('env.js', `export default ${JSON.stringify(env, null, 2)};`);
|
||||
|
||||
// docs
|
||||
// Docs
|
||||
const docsDir = path.resolve(siteDir, '..', siteConfig.customDocsPath);
|
||||
const {docsMetadatas, docsSidebars} = await loadDocs({
|
||||
siteDir,
|
||||
|
@ -44,7 +44,7 @@ module.exports = async function load(siteDir) {
|
|||
`export default ${JSON.stringify(docsSidebars, null, 2)};`,
|
||||
);
|
||||
|
||||
/* Create source to metadata mapping */
|
||||
// Create source to metadata mapping.
|
||||
const sourceToMetadata = {};
|
||||
Object.values(docsMetadatas).forEach(
|
||||
({source, version, permalink, language}) => {
|
||||
|
@ -56,7 +56,7 @@ module.exports = async function load(siteDir) {
|
|||
},
|
||||
);
|
||||
|
||||
// pages
|
||||
// Pages.
|
||||
const pagesDir = path.resolve(siteDir, 'pages');
|
||||
const pagesMetadatas = await loadPages({pagesDir, env, siteConfig});
|
||||
await generate(
|
||||
|
@ -64,7 +64,7 @@ module.exports = async function load(siteDir) {
|
|||
`export default ${JSON.stringify(pagesMetadatas, null, 2)};`,
|
||||
);
|
||||
|
||||
// blog
|
||||
// Blog.
|
||||
const blogDir = path.resolve(siteDir, 'blog');
|
||||
const blogMetadatas = await loadBlog({blogDir, env, siteConfig});
|
||||
await generate(
|
||||
|
@ -72,10 +72,10 @@ module.exports = async function load(siteDir) {
|
|||
`export default ${JSON.stringify(blogMetadatas, null, 2)};`,
|
||||
);
|
||||
|
||||
// resolve outDir
|
||||
// Resolve outDir.
|
||||
const outDir = path.resolve(siteDir, 'build');
|
||||
|
||||
// resolve the theme
|
||||
// Resolve theme.
|
||||
const themePath = loadTheme(siteDir);
|
||||
|
||||
const {baseUrl} = siteConfig;
|
||||
|
@ -101,7 +101,7 @@ module.exports = async function load(siteDir) {
|
|||
translatedDir,
|
||||
};
|
||||
|
||||
// Generate React Router Config
|
||||
// Generate React Router Config.
|
||||
const routesConfig = await genRoutesConfig(props);
|
||||
await generate('routes.js', routesConfig);
|
||||
|
||||
|
|
|
@ -16,10 +16,10 @@ async function loadPages({pagesDir, env, siteConfig}) {
|
|||
|
||||
const {baseUrl} = siteConfig;
|
||||
|
||||
/* Prepare metadata container */
|
||||
// Prepare metadata container.
|
||||
const pagesMetadatas = [];
|
||||
|
||||
/* Translation */
|
||||
// Translation.
|
||||
const translationEnabled = idx(env, ['translation', 'enabled']);
|
||||
const enabledLanguages =
|
||||
translationEnabled && idx(env, ['translation', 'enabledLanguages']);
|
||||
|
@ -33,7 +33,7 @@ async function loadPages({pagesDir, env, siteConfig}) {
|
|||
const pathName = encodePath(fileToPath(relativeSource));
|
||||
if (translationEnabled && enabledLangTags.length > 0) {
|
||||
enabledLangTags.forEach(langTag => {
|
||||
/* default lang should also be available. E.g: /en/users and /users is the same */
|
||||
// Default lang should also be available. E.g: /en/users and /users is the same.
|
||||
if (langTag === defaultLangTag) {
|
||||
pagesMetadatas.push({
|
||||
permalink: pathName.replace(/^\//, baseUrl),
|
||||
|
@ -49,9 +49,8 @@ async function loadPages({pagesDir, env, siteConfig}) {
|
|||
};
|
||||
pagesMetadatas.push(metadata);
|
||||
});
|
||||
|
||||
// for defaultLanguage
|
||||
} else {
|
||||
// Default Language.
|
||||
const metadata = {
|
||||
permalink: pathName.replace(/^\//, baseUrl),
|
||||
source,
|
||||
|
|
|
@ -24,6 +24,7 @@ module.exports = function loadConfig(siteDir) {
|
|||
'Markdown',
|
||||
'Search',
|
||||
];
|
||||
|
||||
themeComponents.forEach(component => {
|
||||
if (!require.resolve(path.join(themePath, component))) {
|
||||
throw new Error(
|
||||
|
|
|
@ -17,7 +17,7 @@ module.exports = function createClientConfig(props) {
|
|||
const config = createBaseConfig(props);
|
||||
config.entry('main').add(path.resolve(__dirname, '../core/clientEntry.js'));
|
||||
|
||||
// remove/clean build folders before building bundles
|
||||
// Remove/clean build folders before building bundles.
|
||||
const {outDir} = props;
|
||||
config
|
||||
.plugin('clean')
|
||||
|
@ -33,7 +33,7 @@ module.exports = function createClientConfig(props) {
|
|||
{filename: path.join(outDir, 'react-loadable.json')},
|
||||
]);
|
||||
|
||||
// show compilation progress bar and build time
|
||||
// Show compilation progress bar and build time.
|
||||
const isProd = process.env.NODE_ENV === 'production';
|
||||
config
|
||||
.plugin('niceLog')
|
||||
|
|
|
@ -26,10 +26,10 @@ module.exports = function(fileString) {
|
|||
sourceToMetadata,
|
||||
} = options;
|
||||
|
||||
/* Extract content of markdown (without frontmatter) */
|
||||
// Extract content of markdown (without frontmatter).
|
||||
const {body} = fm(fileString);
|
||||
|
||||
/* Determine the source dir. e.g: /docs, /website/versioned_docs/version-1.0.0 */
|
||||
// Determine the source dir. e.g: /docs, /website/versioned_docs/version-1.0.0
|
||||
let sourceDir;
|
||||
const thisSource = this.resourcePath;
|
||||
if (thisSource.startsWith(translatedDir)) {
|
||||
|
@ -48,7 +48,7 @@ module.exports = function(fileString) {
|
|||
sourceDir = docsDir;
|
||||
}
|
||||
|
||||
/* Replace internal markdown linking (except in fenced blocks) */
|
||||
// Replace internal markdown linking (except in fenced blocks).
|
||||
let content = body;
|
||||
if (sourceDir) {
|
||||
let fencedBlock = false;
|
||||
|
@ -59,14 +59,13 @@ module.exports = function(fileString) {
|
|||
if (fencedBlock) return line;
|
||||
|
||||
let modifiedLine = line;
|
||||
/* Replace inline-style links or reference-style links e.g:
|
||||
This is [Document 1](doc1.md) -> we replace this doc1.md with correct link
|
||||
[doc1]: doc1.md -> we replace this doc1.md with correct link
|
||||
*/
|
||||
// Replace inline-style links or reference-style links e.g:
|
||||
// This is [Document 1](doc1.md) -> we replace this doc1.md with correct link
|
||||
// [doc1]: doc1.md -> we replace this doc1.md with correct link
|
||||
const mdRegex = /(?:(?:\]\()|(?:\]:\s?))(?!https)([^'")\]\s>]+\.md)/g;
|
||||
let mdMatch = mdRegex.exec(modifiedLine);
|
||||
while (mdMatch !== null) {
|
||||
/* Replace it to correct html link */
|
||||
// Replace it to correct html link.
|
||||
const mdLink = mdMatch[1];
|
||||
const targetSource = `${sourceDir}/${mdLink}`;
|
||||
const {permalink} =
|
||||
|
@ -86,21 +85,21 @@ module.exports = function(fileString) {
|
|||
const md = new Remarkable({
|
||||
langPrefix: 'hljs css language-',
|
||||
highlight(str, rawLang) {
|
||||
// Default language fallback
|
||||
// Default language fallback.
|
||||
const defaultLang =
|
||||
siteConfig.highlight && siteConfig.highlight.defaultLang;
|
||||
|
||||
// No syntax highlighting
|
||||
// No syntax highlighting.
|
||||
if (rawLang === 'text' || (!rawLang && !defaultLang)) {
|
||||
return escapeHtml(str);
|
||||
}
|
||||
|
||||
// User's own hljs function to register additional languages
|
||||
// User's own hljs function to register additional languages.
|
||||
if (siteConfig.highlight && siteConfig.highlight.hljs) {
|
||||
siteConfig.highlight.hljs(hljs);
|
||||
}
|
||||
|
||||
// Syntax highlighting
|
||||
// Syntax highlighting.
|
||||
const lang = rawLang.toLowerCase() || defaultLang;
|
||||
try {
|
||||
if (hljs.getLanguage(lang)) {
|
||||
|
@ -119,10 +118,10 @@ module.exports = function(fileString) {
|
|||
linkify: true,
|
||||
});
|
||||
|
||||
// Register anchors plugin
|
||||
// Register anchors plugin.
|
||||
md.use(anchors);
|
||||
|
||||
// Allow client sites to register their own plugins
|
||||
// Allow client sites to register their own plugins.
|
||||
if (siteConfig.markdownPlugins) {
|
||||
siteConfig.markdownPlugins.forEach(plugin => {
|
||||
md.use(plugin);
|
||||
|
@ -134,7 +133,8 @@ module.exports = function(fileString) {
|
|||
const html = md
|
||||
.render(content)
|
||||
.replace(/<pre><code>/g, '<pre><code class="hljs">');
|
||||
/* Return a React component */
|
||||
|
||||
// Return a React component.
|
||||
return `
|
||||
import React from 'react';
|
||||
import Markdown from '@theme/Markdown';
|
||||
|
|
|
@ -59,7 +59,7 @@ module.exports = (string, context = {}) => {
|
|||
}
|
||||
|
||||
if (typeof context.slugStats[slug] === 'number') {
|
||||
// search for an index, that will not clash with an existing headings
|
||||
// Search for an index, that will not clash with an existing headings
|
||||
while (
|
||||
typeof context.slugStats[`${slug}-${++context.slugStats[slug]}`] ===
|
||||
'number'
|
||||
|
@ -67,7 +67,7 @@ module.exports = (string, context = {}) => {
|
|||
slug += `-${context.slugStats[slug]}`;
|
||||
}
|
||||
|
||||
// we are tracking both original anchors and suffixed to avoid future name
|
||||
// We are tracking both original anchors and suffixed to avoid future name
|
||||
// clashing with headings with numbers e.g. `#Foo 1` may clash with the second `#Foo`
|
||||
context.slugStats[slug] = 0;
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ module.exports = function createServerConfig(props) {
|
|||
|
||||
const {siteConfig, blogMetadatas, docsMetadatas, pagesMetadatas} = props;
|
||||
|
||||
// static site generator webpack plugin
|
||||
// Static site generator webpack plugin.
|
||||
const docsFlatMetadatas = Object.values(docsMetadatas);
|
||||
const paths = [...blogMetadatas, ...docsFlatMetadatas, ...pagesMetadatas].map(
|
||||
data => data.permalink,
|
||||
|
@ -38,7 +38,7 @@ module.exports = function createServerConfig(props) {
|
|||
},
|
||||
]);
|
||||
|
||||
// show compilation progress bar
|
||||
// Show compilation progress bar.
|
||||
const isProd = process.env.NODE_ENV === 'production';
|
||||
config
|
||||
.plugin('niceLog')
|
||||
|
@ -46,7 +46,7 @@ module.exports = function createServerConfig(props) {
|
|||
{name: 'Server', color: 'yellow', skipBuildTime: isProd},
|
||||
]);
|
||||
|
||||
// user extended webpack-chain config
|
||||
// User-extended webpack-chain config.
|
||||
applyChainWebpack(props.siteConfig.chainWebpack, config, true);
|
||||
|
||||
return config;
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
const merge = require('webpack-merge');
|
||||
|
||||
// Modify the generated webpack config with normal webpack config
|
||||
// Modify the generated webpack config with normal webpack config.
|
||||
function applyConfigureWebpack(userConfig, config, isServer) {
|
||||
if (typeof userConfig === 'object') {
|
||||
return merge(config, userConfig);
|
||||
|
@ -21,7 +21,7 @@ function applyConfigureWebpack(userConfig, config, isServer) {
|
|||
return config;
|
||||
}
|
||||
|
||||
// Modify the generated webpack config with webpack-chain API
|
||||
// Modify the generated webpack config with webpack-chain API.
|
||||
function applyChainWebpack(userChainWebpack, config, isServer) {
|
||||
if (userChainWebpack) {
|
||||
userChainWebpack(config, isServer);
|
||||
|
|
|
@ -18,7 +18,7 @@ describe('loadDocs', () => {
|
|||
expect(docsMetadatas.hello).toEqual({
|
||||
category: 'Guides',
|
||||
id: 'hello',
|
||||
language: undefined,
|
||||
language: null,
|
||||
localized_id: 'hello',
|
||||
permalink: '/docs/hello',
|
||||
previous: 'foo/baz',
|
||||
|
@ -27,12 +27,12 @@ describe('loadDocs', () => {
|
|||
sidebar: 'docs',
|
||||
source: path.join(docsDir, 'hello.md'),
|
||||
title: 'Hello, World !',
|
||||
version: undefined,
|
||||
version: null,
|
||||
});
|
||||
expect(docsMetadatas['foo/bar']).toEqual({
|
||||
category: 'Test',
|
||||
id: 'foo/bar',
|
||||
language: undefined,
|
||||
language: null,
|
||||
localized_id: 'foo/bar',
|
||||
next: 'foo/baz',
|
||||
next_id: 'foo/baz',
|
||||
|
@ -41,7 +41,7 @@ describe('loadDocs', () => {
|
|||
sidebar: 'docs',
|
||||
source: path.join(docsDir, 'foo', 'bar.md'),
|
||||
title: 'Bar',
|
||||
version: undefined,
|
||||
version: null,
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -52,7 +52,7 @@ describe('loadDocs', () => {
|
|||
expect(docsMetadatas['version-1.0.0-foo/bar']).toEqual({
|
||||
category: 'Test',
|
||||
id: 'version-1.0.0-foo/bar',
|
||||
language: undefined,
|
||||
language: null,
|
||||
localized_id: 'version-1.0.0-foo/bar',
|
||||
next: 'version-1.0.0-foo/baz',
|
||||
next_id: 'version-1.0.0-foo/baz',
|
||||
|
@ -66,7 +66,7 @@ describe('loadDocs', () => {
|
|||
expect(docsMetadatas['foo/bar']).toEqual({
|
||||
category: 'Test',
|
||||
id: 'foo/bar',
|
||||
language: undefined,
|
||||
language: null,
|
||||
localized_id: 'foo/bar',
|
||||
next: 'foo/baz',
|
||||
next_id: 'foo/baz',
|
||||
|
@ -156,7 +156,7 @@ describe('loadDocs', () => {
|
|||
sidebar: 'docs',
|
||||
source: path.join(translatedDir, 'ko', 'foo', 'baz.md'),
|
||||
title: 'baz',
|
||||
version: undefined,
|
||||
version: null,
|
||||
});
|
||||
expect(docsMetadatas['en-foo/bar']).toEqual({
|
||||
category: 'Test',
|
||||
|
@ -170,7 +170,7 @@ describe('loadDocs', () => {
|
|||
sidebar: 'docs',
|
||||
source: path.join(docsDir, 'foo', 'bar.md'),
|
||||
title: 'Bar',
|
||||
version: undefined,
|
||||
version: null,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -20,21 +20,21 @@ describe('processMetadata', () => {
|
|||
const dataB = await processMetadata(sourceB, docsDir, env, {}, siteConfig);
|
||||
expect(dataA).toEqual({
|
||||
id: 'foo/bar',
|
||||
language: undefined,
|
||||
language: null,
|
||||
localized_id: 'foo/bar',
|
||||
permalink: '/docs/foo/bar',
|
||||
source: path.join(docsDir, sourceA),
|
||||
title: 'Bar',
|
||||
version: undefined,
|
||||
version: null,
|
||||
});
|
||||
expect(dataB).toEqual({
|
||||
id: 'hello',
|
||||
language: undefined,
|
||||
language: null,
|
||||
localized_id: 'hello',
|
||||
permalink: '/docs/hello',
|
||||
source: path.join(docsDir, sourceB),
|
||||
title: 'Hello, World !',
|
||||
version: undefined,
|
||||
version: null,
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -45,12 +45,12 @@ describe('processMetadata', () => {
|
|||
const data = await processMetadata(source, docsDir, env, {}, siteConfig);
|
||||
expect(data).toEqual({
|
||||
id: 'permalink',
|
||||
language: undefined,
|
||||
language: null,
|
||||
localized_id: 'permalink',
|
||||
permalink: '/docs/endiliey/permalink',
|
||||
source: path.join(docsDir, source),
|
||||
title: 'Permalink',
|
||||
version: undefined,
|
||||
version: null,
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -80,7 +80,7 @@ describe('processMetadata', () => {
|
|||
const dataD = await processMetadata(sourceD, docsDir, env, {}, siteConfig);
|
||||
expect(dataA).toEqual({
|
||||
id: 'version-1.0.0-foo/bar',
|
||||
language: undefined,
|
||||
language: null,
|
||||
localized_id: 'version-1.0.0-foo/bar',
|
||||
permalink: '/docs/1.0.0/foo/bar',
|
||||
source: path.join(versionedDir, sourceA),
|
||||
|
@ -89,7 +89,7 @@ describe('processMetadata', () => {
|
|||
});
|
||||
expect(dataB).toEqual({
|
||||
id: 'version-1.0.0-hello',
|
||||
language: undefined,
|
||||
language: null,
|
||||
localized_id: 'version-1.0.0-hello',
|
||||
permalink: '/docs/1.0.0/hello',
|
||||
source: path.join(versionedDir, sourceB),
|
||||
|
@ -98,7 +98,7 @@ describe('processMetadata', () => {
|
|||
});
|
||||
expect(dataC).toEqual({
|
||||
id: 'foo/bar',
|
||||
language: undefined,
|
||||
language: null,
|
||||
localized_id: 'foo/bar',
|
||||
permalink: '/docs/next/foo/bar',
|
||||
source: path.join(docsDir, sourceC),
|
||||
|
@ -107,7 +107,7 @@ describe('processMetadata', () => {
|
|||
});
|
||||
expect(dataD).toEqual({
|
||||
id: 'hello',
|
||||
language: undefined,
|
||||
language: null,
|
||||
localized_id: 'hello',
|
||||
permalink: '/docs/next/hello',
|
||||
source: path.join(docsDir, sourceD),
|
||||
|
@ -275,7 +275,7 @@ describe('processMetadata', () => {
|
|||
permalink: '/docs/ko/foo/bar',
|
||||
source: path.join(translatedDir, sourceA),
|
||||
title: 'Bar',
|
||||
version: undefined,
|
||||
version: null,
|
||||
});
|
||||
expect(dataB).toEqual({
|
||||
id: 'ko-hello',
|
||||
|
@ -284,7 +284,7 @@ describe('processMetadata', () => {
|
|||
permalink: '/docs/ko/hello',
|
||||
source: path.join(translatedDir, sourceB),
|
||||
title: 'Hello, World !',
|
||||
version: undefined,
|
||||
version: null,
|
||||
});
|
||||
expect(dataC).toEqual({
|
||||
id: 'en-foo/bar',
|
||||
|
@ -293,7 +293,7 @@ describe('processMetadata', () => {
|
|||
permalink: '/docs/en/foo/bar',
|
||||
source: path.join(docsDir, sourceC),
|
||||
title: 'Bar',
|
||||
version: undefined,
|
||||
version: null,
|
||||
});
|
||||
expect(dataD).toEqual({
|
||||
id: 'en-hello',
|
||||
|
@ -302,7 +302,7 @@ describe('processMetadata', () => {
|
|||
permalink: '/docs/en/hello',
|
||||
source: path.join(docsDir, sourceD),
|
||||
title: 'Hello, World !',
|
||||
version: undefined,
|
||||
version: null,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -100,7 +100,7 @@ describe('loadEnv', () => {
|
|||
expect(() => {
|
||||
loadEnv({siteDir, siteConfig});
|
||||
}).toThrowErrorMatchingInlineSnapshot(
|
||||
`"Please set a default language in 'docusaurus.config.js' which is enabled in 'languages.js'"`,
|
||||
`"Please set a default language in docusaurus.config.js which is enabled in languages.js"`,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue