从文件系统托管但显示在 localhost:8080 上时,docfx 菜单缺失 "Articles"、"Api Documentation"

docfx menu missing "Articles", "Api Documentation" when hosted from filesystem but show up on localhost:8080

当我 运行 docfx docfx.json --serve 并转到 localhost:8080 时,我在顶部菜单上看到两个项目:"Articles" 和 "Api Documentation"。当我在文件系统中导航到 _site\ 并单击 index.html 以在 Chrome 中打开它时,这些菜单项丢失了。当我 运行 作为静态站点时,如何确保菜单设置正确?

我需要能够打包 html 文件并将它们发送给人们,以便他们在本地查看,而无需他们下载存储库和安装 docFX。

原因:页面需要额外的JS文件到导航栏,但是被Chrome屏蔽了。您可以在 Chrome 控制台 (F12) 中看到这些错误:

docfx.vendor.js:4 Access to XMLHttpRequest at 'file:///C:/git/docfx-seed/_site/toc.html' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.
send @ docfx.vendor.js:4
docfx.vendor.js:4 Access to XMLHttpRequest at 'file:///C:/git/docfx-seed/_site/logo.svg' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.

解决方案:使用模板 statictoc,它已经将所有需要的部分嵌入到 HTML 文件中:

docfx docfx.json -t statictoc