静态资源未在GitHub Pages上加载 [英] Static resources not loading on GitHub Pages

查看:86
本文介绍了静态资源未在GitHub Pages上加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个网站,并试图将其托管在git中心页面上.我的网站位于-

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

上面的路径省略了<project name>

因此,每当我点击url时,我的静态文件都不会加载.

So whenever I hit the url my static files are not loaded.

有没有一种方法可以使其与github url一起使用?

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.

推荐答案

来自用于设置自定义域的文档:

警告:项目页面子路径如 http://username.github.io/projectname 不会重定向到 项目的自定义域.

Warning: Project pages subpaths like http://username.github.io/projectname will not be redirected to a project's custom domain.

这意味着,由于相对路径的原因,您既可以将资产放在username.github.io/project-name 上,也可以在自定义域上上.

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.

如果要在github中使用它们,请检查文档中有关 baseurl 配置,它位于页面底部的项目网址结构"中.很简单,您只需要添加

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 a

baseurl: /project-name

行到您的_config.yml并在永久链接中使用{{ baseurl }}标记,jekyll将进行替换.要在本地对其进行测试,只需使用此选项运行服务器

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 option

jekyll serve --baseurl ''

希望它会有所帮助:)编码愉快!

Hope it helps :) Happy coding!

这篇关于静态资源未在GitHub Pages上加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆