jekyll 世纪使用模板过程的遇到的坑


前言:github 的Project Page入门级别文章是真的多,但是都是讲的浅显,使用中问题的自己总结下,总结下在使用总的问题点:

一:你在网上下的模板一般你本地使用jekyll 的时候配置baseUrl 是没有问题的,但是一旦push 到github上时,会存现有些资源(最为常见的是图片加载不出来)加载不出来,那是因为路径问题,建议使用将需要在_config.yml设置的路径baseurl :; url :等置空;

二是:github Page 的gemfile和需要另行配置 update github page 等; 注意经常 update bundle ;jekyll为开源项目跟新较快;参考网址:Setting up your GitHub Pages site locally with Jekyll 在github发布与jekyll的使用参考结合使用参考;

另附:github page的问题不要用百度搜:垃圾百度被hacker用来攻击github ,百度就被屏蔽了,使用搜狗搜jekyll问题,gitbub上专门解决各类问题的社区存在,记得换浏览器就行了;要不然找不到的;

使用jekyll 写静态网页,与发布在github page  的静态网页的不同是:需要另外配置Gemfile;打开gemfile 查看即可;

push 到github上时:出现错误的查看方式:如果出现不发email同时无错误,多是你文件本生的问题,建议是用本地jekyll调试好了再发布;


GitHub pages and relative paths

匿名 (未验证) 提交于 周六, 03/17/2018 - 13:54


I have created a gh-pages branch for a project that I am working on at GitHub.

I use Sublime text to author the website locally and my problem is that when this is pushed to GitHub, all the links to javascrips, images, and css files are invalid.

For instance, I have this in my head section.

This works great locally, but it does not work from GitHub as the links are not resolved using the repository name as part of the URL.

It asks for:


when it should have been asking for:


I could of course put the repo name as part of the URL, but that would prevent my site to work locally during development.

Any idea how to deal with this?


Which browser are you using? Are you sure that this happens? Because it shouldn't. If you include a relative URL in a link, it will get resolved relative to the URL of the document that contains the link. In other words, when you include

in an HTML document at, the link to assets/css/common.css will get resolved by appending it to the prefix of the URL of the HTML document without the last part of the path (without doc.html), i.e. the link will resolve to, not to as you claim.

For example, view the source of the Twitter Bootstrap webpage: Notice the style links at the top, specified as . That link correctly resolves to, i.e. it does include the repo name.


You'll need to use Jekyll.

Copying verbatim from the relevant documentation:

Sometimes it’s nice to preview your Jekyll site before you push your gh-pages branch to GitHub. However, the subdirectory-like URL structure GitHub uses for Project Pages complicates the proper resolution of URLs. Here is an approach to utilizing the GitHub Project Page URL structure ( whilst maintaining the ability to preview your Jekyll site locally.

  1. In _config.yml, set the baseurl option to /project-name – note the leading slash and the absence of a trailing slash.

  2. When referencing JS or CSS files, do it like this: {{ site.baseurl}}/path/to/css.css – note the slash immediately following the variable (just before “path”).

  3. When doing permalinks or internal links, do it like this: {{ site.baseurl }}{{ post.url }} – note that there is no slash between the two variables.

  4. Finally, if you’d like to preview your site before committing/deploying using jekyll serve, be sure to pass an empty string to the --baseurl option, so that you can view everything at localhost:4000 normally (without /project-name at the beginning): jekyll serve --baseurl ''

This way you can preview your site locally from the site root on localhost, but when GitHub generates your pages from the gh-pages branch all the URLs will start with /project-name and resolve properly.

(Apparently someone figured this out only a few months ago.)


This should not be an issue anymore in Dec. 2016, 3 and an half years later.
See "Relative links for GitHub pages", published by Ben Balter:

You've been able to use relative links when authoring Markdown on for a while.

(that is from January 2013)

Now, those links will continue to work when published via GitHub Pages.

If you have a Markdown file in your repository at docs/, and you want to link from that file to docs/, you can do so with the following markup:

[a relative link](

When you view the source file on, the relative link will continue to work, as it has before, but now, when you publish that file using GitHub Pages, the link will be silently translated to docs/another-page.html to match the target page's published URL.

Under the hood, we're using the open source Jekyll Relative Links plugin, which is activated by default for all builds.

Relative links on GitHub Pages also take into account custom permalinks (e.g., permalink: /docs/page/) in a file's YAML front matter, as well as prepend project pages' base URL as appropriate, ensuring links continue to work in any context.

And don't forget that since August 2016, you can publish your pages right from the master branch (not always the gh-pages branch)

And since Dec. 2016, you don't even need Jekyll or Simple markdown files are enough.


Another option is to create a new repo specifically for the webpages. If you name the repo as [user] on github then it will be published at https://[user] and you can avoid having the repo name in the URL path completely. Obviously the downside is that you can only have 1 repo like this per github user, so it may not suit your needs, I'm not sure.


It seems that Github Pages is not very responsive. Though it makes new files available immediately, modified files would not appear immediately due to caching or something.

After waiting 15 minutes or so, everything is fine.

转载请标明出处:GitHub pages and relative paths


                                                                                            我的Git  Home Page

想对作者说点什么? 我来说一句