当我运行docfx docfx.json --serve
并转到localhost:8080
时,在顶部菜单上看到两个项目:“文章”和“ Api文档”。当我在文件系统中导航到_site\
并单击index.html
在Chrome中打开它时,这些菜单项丢失了。当我将其作为静态网站运行时,如何确保菜单设置正确?
我需要能够打包html文件并将其发送给人们,以便他们在本地查看,而无需下载回购文件和安装docFX。
答案 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