从文件系统托管时,docfx菜单缺少“文章”,“ Api文档”,但显示在localhost:8080上

时间:2019-05-13 20:45:04

标签: asp.net-core docfx

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

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

1 个答案:

答案 0 :(得分:1)

原因:该页面需要在导航栏中添加其他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