4

我有一个 GitHub 托管 https://waltershub.github.io回购是https://github.com/waltershub/waltershub.github.io

该站点使用所有资产和 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,它很好

4

1 回答 1

5

_config.yml您使用的 baseurl 中webpage

baseurl: "/webpage" # the subpath of your site, e.g. /blog

根据您的设置应该是''

baseurl: ""

然后是加载资产的部分:

<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">
于 2017-09-28T21:31:27.580 回答