强制在 Jekyll 中使用绝对 URL
Forced to use Absolute URLs in Jekyll
我正在尝试使用我所在大学提供的域来设置 Jekyll 的个人主页。
我无法解决的一个问题是 Jekyll 强迫我使用我认为与网页托管服务不兼容的绝对路径。
_config.yml 文件决定了 Jekyll 如何在 index.html 文件(即主页)中生成链接。 _config.yml 看起来像这样...
title: Homepage | Ishank Juneja
email: ishankjuneja@gmail.com
description: >- # this means to ignore newlines until "baseurl:"
Personal homepage Beta version
baseurl: "foobar" # the subpath of your
site, e.g. /blog
url: "http://home.iitb.ac.in/~ishankjuneja" # the base hostname & protocol for your site, e.g.
http://example.com
twitter_username: ishankjuneja
github_username: ishank-juneja
# Build settings
markdown: kramdown
theme: minima
plugins:
- jekyll-feed
它在 index.html 文件中生成的(许多)链接的一个示例是
<link rel="stylesheet" href="/foobar/assets/main.css">
This link 向我解释说,这实际上是一个绝对路径,对我来说这似乎不是问题,但是 Web 托管服务上的目录树看起来像,
public_html
├── 404.html
├── about
│ └── index.html
├── assets
│ ├── main.css
│ └── minima-social-icons.svg
├── feed.xml
├── index.html
└── jekyll
└── update
└── 2018
└── 10
└── 04
└── test-post.html
我的主页 http://home.iitb.ac.in/~ishankjuneja/
的 URL 与文件夹 public_html
关联,因此上述 main.css 的路径不正确。 href="assets/main.css"
之类的东西运行良好,但我似乎无法输入 _config.yml
来获得此结果。
在配置中,您必须正确设置 baseurl:
baseurl: "~ishankjuneja"
然后使用
{{site.baseurl}}page.url
使用{{ page.url | absolute_url }}
在您的示例中,放置 /foobar(_config.yml 中的 baseurl)不是一个好主意。
如您所说,使用绝对 URl 也不是一个好主意。
解决方案是使用 relative_url 液体过滤器作为
<link rel="stylesheet" href={{"/assets/main.css" | relative_url }} >
@Aleksandr Kiselev 建议的类似解决方案。
我正在尝试使用我所在大学提供的域来设置 Jekyll 的个人主页。
我无法解决的一个问题是 Jekyll 强迫我使用我认为与网页托管服务不兼容的绝对路径。
_config.yml 文件决定了 Jekyll 如何在 index.html 文件(即主页)中生成链接。 _config.yml 看起来像这样...
title: Homepage | Ishank Juneja
email: ishankjuneja@gmail.com
description: >- # this means to ignore newlines until "baseurl:"
Personal homepage Beta version
baseurl: "foobar" # the subpath of your
site, e.g. /blog
url: "http://home.iitb.ac.in/~ishankjuneja" # the base hostname & protocol for your site, e.g.
http://example.com
twitter_username: ishankjuneja
github_username: ishank-juneja
# Build settings
markdown: kramdown
theme: minima
plugins:
- jekyll-feed
它在 index.html 文件中生成的(许多)链接的一个示例是
<link rel="stylesheet" href="/foobar/assets/main.css">
This link 向我解释说,这实际上是一个绝对路径,对我来说这似乎不是问题,但是 Web 托管服务上的目录树看起来像,
public_html
├── 404.html
├── about
│ └── index.html
├── assets
│ ├── main.css
│ └── minima-social-icons.svg
├── feed.xml
├── index.html
└── jekyll
└── update
└── 2018
└── 10
└── 04
└── test-post.html
我的主页 http://home.iitb.ac.in/~ishankjuneja/
的 URL 与文件夹 public_html
关联,因此上述 main.css 的路径不正确。 href="assets/main.css"
之类的东西运行良好,但我似乎无法输入 _config.yml
来获得此结果。
在配置中,您必须正确设置 baseurl:
baseurl: "~ishankjuneja"
然后使用
{{site.baseurl}}page.url
使用{{ page.url | absolute_url }}
在您的示例中,放置 /foobar(_config.yml 中的 baseurl)不是一个好主意。
如您所说,使用绝对 URl 也不是一个好主意。
解决方案是使用 relative_url 液体过滤器作为
<link rel="stylesheet" href={{"/assets/main.css" | relative_url }} >
@Aleksandr Kiselev 建议的类似解决方案。