Jekyll writes incorrect page urls assuming that the site is located at the root of the domain

StackOverflow https://stackoverflow.com/questions/22283492

  •  11-06-2023
  •  | 
  •  

سؤال

Using the default setup made by jekyll new siteName creating a folder located at "domain.com/siteName" so that the static content is outputted in "domain.com/siteName/_site". The issue being that all url:s to posts all point to "domain.com/" instead of "domain.com/siteName/_site". Setting "url: domain.com/siteName/_site" or "baseurl: domain.com/siteName/_site" in _config.yml makes no difference.

The static result is then served by nginx but that should be of no significance. The list with the urls to the posts are generated by the default snippet:

{% for post in site.posts %} <li><span>{{ post.date | date_to_string }}</span> &raquo; <a href="{{ post.url }}">{{ post.title }}</a></li> {% endfor %}

هل كانت مفيدة؟

المحلول

jaybe in #jekyll@irc.freenode.net gave the following solution:

Add baseurl: /siteName/_site to _config.yml and add {{site.baseurl}} before every {{post.url}}

The template then looks as follows:

{% for post in site.posts %}
  <li><span>{{ post.date | date_to_string }}</span> &raquo;
  <a href="{{ site.baseurl }}{{ post.url }}">{{ post.title }}</a></li>
{% endfor %}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top