diff --git a/lib/load/index.js b/lib/load/index.js index 7c986f7c3e..e7c91d005f 100644 --- a/lib/load/index.js +++ b/lib/load/index.js @@ -27,10 +27,16 @@ module.exports = async function load(siteDir) { ); /* Create source to permalink mapping */ - const sourceToLink = {}; - Object.values(docsMetadata).forEach(({source, permalink}) => { - sourceToLink[source] = permalink; - }); + const sourceToMetadata = {}; + Object.values(docsMetadata).forEach( + ({source, version, permalink, language}) => { + sourceToMetadata[source] = { + version, + permalink, + language + }; + } + ); // pages const pagesDir = path.resolve(siteDir, 'pages'); @@ -61,7 +67,7 @@ module.exports = async function load(siteDir) { outDir, themePath, baseUrl, - sourceToLink, + sourceToMetadata, versionedDir, translatedDir }; diff --git a/lib/webpack/base.js b/lib/webpack/base.js index 9913fe9a31..9a135a45fc 100644 --- a/lib/webpack/base.js +++ b/lib/webpack/base.js @@ -13,7 +13,7 @@ module.exports = function createBaseConfig(props, isServer) { docsDir, pagesDir, siteDir, - sourceToLink, + sourceToMetadata, versionedDir, translatedDir, baseUrl @@ -78,7 +78,13 @@ module.exports = function createBaseConfig(props, isServer) { mdRule .use('markdown-loader') .loader(mdLoader) - .options({siteConfig, versionedDir, translatedDir, docsDir, sourceToLink}); + .options({ + siteConfig, + versionedDir, + translatedDir, + docsDir, + sourceToMetadata + }); const cssRule = config.module.rule('css').test(/\.css$/); if (isProd) { diff --git a/lib/webpack/loader/markdown.js b/lib/webpack/loader/markdown.js index 335a6c59ca..e5893299a6 100644 --- a/lib/webpack/loader/markdown.js +++ b/lib/webpack/loader/markdown.js @@ -8,25 +8,36 @@ module.exports = function(fileString) { versionedDir, docsDir, translatedDir, - sourceToLink + sourceToMetadata } = options; /* Extract content of markdown (without frontmatter) */ const {body} = fm(fileString); - /* Determine whether this file is in @docs, @versioned_docs or @translated_docs */ - let dirAlias; - if (this.resourcePath.startsWith(translatedDir)) { - dirAlias = '@translated_docs'; - } else if (this.resourcePath.startsWith(versionedDir)) { - dirAlias = '@versioned_docs'; - } else if (this.resourcePath.startsWith(docsDir)) { - dirAlias = '@docs'; + /* Determine the source dir. e.g: @docs, @translated_docs/ko and @versioned_docs/version-1.0.0 */ + let sourceDir; + let 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}`; + } else if (language && (!version || version === 'next')) { + sourceDir = `@translated_docs/${language}`; + } + } else if (thisSource.startsWith(versionedDir)) { + thisSource = thisSource.replace(versionedDir, '@versioned_docs'); + const {version} = sourceToMetadata[thisSource] || {}; + if (version) { + sourceDir = `@versioned_docs/version-${version}`; + } + } else if (thisSource.startsWith(docsDir)) { + sourceDir = `@docs`; } /* Replace internal markdown linking (except in fenced blocks) */ let content = body; - if (dirAlias) { + if (sourceDir) { let fencedBlock = false; const lines = body.split('\n').map(line => { if (line.trim().startsWith('```')) { @@ -43,8 +54,8 @@ module.exports = function(fileString) { match = mdRegex.exec(content); } mdLinks.forEach(mdLink => { - const source = `${dirAlias}/${mdLink}`; - const permalink = sourceToLink[source]; + const targetSource = `${sourceDir}/${mdLink}`; + const {permalink} = sourceToMetadata[targetSource] || {}; if (permalink) { modifiedLine = modifiedLine.replace(mdLink, permalink); } diff --git a/test/__fixtures__/docs/hello.md b/test/__fixtures__/docs/hello.md index a392b2ca54..ab550d7363 100644 --- a/test/__fixtures__/docs/hello.md +++ b/test/__fixtures__/docs/hello.md @@ -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... diff --git a/test/__fixtures__/transversioned-site/translated_docs/ko/foo/bar.md b/test/__fixtures__/transversioned-site/translated_docs/ko/foo/bar.md new file mode 100644 index 0000000000..a1b031cb23 --- /dev/null +++ b/test/__fixtures__/transversioned-site/translated_docs/ko/foo/bar.md @@ -0,0 +1,66 @@ +--- +id: bar +title: Bar +--- + +# Remarkable + +> Remarkable로 실시간 편집을 경험하십시오! + +깨끗한 슬레이트로 시작하려면`clear` 링크를 클릭하고 결과를 공유하거나 저장하려면`permalink`를 가져옵니다. + +*** + +# h1 제목 +## h2 제목 +### h3 제목 +#### h4 헤딩 +##### h5 제목 +###### h6 제목 + + +## 수평 규칙 + +___ + +*** + +*** + + +## 활자체 대체 + +입력기 옵션을 사용하면 결과를 볼 수 있습니다. + +(p) (P) + - (r) (t) + +테스트 .. 테스트 ... 테스트 ..... 테스트? ..... 테스트! .... + +!!!!!! ???? ,, + +놀라운 - 굉장한 + +"Smartypants, 큰 따옴표" + +'Smartypants, 작은 따옴표' + + +## 강조 + +** 이것은 굵은 글씨입니다 ** + +__ 이것은 굵은 글씨입니다 __ + +* 이탤릭체 텍스트 * + +_ 이탤릭체 텍스트 _ + +~~ 삭제 된 텍스트 ~~ + +위 첨자 : 19 ^ th ^ + +아래 첨자 : H ~ 2 ~ O + +++ 삽입 된 텍스트 ++ + +== 표시된 텍스트 == \ No newline at end of file diff --git a/test/__fixtures__/transversioned-site/translated_docs/ko/foo/baz.md b/test/__fixtures__/transversioned-site/translated_docs/ko/foo/baz.md new file mode 100644 index 0000000000..c078572ef4 --- /dev/null +++ b/test/__fixtures__/transversioned-site/translated_docs/ko/foo/baz.md @@ -0,0 +1,74 @@ +--- +id: baz +title: baz +--- + +## 이미지 + +링크와 마찬가지로 이미지에도 각주 스타일 구문이 있습니다. + +! [Alt text] [id] + +나중에 URL 위치를 정의하는 문서에서 참조로 : + +[id] : https://octodex.github.com/images/dojocat.jpg "The Dojocat" + +## 링크 + +[링크 텍스트] (http://dev.nodeca.com) + +[제목 링크] (http://nodeca.github.io/pica/demo/ "제목 텍스트!") + +자동 변환 된 링크 https://github.com/nodeca/pica (linkify를 사용하도록 설정) + + + +## 각주 + +각주 1 링크 [^ 첫 번째]. + +각주 2 링크 [^ 초]. + +인라인 각주 ^ [인라인 각주의 텍스트] 정의. + +중복 된 각주 참조 [^ 초]. + +[^ first] : 각주 **는 마크 업을 가질 수 있습니다 ** + +    및 여러 단락. + +[^ 초] : 각주 텍스트. + + +## 정의 목록 + +1 학기 + +정의 1 +게으른 연속. + +* 인라인 마크 업과 함께 2 학기 * + +: 정의 2 + +        {일부 코드, 정의 2의 일부} + +    정의의 세 번째 단락 2. + +_ 컴팩트 스타일 : _ + +1 학기 +  ~ 정의 1 + +2 학기 +  ~ 정의 2a +  ~ 정의 2b + + +## 약어 + +이것은 HTML 약어입니다. + +그것은 "HTML"을 변환하지만 "xxxHTMLyyy"와 같이 부분적인 항목을 그대로 유지합니다. + +* [HTML] : 하이퍼 텍스트 마크 업 언어 \ No newline at end of file diff --git a/test/__fixtures__/transversioned-site/translated_docs/ko/hello.md b/test/__fixtures__/transversioned-site/translated_docs/ko/hello.md new file mode 100644 index 0000000000..cb2afd1888 --- /dev/null +++ b/test/__fixtures__/transversioned-site/translated_docs/ko/hello.md @@ -0,0 +1,54 @@ +--- +id: hello +title: Hello, World ! +--- + +안녕하세요, 여기 엔 틸리에 :) + +## 상대 링크 + +이것 바꾸기 +[foo](foo/bar.md) + +이것을 대체 할 수 없습니다. +[파일] (file.md) + +아래를 교체하지 마십시오. + +``` +[hello] (hello.md) +``` + +## Blockquotes + +> Blockquotes는 또한 중첩 될 수 있습니다 ... +>> ... 서로 옆에 큰 더 큰 부호를 사용하여 ... +>>> ... 또는 화살표 사이에 공백이 있어야합니다. + + +## 목록 + +정렬되지 않은 + ++`+`,`-` 또는`*`를 사용하여 행을 시작하여 목록을 만듭니다. ++ 하위 목록은 2 칸을 들여서 만들어집니다 : +   - 마커 문자 변경으로 새로운 목록 시작 : +     * AC tristique libero volutpat at +     + Preisium nisl aliquet에 대한 + 시설 +     - Nulla volutpat aliquam velit ++ 매우 쉽습니다! + +주문 됨 + +1. Lorem ipsum dolor sit amet +2. 컨소시엄 adipiscing 엘리트 +3. massa에서의 정수 lorem + + +1. 일련 번호를 사용할 수 있습니다 ... +1. ... 또는 모든 숫자를 '1'로 유지하십시오. + +오프셋을 사용하여 번호 매기기 시작 : + +57. foo +1. 막대기 \ No newline at end of file diff --git a/test/__fixtures__/transversioned-site/translated_docs/ko/version-1.0.0/hello.md b/test/__fixtures__/transversioned-site/translated_docs/ko/version-1.0.0/hello.md index 5075f44119..5148b6723f 100644 --- a/test/__fixtures__/transversioned-site/translated_docs/ko/version-1.0.0/hello.md +++ b/test/__fixtures__/transversioned-site/translated_docs/ko/version-1.0.0/hello.md @@ -5,6 +5,20 @@ title: Hello, World ! 안녕하세요, 여기 엔 틸리에 :) +## 상대 링크 + +이것 바꾸기 +[foo](foo/bar.md) + +이것을 대체 할 수 없습니다. +[파일] (file.md) + +아래를 교체하지 마십시오. + +``` +[hello] (hello.md) +``` + ## Blockquotes > Blockquotes는 또한 중첩 될 수 있습니다 ... diff --git a/test/__fixtures__/transversioned-site/translated_docs/ko/version-1.0.1/hello.md b/test/__fixtures__/transversioned-site/translated_docs/ko/version-1.0.1/hello.md index 80ef3933a4..f76f93aabb 100644 --- a/test/__fixtures__/transversioned-site/translated_docs/ko/version-1.0.1/hello.md +++ b/test/__fixtures__/transversioned-site/translated_docs/ko/version-1.0.1/hello.md @@ -5,6 +5,20 @@ title: Hello, World ! 안녕하세요, 여기 엔 틸리에 :) +## 상대 링크 + +이것 바꾸기 +[foo](foo/bar.md) + +이것을 대체 할 수 없습니다. +[파일] (file.md) + +아래를 교체하지 마십시오. + +``` +[hello] (hello.md) +``` + ## Blockquotes > Blockquotes는 또한 중첩 될 수 있습니다 ... diff --git a/test/__fixtures__/transversioned-site/versioned_docs/version-1.0.0/hello.md b/test/__fixtures__/transversioned-site/versioned_docs/version-1.0.0/hello.md index ef91d00826..56665f5b2e 100644 --- a/test/__fixtures__/transversioned-site/versioned_docs/version-1.0.0/hello.md +++ b/test/__fixtures__/transversioned-site/versioned_docs/version-1.0.0/hello.md @@ -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... diff --git a/test/__fixtures__/transversioned-site/versioned_docs/version-1.0.1/hello.md b/test/__fixtures__/transversioned-site/versioned_docs/version-1.0.1/hello.md index 3a81461691..9e6725f688 100644 --- a/test/__fixtures__/transversioned-site/versioned_docs/version-1.0.1/hello.md +++ b/test/__fixtures__/transversioned-site/versioned_docs/version-1.0.1/hello.md @@ -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...