Skip to content

Commit bfd0d18

Browse files
committed
fix: resolve path of image and embed files, fixed #412
1 parent 74ff68a commit bfd0d18

File tree

8 files changed

+29
-23
lines changed

8 files changed

+29
-23
lines changed

docs/de-de/custom-navbar.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ Du kannst untergeordnete Listen erstellen, indem du untergeordnete Punkte einem
6868

6969
wird also wie folgt aussehen
7070

71-
![Nesting navbar](_images/nested-navbar.png 'Nesting navbar')
71+
![Nesting navbar](../_images/nested-navbar.png 'Nesting navbar')
7272

7373
## Angepasste Navigationsleisten in Verbindung mit dem emoji Erweiterung
7474

docs/de-de/deploy.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Du kannst folgende drei Orte verwenden, um die Dokumentation für dein Github re
1212

1313
Es wird empfohlen, deine Dateien im `./docs` Unterordner im `master` branch deines repository zu speichern. Wechsle dann zu den Einstellungen deines repository und wähle `master branch /docs folder` als deine Github Pages Quelle.
1414

15-
![github pages](_images/deploy-github-pages.png)
15+
![github pages](../_images/deploy-github-pages.png)
1616

1717
!> Du kannst die Dateien auch im Hauptverzeichnis speichern und dann `master branch` in den Einstellungen auswählen.
1818

docs/de-de/embed-files.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ You can embed these files as video, audio, iframes, or code blocks, and even Mar
66
For example, here embedded a Markdown file. You only need to do this:
77

88
```markdown
9-
[filename](_media/example.md ':include')
9+
[filename](../_media/example.md ':include')
1010
```
1111

1212
Then the content of `example.md` will be displayed directly here
1313

14-
[filename](_media/example.md ':include')
14+
[filename](../_media/example.md ':include')
1515

16-
You can check the original content for [example.md](_media/example.md ':ignore').
16+
You can check the original content for [example.md](../_media/example.md ':ignore').
1717

1818
Normally, this will compiled into a link, but in docsify, if you add `:include` it will be embedded.
1919

@@ -32,12 +32,12 @@ This is a supported embedding type:
3232
Of course, you can force the specified. For example, you want to Markdown file as code block embedded.
3333

3434
```markdown
35-
[filename](_media/example.md ':include :type=code')
35+
[filename](../_media/example.md ':include :type=code')
3636
```
3737

3838
You will get it
3939

40-
[filename](_media/example.md ':include :type=code')
40+
[filename](../_media/example.md ':include :type=code')
4141

4242
## Tag attribute
4343

@@ -56,11 +56,11 @@ Did you see it? You only need to write directly. You can check [MDN](https://dev
5656
Embedding any type of source code file, you can specify the highlighted language or automatically identify.
5757

5858
```markdown
59-
[](_media/example.html ':include :type=code text')
59+
[](../_media/example.html ':include :type=code text')
6060
```
6161

6262
⬇️
6363

64-
[](_media/example.html ':include :type=code text')
64+
[](../_media/example.html ':include :type=code text')
6565

6666
?> How to set highlight? You can see [here](language-highlight.md).

docs/zh-cn/custom-navbar.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,4 @@ _\_navbar.md_
6161

6262
效果图
6363

64-
![嵌套导航栏](_images/zh-cn/nested-navbar.png '嵌套导航栏')
64+
![嵌套导航栏](../_images/zh-cn/nested-navbar.png '嵌套导航栏')

docs/zh-cn/deploy.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ GitHub Pages 支持从三个地方读取文件
1111

1212
我们推荐直接将文档放在 `docs/` 目录下,在设置页面开启 **GitHub Pages** 功能并选择 `master branch /docs folder` 选项。
1313

14-
![github pages](_images/deploy-github-pages.png)
14+
![github pages](../_images/deploy-github-pages.png)
1515

1616
!> 可以将文档放在根目录下,然后选择 **master 分支** 作为文档目录。
1717

docs/zh-cn/embed-files.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ docsify 4.6 开始支持嵌入任何类型的文件到文档里。你可以将
55
这是一个嵌入 Markdown 文件的例子。
66

77
```markdown
8-
[filename](_media/example.md ':include')
8+
[filename](../_media/example.md ':include')
99
```
1010

1111
`example.md` 文件的内容将会直接显示在这里
1212

13-
[filename](_media/example.md ':include')
13+
[filename](../_media/example.md ':include')
1414

15-
你可以查看 [example.md](_media/example.md ':ignore') 原始内容对比效果。
15+
你可以查看 [example.md](../_media/example.md ':ignore') 原始内容对比效果。
1616

1717
通常情况下,这样的语法将会被当作链接处理。但是在 docsify 里,如果你添加一个 `:include` 选项,它就会被当作文件嵌入。
1818

@@ -29,12 +29,12 @@ docsify 4.6 开始支持嵌入任何类型的文件到文档里。你可以将
2929
当然,你也可以强制设置嵌入类型。例如你想将 Markdown 文件当作一个 `code block` 嵌入。
3030

3131
```markdown
32-
[filename](_media/example.md ':include :type=code')
32+
[filename](../_media/example.md ':include :type=code')
3333
```
3434

3535
你将得到
3636

37-
[filename](_media/example.md ':include :type=code')
37+
[filename](../_media/example.md ':include :type=code')
3838

3939
## 标签属性
4040

@@ -53,11 +53,11 @@ docsify 4.6 开始支持嵌入任何类型的文件到文档里。你可以将
5353
如果是嵌入一个代码块,你可以设置高亮的语言,或者让它自动识别。这里是手动设置高亮语言
5454

5555
```markdown
56-
[](_media/example.html ':include :type=code text')
56+
[](../_media/example.html ':include :type=code text')
5757
```
5858

5959
⬇️
6060

61-
[](_media/example.html ':include :type=code text')
61+
[](../_media/example.html ':include :type=code text')
6262

6363
?> 如何高亮代码?你可以查看[这份文档](language-highlight.md).

package-lock.json

+4-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/core/render/compiler.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {helper as helperTpl, tree as treeTpl} from './tpl'
44
import {genTree} from './gen-tree'
55
import {slugify} from './slugify'
66
import {emojify} from './emojify'
7-
import {isAbsolutePath, getPath} from '../router/util'
7+
import {isAbsolutePath, getPath, getParentPath} from '../router/util'
88
import {isFn, merge, cached, isPrimitive} from '../util/core'
99

1010
const cachedLinks = {}
@@ -112,7 +112,11 @@ export class Compiler {
112112

113113
if (config.include) {
114114
if (!isAbsolutePath(href)) {
115-
href = getPath(process.env.SSR ? '' : this.contentBase, href)
115+
href = getPath(
116+
process.env.SSR ? '' : this.contentBase,
117+
getParentPath(this.router.getCurrentPath()),
118+
href
119+
)
116120
}
117121

118122
let media
@@ -254,7 +258,7 @@ export class Compiler {
254258
}
255259

256260
if (!isAbsolutePath(href)) {
257-
url = getPath(contentBase, href)
261+
url = getPath(contentBase, getParentPath(router.getCurrentPath()), href)
258262
}
259263

260264
return `<img src="${url}"data-origin="${href}" alt="${text}"${attrs}>`

0 commit comments

Comments
 (0)