最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【未解决】gitbook中用markdown的include实现根目录外部的README.md文件内容同步

gitbook crifan 4841浏览 0评论

折腾:

【已解决】gitbook中想要实现引用别的章节的内容

期间,无意间发现:

内容引用 | GitBook文档(中文版)

说是markdown支持include别的文件

而之前自己有个需求:

对于优化了gitbook的文件结构后,每个book根目录和src子目录,都有个README.md,需要内容保持同步:

而之前的做法是都是每次改动都要同时改两个文件

后来是用makefile实现了cp拷贝去同步:

<code>## copy README.md to ./src
copy_readme:
  cp README.md ./src/README.md
</code>

现在去试试换成include:

/Users/crifan/GitBook/Library/Import/ebook_system_gitbook/src/README.md

<code>{% include "../README.md" %}
</code>

结果出错:

<code>error: error while generating page "README.md":

Template render error: (/Users/crifan/GitBook/Library/Import/ebook_system_gitbook/src/README.md)
  FileOutOfScopeError: "/Users/crifan/GitBook/Library/Import/ebook_system_gitbook/README.md" not in "/Users/crifan/GitBook/Library/Import/ebook_system_gitbook/src"
</code>

看到:

Relative Internal Links in GitBook · Today I Learned…

好像不是包含内容,而只是引用内容

去试试

gitbook include markdown

“Include” extenal content · Issue #226 · GitbookIO/gitbook

仔细看错误信息,其实写的是:

ebook_system_gitbook/README.md

不在

ebook_system_gitbook/src

(因为book.json中配置的是

“root”: “./src”

这个路径中,所以不给你去包含

-》其实本身gitbook,看起来是支持include的语法的。

-〉只不过此处不在root的目录范围内,无法包含进来而已。

How to import a markdown file from github into local gitbook – Stack Overflow

gitbook Template render error FileOutOfScopeError not in

gitbook  FileOutOfScopeError not in

Template render error · Issue #1 · krishnaIndia/gitbook-plugin-customtheme

没有找到有参考价值的。

换个方式,让外部的引用内部的试试

/Users/crifan/GitBook/Library/Import/ebook_system_gitbook/README.md

<code>{% include "../README.md" %}
</code>

结果:是能正常build,但是对于源码来说,没法同步两个内容,所以放弃。

gitbook-plugin-include – npm

也支持gitbook内部有用,对于src外部的源码,还是没法起效果。

所以放弃。

转载请注明:在路上 » 【未解决】gitbook中用markdown的include实现根目录外部的README.md文件内容同步

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
89 queries in 0.174 seconds, using 22.14MB memory