Introduction

Welcome to our guide on how to change the URL of your Jekyll website. Our Basic instructions create a Jekyll website that has two folders in the URL (/docs/_site). This document describes how to change that URL.

Folder structure

You create a new Jekylly site with the new command. In this example, we used jekyll new docs. When you run the command, Jekyll creates a directory named docs with several documents inside. The _site folder is the one that contains the generated files that are served to the public. This is the directory that we will be changing the location for.

📁 (current working directory)
└──📁 docs
   ├── 404.html
   ├── Gemfile
   ├── Gemfile.lock
   ├── _config.yml
   ├── _posts
   ├── _site
   ├── about.markdown
   └── index.markdown

Docker commands

The commands I a script that call Docker. You can learn more about script. You can also learn more about the Docker [jekyll]jekyll.html).

Option 1 - Use separate source and destination repositories

I tried using two separate repositories, one for the source, and one for the destination where both directories are children of the same parent. This is probably the best approach.

baseurl: "/docs"
destination: path_to_destination/docs

Option 2 - Use sibling directories

I tried renaming the docs folder with the source to something else (eg docs-source). Then I change the configuration file to output the generated files to a directory that is a sibling of the source directory. This is less secure because if the client determines the name of the source directory, then they can browser the source.

📁 {username}.bitbucket.io
├──📁 data
└──📁 data-source

These are the changes to _config.yml:

baseurl: "/docs"
destination: ../docs

I tried moving the source to something else (eg docs-source). then I cd to the parent of the source directory and create a symlink to the generated folder. When I try to load the /docs folder in Bitbucket, I just see a page that displays the text docs/_site.

ln -s docs/_site

Option 4 - Move the source to the site root (ugly)

I tried moving the files in docs to the root of the website.

📁 {username}.bitbucket.io
├── .gitignore
├── README.md
├── 404.html
├── Gemfile
├── Gemfile.lock
├── _config.yml
├── _posts
├── docs
├── about.markdown
└── index.markdown

These are the changes to _config.yml:

baseurl: "/docs"
destination: docs

Option 5 - Move the source to the destination (fail)

I tried moving the files in docs/_site to the root of the website.

📁 
├── Gemfile
├── Gemfile.lock
├── Readme
├── _config.yml
└──📁 src
   ├── 404.html
   ├── _config.yml
   ├── _posts
   ├── docs
   ├── about.markdown
   └── index.markdown

This produced an error:

/usr/gem/gems/jekyll-4.2.2/lib/jekyll/site.rb:143:in 
`block in ensure_not_in_dest': 
Destination directory cannot be or contain the Source directory. 
(Jekyll::Errors::FatalException)

References