Installing Jekyll Without Root

Installing Jekyll without root

I didn't find the answer for a while. on the #jekyll IRC a user pointed me at the Arch wiki and I discovered that the thing is to force the install as a single user:

gem install jekyll --user-install

Use Jekyll without Jekyll server / without root directory

This answer is still valid. But I must admit that it's not really portable to tweak baseurl. You cannot always guess the correct path.

Let's try to make it run on the file system with relatives urls like ./path/to.

What do we need to tweak

Examining the index page, sitting at file:///path/to/_site/index.html, we can identify some potential problems :

  • styles are not working
  • posts are linked like file:///jekyll/update/2016/08/05/welcome-to-jekyll.html following the /:categories/:year/:month/:day/:title.html permalink pattern. And we know the folder hierachy is a nightmare when using relative links.
  • pages. The only one is about with an already defined permalink pointing to /about/ which will not work from file system, because it resolves to file:///about/

In order to avoid folder hierachy hell, we will make every post and page to be created at the root.

Redefining permalinks

In _config.yml we add :

defaults:
-
scope:
type: "posts"
values:
permalink: :slug:output_ext

-
scope:
type: "pages"
values:
permalink: :basename:output_ext

Now any post is generated at the root.

But this about page is still generated in an about folder. Why ?

Because front matter permalink overrides default configuration. We remove permalink: /about/ from about.md front matter and now our page is generated at the root /path/to/_site/about.html. Good !

Rewriting links

We're now making our links relatives to root using the ./ expression.

_includes/head.html

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

becomes

<link rel="stylesheet" href="{{ "./main.css" }}">

_includes/header.html

<a class="site-title" href="{{ site.baseurl }}/">{{ site.title }}</a>

becomes

<a class="site-title" href="./index.html">{{ site.title }}</a>

And

<a class="page-link" href="{{ my_page.url | prepend: site.baseurl }}">{{ my_page.title }}</a>

becomes

<a class="page-link" href="./{{ my_page.url }}">{{ my_page.title }}</a>

index.html

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

becomes

<a class="post-link" href="./{{ post.url }}">{{ post.title }}</a>

And you can now navigate.

Remember to keep everything a the root and it will be ok.

How to Install Jekyll in linux?

Ruby 1.9.x is to old for Jekyll. You need at least ruby 2.0.x.

I advice you to go with rbenv in order to manage your ruby versions.

Jekyll on Mac no Admin access (No homebrew, Ruby, Rvm, cURL)

If you have unsufficient rights, and/or you are on a shared computer, I would choose to use Cloud9 to run admin on Linux. I gave this answer earlier: https://stackoverflow.com/a/46144384/2397550



Related Topics



Leave a reply



Submit