简体   繁体   English

Jekyll网址在推送到Github页面时会添加斜杠

[英]Jekyll URLs add leading slash when pushed to Github Pages

I have successfully hosted on Github Pages. 我已经成功托管在Github Pages上。 Today I was trying to run the site through browser-sync so I could view my changes faster, and noticed that my urls were different when served locally than on the actual website. 今天,我试图通过浏览器同步来运行该网站,以便可以更快地查看更改,并注意到本地提供的URL与实际网站上的URL不同。 Here's what the local url looks like: 本地网址如下所示:

<a href="blog/post-title/">

Which when clicked on brings me to the page 点击后将我带到该页面

http://localhost:3000/blog/blog/oven-baked-fajitas/

This same link, once it has been pushed to the Github repo and processed by them, turns into 一旦将相同的链接推送到Github存储库并由他们处理,它就会变成

<a href="/blog/blog-title/">

Which works correctly. 哪个工作正常。

I link to individual posts in my archive like this: 我链接到存档中的各个帖子,如下所示:

<a href="{{ post.url }}">

And my _config.yml is as follows: 我的_config.yml如下:

name: Adam Hammes
description: Adam Hammes' Website
author: Adam Hammes
url: http://hammes.io
permalink: blog/:title/
excerpt_separator: <!--more-->
exclude: ["README.md", "gulpfile.js", "package.json", "node_modules"]

What I have tried: 我尝试过的

  1. I added baseurl: "" to my _config.yml ; 我在我的_config.yml添加了baseurl: "" ; no effect. 没有效果。

  2. I added baseurl: "/" ; 我添加了baseurl: "/" ; no effect. 没有效果。

  3. I added baseurl: "/" , and changed the link format to {{ site.baseurl }}{{ post.url}} ; 我添加了baseurl: "/" ,并将链接格式更改为{{ site.baseurl }}{{ post.url}} this fixed the links locally, but resulted in 2 leading slashes live thus breaking the links. 这在本地固定了链接,但导致2个前导斜线有效,从而断开了链接。

I was using an old version of Ruby. 我正在使用旧版本的Ruby。 By updating to Ruby 2 and then running gem install Jekyll I was able to get consistent behavior. 通过更新到Ruby 2,然后运行gem install Jekyll我能够获得一致的行为。

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

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