在生成概念 html 文件时参考 toc.yml

  • 本文关键字:参考 toc yml 文件 html docfx
  • 更新时间 :
  • 英文 :


我正在尝试创建一个 DocFx 模板,使用它对胡子的支持。

我希望能够根据项目根目录中的 toc.yml 文件在所有生成的 html 页面的导航栏中生成一个站点菜单。

我知道默认模板会这样做。但它显然是通过将 toc.yml 转换为独立的 html 文件来实现的,然后由概念 html 文件中的 javascript 解析以加载菜单。

我希望能够直接在创建概念 html 文件的胡子文件中执行此操作。

我创建了这个部分(toc.tmpl.partial),并在概念胡子文件的适当部分调用它:

{{!版权 (c) Microsoft.保留所有权利。根据 MIT 许可证获得许可。有关完整的许可证信息,请参阅项目根目录中的许可证文件。

<div class="sidenav">
this is sidenav!
{{#items}}
hello!
{{/items}}
</div>

但是,不幸的是,{{items}} 标签中的任何内容都不会生成。

然而,如果我在 toc.tmpl 中使用相同的代码,就会生成一个具有适当数量的 hello! 行的 html 文件。

所以我缺少一些关于 DocFx 各部分协同工作方式的基本知识。

这是我的简单概念文件生成器:

{{!include(/^styles/.*/)}}
{{!include(/^fonts/.*/)}}
{{!include(favicon.ico)}}
{{!include(logo.svg)}}
{{!include(search-stopwords.json)}}
<!DOCTYPE html>
<!--[if IE]><![endif]-->
<html>
{{>partials/head}}
<body data-spy="scroll" data-target="#affix">
{{>partials/navbar}}
<div style="position: relative; margin-top: 5px;">
<div class="toc-column" style="position: fixed;">
{{>partials/toc}}
</div>
<div style="position: fixed; left: 160px;" data-uid="{{uid}}">
{{{rawTitle}}}
{{{conceptual}}}
</div>
</div>
{{^_disableFooter}}
{{>partials/footer}}
{{/_disableFooter}}
{{>partials/scripts}}
</body>
</html>

一句话:items在 toc 的模型中,而不是在概念的模型中。在概念items中,您不会得到任何东西。您可以尝试运行docfx --exportRawModel以查看模型是什么样的。

实际上,您需要使TOC的模型在所有其他文件之间共享。您可以使用此处提到的isShared。将以下代码添加到您的toc.tmpl.js

exports.getOptions = function (model) {
return {
isShared: true;
};
}

更多信息可以在这里找到:http://dotnet.github.io/docfx/tutorial/intro_template.html

最新更新