1
votes

I have started a small website with a few pages and a couple of blog posts. It is hosted on my organization's server and I ftp'ed all contents of _site/ directory into a subdirectory of the website. Hence the Jekyll site is at http:// myusername.foobar.foo/thiswebsite/ .

In my _config.yml

baseurl: "/thiswebsite"
url: "http:// myusername.foobar.foo"

Now all pages show up correctly. But blog posts don't.

In YAML front matter of each blog post:

permalink: /:title.html

Then I ended up generating links on index.html page to blog posts at http:// myusername.foobar.bar/blog-title.html but the actual blog posts are found at http:// myusername.foobar.bar/thiswebsite/blog-title.html. So if people click on the links found on index.html they will see 404.

On index.html I have:

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

I would have thought {{ post.url }} would automatically insert correct URL for the posts, but apparently that's not happening. :(

Where did I screw up?

(Jekyll version 3.1.2)

Note: blank space after http:// is intentional as StackExchange thinks I'm posting links and that's apparently not allowed. In my actual markdown and html they are proper URLs.

1
You need {{site.baseurl}}{{post.url}} when setting a baseurl in your configmichaPau

1 Answers

0
votes

Link to a collection item (post are collections items) or pages :

eg : <a href="{{ site.baseurl }}{{ post.url }}">{{ post.title }}</a>

or <a href="{{ post.url | prepend: site.baseurl }}">{{ post.title }}</a>

And it's the same for resources links (image, script, css, ...).

eg : <link rel="stylesheet" href="{{ "/css/main.css" | prepend: site.baseurl }}">

or <script src="{{ site.baseurl }}/js/script.js"></script>