Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(v2): use absolute path instead of alias for metadata source #967

Merged
merged 1 commit into from
Sep 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions v2/lib/load/docs/metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,10 @@ module.exports = async function processMetadata(
}

/*
The docs file source
e.g: `@docs/hello.md` or `@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`
*/
if (language && language !== defaultLangTag) {
metadata.source = `@translated_docs/${source}`;
} else if (version && version !== 'next') {
metadata.source = `@versioned_docs/${source}`;
} else {
metadata.source = `@docs/${source}`;
}
metadata.source = path.join(refDir, source);

/* Build the permalink */
const {baseUrl, docsUrl} = siteConfig;
Expand Down
15 changes: 7 additions & 8 deletions v2/lib/webpack/loader/markdown.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const {getOptions} = require('loader-utils');
const path = require('path');
const fm = require('front-matter');

module.exports = function(fileString) {
Expand All @@ -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) */
Expand Down
14 changes: 14 additions & 0 deletions v2/test/__fixtures__/translated-site/translated_docs/ko/hello.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@ title: Hello, World !

안녕하세요, 여기 엔 틸리에 :)

## 상대 링크

이것 바꾸기
[foo](foo/bar.md)

이것을 대체 할 수 없습니다.
[파일] (file.md)

아래를 교체하지 마십시오.

```
[hello] (hello.md)
```

## Blockquotes

> Blockquotes는 또한 중첩 될 수 있습니다 ...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@ title: Hello, World !

Hi, Endilie here :)

## Relative links

Replace this
[foo](foo/bar.md)

Can't replace this
[file](file.md)

Do not replace below

```
[hello](hello.md)
```

## Blockquotes

> Blockquotes can also be nested...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@ title: Hello, World !

Hi, Endilie here :)

## Relative links

Replace this
[foo](foo/bar.md)

Can't replace this
[file](file.md)

Do not replace below

```
[hello](hello.md)
```

## Blockquotes

> Blockquotes can also be nested...
Expand Down
Loading