文档生成工具docfx在文件系统中托管时,菜单栏缺少“文章”和“API文档”,但在本地主机上的8080端口显示。

5
当我运行docfx docfx.json --serve命令并打开localhost:8080时,在顶部菜单中看到两个项目:“文章”和“API文档”。 当我在文件系统中导航到_site\并单击index.html在Chrome中打开它时,这些菜单项会消失。如何确保静态站点正常设置菜单?
我需要能够打包HTML文件并将它们发送给其他人在本地查看,而无需下载存储库并安装docFX。

查看_site\toc.html对您有帮助吗? - hcdocs
当我这样做时,我看到(未格式化)[在此输入以筛选] *文章 * API文档而且这两个页面都缺少任何导航。 - devlord
1个回答

10

原因: 页面需要额外的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

我开始觉得DocFx不是一个选项了... -t statictoc 解决了问题。谢谢! - owns

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接