简体   繁体   English

为github PROJECT页面配置Jekyll

[英]Configuring Jekyll for github PROJECT pages

I am at my wits end here. 我在这里结束了我的智慧。 I've been trying to look at all other example github project pages I could find and even the blogs but none exhibit the problems I am getting. 我一直在试图查看我能找到的所有其他示例github项目页面,甚至是博客,但没有一个表现出我遇到的问题。 First, I am trying to create a project page for my repo. 首先,我正在尝试为我的仓库创建一个项目页面。 I did this by following the usual tutorials, creating a gh-pages branch in my project repo and pushing. 我按照通常的教程,在我的项目仓库和推送中创建了一个gh-pages分支。

I managed to do these and template my files. 我设法做了这些并模板化我的文件。 I even managed to use HAML and SASS(they still both get converted to html/css and that's what I push to the repo so no problem there). 我甚至设法使用HAML和SASS(它们仍然被转换为html / css,这就是我推送到repo所以没有问题)。 I just think that I am configuring my jekyll wrong. 我只是认为我正在配置我的jekyll错误。 First, I don't see any configurations in other people's pages that use baseurl or url on config.yml. 首先,我没有看到在config.yml上使用baseurl或url的其他人页面中的任何配置。

The problem with mine is when looping through my posts: 我的问题是在我的帖子中循环:

{% for post in site.posts %}
  <a href="{{ post.url }}">{{ post.title }}</a>
{% endfor %}

It always generates the href as href="/post-title" 它始终生成href为href="/post-title"

my _config.yml btw only has this: 我的_config.yml btw只有这个:

permalink: /exercises/:title

The problem with this when I click the link, it always points to http://corroded.github.com/exercises/title-here when it should actually be http://corroded.github.com/projectname/exercises/title-here 当我点击链接时出现这个问题,它始终指向http://corroded.github.com/exercises/title-其实应该是http://corroded.github.com/projectname/exercises/title-这里

I have actually tried hard coding the path by doing: 我实际上尝试通过以下方式对路径进行硬编码:

<a href="http://corroded.github.com{{ post.url }}"> and this works. <a href="http://corroded.github.com{{ post.url }}">这是有效的。 It goes to the post BUT it shows it as plain text and not as the generated html. 它转到帖子但是它显示为纯文本而不是生成的html。 I know I am missing something very simple here but I can't seem to find it and I've been wrestling with this the whole weekend. 我知道我在这里错过了一些非常简单的东西,但我似乎无法找到它,整个周末我一直在努力解决这个问题。

Oh and I forgot to add: doing this in my localhost, I can access everything at: 哦,我忘了添加:在我的localhost中执行此操作,我可以访问以下所有内容:

http://localhost:4000/ and clicking on links will get me to http://localhost:4000/exercises/title-here and IT WORKS. http://localhost:4000/并点击链接将我带到http://localhost:4000/exercises/title-here和IT WORKS。 So I have a pretty good guess that it has something to do with the configuration. 所以我很好地猜测它与配置有关。

EDIT: This answer has been added to the Jekyll documentation at http://jekyllrb.com/docs/github-pages/ . 编辑:此答案已添加到http://jekyllrb.com/docs/github-pages/上的Jekyll文档中。


I finally figured out the trick, if you're looking for a solution with the standard URL for GitHub Pages ( username.github.io/project-name/ ). 如果你正在寻找一个带有GitHub页面标准URL的解决方案( username.github.io/project-name/ ),我终于找到了诀窍。 Here's what to do: 这是做什么的:

In _config.yml , set the baseurl option to /project-name -- note the leading slash and the absence of a trailing slash. _config.yml ,将baseurl选项设置为/project-name - 记下前导斜杠和缺少尾部斜杠。

Now you'll need to change the way you do links in your templates and posts, in the following two ways: 现在,您需要通过以下两种方式更改模板和帖子中的链接方式:

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"). 在引用JS或CSS文件时,请执行以下操作: {{ site.baseurl }}/path/to/css.css - 请注意紧跟在变量之后的斜杠(在“path”之前)。

When doing permalinks or internal links, do it like this: {{ site.baseurl }}{{ post.url }} -- note that there is no slash between the two variables. 在执行永久链接或内部链接时,请执行以下操作: {{ site.baseurl }}{{ post.url }} - 请注意,这两个变量之间没有斜杠。

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 getting in there to muck everything up): jekyll serve --baseurl '' 最后,如果您想在使用jekyll serve提交/部署之前预览您的站点,请确保将空字符串传递给--baseurl选项,以便您可以正常查看localhost:4000所有内容(不使用/project-name进入那里jekyll serve --baseurl ''一切): 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. 这样您就可以从localhost上的站点根目录本地预览您的站点,但是当GitHub从gh-pages分支生成您的页面时,所有URL都将以/project-name开头并正确解析。

More conversation about this problem on issue #332 . 问题#332上关于这个问题的更多讨论。

When you have a slash at the front of your permalink, it means that all URLs should be relative to the site root. 如果在永久链接的前面有斜杠,则表示所有URL都应该相对于站点根目录。 This is the reason that it's going to http://corroded.github.com/exercises/title-here instead of http://corroded.github.com/projectname/exercises/title-here . 这就是为什么它会转到http://corroded.github.com/exercises/title-here而不是http://corroded.github.com/projectname/exercises/title-here Try it without the first slash: 没有第一个斜线尝试它:

permalink: exercises/:title

The same thing goes for any URLs you create with HTML. 您使用HTML创建的任何网址都是一样的。 If you have: 如果你有:

<a href="/about">

it will always go to the root of the domain (eg http://corroded.github.com/about ). 它将始终到域的根目录(例如http://corroded.github.com/about )。 If you're project is called 'projectname', you can use HTML like 如果您的项目名为'projectname',则可以使用HTML

<a href="/projectname/about">

to link directly to pages (eg http://corroded.github.com/projectname/about ). 直接链接到页面(例如http://corroded.github.com/projectname/about )。

Of course, you can also use relative URLs (ie URLs without a leading slash) as well. 当然,您也可以使用相对URL (即没有前导斜杠的URL)。 You just have to be aware of where you are in the directory tree. 您只需要知道您在目录树中的位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM