fix(v2): do not reveal environment file path ()

* fix(v2): do not reveal environment file path

* changelog

* fix broken markdown linking
This commit is contained in:
Yangshun Tay 2019-07-22 23:12:21 -07:00 committed by Endi
parent 84b2270039
commit a684806a0f
9 changed files with 48 additions and 41 deletions
packages/docusaurus-plugin-content-docs-legacy/src/markdown

View file

@ -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);
}