我有一个 GitHub 托管 https://waltershub.github.io repo 是 https://github.com/waltershub/waltershub.github.io
该站点使用所有 Assets 和 css 在本地正确构建,但在托管版本上没有显示
控制台中的错误是:
[Error] Failed to load resource: the server responded with a status of 404 (HTTP/2.0 404) (font-awesome.css, line 0)
[Error] Failed to load resource: the server responded with a status of 404 (HTTP/2.0 404) (dark.css, line 0)
[Error] Failed to load resource: the server responded with a status of 404 (HTTP/2.0 404) (function.js, line 0)
[Error] Failed to load resource: the server responded with a status of 404 (HTTP/2.0 404) (walt.jpg, line 0)
[Error] Failed to load resource: the server responded with a status of 404 (HTTP/2.0 404) (walt.jpg, line 0)
我已经验证了 YAML,它很好
最佳答案
在 _config.yml
您正在使用 webpage
的 baseurl :
baseurl: "/webpage" # the subpath of your site, e.g. /blog
根据您的设置何时应该是''
:baseurl: ""
然后是加载 Assets 的部分:<link rel="stylesheet" href="{{ "/assets/fonts/font-awesome/css/font-awesome.css" | prepend: site.baseurl }}">
<link rel="stylesheet" href="{{site.baseurl}}/assets/stylesheets/{% if site.blog_theme == "light" %}light.css{% else %}dark.css{% endif %}">
将正确生成如下网址:<link rel="stylesheet" href="/assets/fonts/font-awesome/css/font-awesome.css">
<link rel="stylesheet" href="/assets/stylesheets/dark.css">
而不是错误:<link rel="stylesheet" href="/webpage/assets/fonts/font-awesome/css/font-awesome.css">
<link rel="stylesheet" href="/webpage/assets/stylesheets/dark.css">
关于jekyll GitHub 页面页面未加载 Assets ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46478421/