mirror of
https://github.com/facebook/docusaurus.git
synced 2025-07-06 19:37:52 +02:00
refactor(v2): use absolute path instead of alias for metadata source (#967)
refactor(v2): use absolute path instead of alias for metadata source
This commit is contained in:
parent
f2927a9fc4
commit
b401a2adc0
8 changed files with 366 additions and 646 deletions
|
@ -1,4 +1,5 @@
|
|||
const {getOptions} = require('loader-utils');
|
||||
const path = require('path');
|
||||
const fm = require('front-matter');
|
||||
|
||||
module.exports = function(fileString) {
|
||||
|
@ -14,25 +15,23 @@ module.exports = function(fileString) {
|
|||
/* Extract content of markdown (without frontmatter) */
|
||||
const {body} = fm(fileString);
|
||||
|
||||
/* Determine the source dir. e.g: @docs, @translated_docs/ko and @versioned_docs/version-1.0.0 */
|
||||
/* Determine the source dir. e.g: /docs, /website/versioned_docs/version-1.0.0 */
|
||||
let sourceDir;
|
||||
let thisSource = this.resourcePath;
|
||||
const thisSource = this.resourcePath;
|
||||
if (thisSource.startsWith(translatedDir)) {
|
||||
thisSource = thisSource.replace(translatedDir, '@translated_docs');
|
||||
const {language, version} = sourceToMetadata[thisSource] || {};
|
||||
if (language && version && version !== 'next') {
|
||||
sourceDir = `@translated_docs/${language}/version-${version}`;
|
||||
sourceDir = path.join(translatedDir, language, `version-${version}`);
|
||||
} else if (language && (!version || version === 'next')) {
|
||||
sourceDir = `@translated_docs/${language}`;
|
||||
sourceDir = path.join(translatedDir, language);
|
||||
}
|
||||
} else if (thisSource.startsWith(versionedDir)) {
|
||||
thisSource = thisSource.replace(versionedDir, '@versioned_docs');
|
||||
const {version} = sourceToMetadata[thisSource] || {};
|
||||
if (version) {
|
||||
sourceDir = `@versioned_docs/version-${version}`;
|
||||
sourceDir = path.join(versionedDir, `version-${version}`);
|
||||
}
|
||||
} else if (thisSource.startsWith(docsDir)) {
|
||||
sourceDir = `@docs`;
|
||||
sourceDir = docsDir;
|
||||
}
|
||||
|
||||
/* Replace internal markdown linking (except in fenced blocks) */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue