静态资源不加载在git hub页面上 [英] static resources not loading on git hub pages
问题描述
我创建了一个网站,并试图将其托管在git hub页面上。我的网站位于 -
http://< username> .github.io /< project name> /
但是我的站点的静态文件可以在以下路径找到 -
http://< username> .github.io / css / site.css
http://< username> .github.io /script/main.js
上面的路径省略了<项目名称> ;
因此,无论何时我点击网址,我的静态文件都不会被加载。 >有没有办法使它与github url一起工作?
注意:当我使用自定义域时,一切正常,因为相对在这种情况下路径很好。
临时解决方案
我创建了用户页面而不是项目页面来解决这个问题。 / div>
从文档设置自定义域:
$ b
警告:项目页面子路径像
http://username.github.io/projectname 不会被重定向到
项目的自定义域。
blockquote>
这意味着由于相对路径,您可以将
username.github.io/project-name
或。
如果您希望他们在github上查看文档中关于
baseurl
配置,它位于页面,在项目网址结构中。这很简单,你只需要添加一个baseurl:/ project-name
行添加到
_config.yml
并使用{{baseurl}}
标记在您的永久链接中,jekyll将执行替换。在本地测试它只需使用此选项运行服务器jekyll serve --baseurl''
希望它有助于:)愉快的编码!
I have created a website and am trying to host it on git hub pages. My site is available at -
http://<username>.github.io/<project name>/
But the static files for my site are available at the following path -
http://<username>.github.io/css/site.css http://<username>.github.io/script/main.js
The above path omits the
<project name>
So whenever I hit the url my static files are not loaded.
Is there a way to make it work with the github url?
Note: When I use a custom domain everything works fine because the relative paths are fine in that case.
Temporary Solution I have created a User page instead of a Project page to overcome this issue.
解决方案From the documentation to setup a custom domain:
Warning: Project pages subpaths like http://username.github.io/projectname will not be redirected to a project's custom domain.
This means that due to the relative paths you can either have the assets on your
username.github.io/project-name
or on your custom domain.If you want them in the github one check what the documentation says about the
baseurl
configuration, it's at the bottom of the page, in the "Project Url Structure". It's simple you just need to add abaseurl: /project-name
row to your
_config.yml
and use the{{ baseurl }}
tag in your permalinks, jekyll will do the substitutions. And to test it locally just run the server with this optionjekyll serve --baseurl ''
Hope it helps :) Happy coding!
这篇关于静态资源不加载在git hub页面上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!