mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-23 22:17:00 +02:00
fix(v2): do not reveal environment file path (#1692)
* fix(v2): do not reveal environment file path * changelog * fix broken markdown linking
This commit is contained in:
parent
84b2270039
commit
a684806a0f
9 changed files with 48 additions and 41 deletions
packages/docusaurus-plugin-content-docs-legacy/src/markdown
|
@ -5,6 +5,7 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
const path = require('path');
|
||||
const {getOptions} = require('loader-utils');
|
||||
const {resolve} = require('url');
|
||||
|
||||
|
@ -13,7 +14,7 @@ module.exports = async function(fileString) {
|
|||
const options = Object.assign({}, getOptions(this), {
|
||||
filepath: this.resourcePath,
|
||||
});
|
||||
const {docsDir, sourceToPermalink} = options;
|
||||
const {docsDir, siteDir, sourceToPermalink} = options;
|
||||
|
||||
// Determine the source dir. e.g: /docs, /website/versioned_docs/version-1.0.0
|
||||
let sourceDir;
|
||||
|
@ -37,15 +38,17 @@ module.exports = async function(fileString) {
|
|||
// 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;
|
||||
const mdRegex = /(?:(?:\]\()|(?:\]:\s?))(?!https)([^'")\]\s>]+\.mdx?)/g;
|
||||
let mdMatch = mdRegex.exec(modifiedLine);
|
||||
while (mdMatch !== null) {
|
||||
// Replace it to correct html link.
|
||||
const mdLink = mdMatch[1];
|
||||
const targetSource = `${sourceDir}/${mdLink}`;
|
||||
const aliasedSource = source =>
|
||||
`@site/${path.relative(siteDir, source)}`;
|
||||
const permalink =
|
||||
sourceToPermalink[resolve(thisSource, mdLink)] ||
|
||||
sourceToPermalink[targetSource];
|
||||
sourceToPermalink[aliasedSource(resolve(thisSource, mdLink))] ||
|
||||
sourceToPermalink[aliasedSource(targetSource)];
|
||||
if (permalink) {
|
||||
modifiedLine = modifiedLine.replace(mdLink, permalink);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue