There are many themes for Jekyll, e.g. https://github.com/jekyll/jekyll/wiki/Themes.
What is the easiest way to switch to a new theme in an EXISTING Jekyll installation?
There are many themes for Jekyll, e.g. https://github.com/jekyll/jekyll/wiki/Themes.
What is the easiest way to switch to a new theme in an EXISTING Jekyll installation?
Jekyll v3.2 introduced gem-based themes (for future plans see here):
Installing a gem-based theme is simple:
gem "jekyll-theme-awesome"
bundle install
._config.yml
to activate the theme:theme: jekyll-theme-awesome
bundle exec jekyll serve
To switch themes, I believe something like this should work:
gem "jekyll-theme-new"
bundle install
_config.yml
to reference the new theme:theme: jekyll-theme-new
bundle exec jekyll serve
bundle show jekyll-theme-awesome
) and uninstall it withgem uninstall jekyll-theme-awesome
. To be on the safe side, make sure its folder was indeed deleted.Updating gem-based themes is easy:
Important note: at the time of writing, GitHub pages only supports a specific set of gem-based themes: Architect, Cayman, Dinky, Hacker, Leap day, Merlot, Midnight, Minima, Minimal, Modernist, Slate, Tactile, and Time machine. Of those, it seems only Minima is blog-oriented (e.g. it's the only one with built-in Disqus support). However, you should be able to use any theme if you are willing to run the Jekyll build process yourself.
Another alternative is GitLab pages (tutorial, sample site).
This is what I did to change the theme of an existing Jekyll installation. Adjust these instructions to suit your needs.
Pull the new theme
We create a new orphan branch
newtheme
and ensure it's empty.Then we pull the theme files into it by adding the theme as an upstream remote. In this example I pull John Otander's Pixyll theme's
master
branch.Build the theme and test it.
Merge your changes
Now we merge our posts, configuration, etc. You can use Git
checkout
to copy a file or folder from your old Jekyll site. Note that this will overwrite the theme's file if it exists.Alternatively, you can copy a file under a new name, for example to merge it manually.
If you accidently overwrote a theme file, you can restore it.
These are the files I had to copy, merge, adjust or remove:
_posts
folder._drafts
folder._config.yml
configuration file.Gemfile
gem file.CNAME
file (for GitHub pages).Rakefile
(if any).Commit your changes, and don't forget to test the theme again.
Replace the master branch
Finally we replace our existing
master
branch with the newnewtheme
branch. Assuming we're on thenewtheme
branch:Push the changes.
And clean up the local
newtheme
branch.That's it! You've successfully replaced your theme. If there's anything I missed, or you have anything to add, please leave a comment.
Updating the theme
If at any later point you want to update the theme to include the latest upstream changes, simply:
And fix any merge conflicts. Here I assume the
upstream
remote is still set to the theme's repository (you can check this withgit remote -v
).With GH-Pages
I tested this, but I did it with a project where I didn't have anything I wanted to save, and with fairly simple themes, so this might not work so well with the increased complexity.
For safety, create a new branch
git checkout -b newtheme
And then add the new theme as a remote
git remote add new-theme-upstream https://github.com:drjekyllthemes/jekyll-minimal-theme.git git pull new-theme-upstream HEAD
git status
, hopefully these conflicts should only be in style files that you want to overwrite. If there any files you want to keep you can either edit them with a text editor: git will have labelled the changes in the filePush to your origin
git push origin newtheme
git pull new-theme-upstream
If you are not using gh-pages or if you are building jekyll locally before pushing to github (I think)
You could keep your themes in git submodules, as separate folders and then symlink the key elements for jekyll. This won't work in gh-pages crude example
blog | +-- theme_1/ | +-- theme_2/ | | | +-- _layouts/ | +-- _layouts ln - theme_2/_layouts
That way when changing themes the themes don't collide.While you could migrate to an existing installation by forking a new theme and then manually copy and pasting over resources like CSS, JS, HTML in the
_includes
,_layouts
and other files you may need, this probably isn't a great idea as you end up having a mash up of old and new resources, which may not be of the same name, but in the scenario that they are (for example you didn't overwrite an old stylesheet that your post references), it will cause mixed up CSS styles that you'll have to debug and slowly fix.Since I'm assuming you have a Jekyll install with Git (if you don't you really should), you could create a branch called
new-theme
and switch to that branch from themaster
as the working branch. (A simpleton way of having something like this is to just copy your entire Jekyll install and paste it elsewhere asold-Jekyll-install
if you don't want to deal with Git branches (but really, you should. Here's a tutorial that helped me learn)_posts
and your customized changes._config.yml
by manually comparing them and moving over what is necessary.<br \>
tags for spacing and you don't want that in the new theme).master
(or push it to production)That being said all this is fairly manual and a pain, but at least you won't have to deal with conflicts in resources. The downside of doing this though is that your repository won't be synced with the theme repo. So you won't get upstream updates. I would still suggest that you fork the theme repo, port over your personal customizations for your Jekyll site, and then rename that repo for production. (this would of course no longer be using the 'existing' Jekyll installation)
The easiest way to switch theme in an existing or new jekyll installation is to use the following plugin: jekyll-remote-theme, which is available since November 2017.
Although it is currently in beta, it works fine and most importantly it is already white-listed on Github Pages, so there is no need to build locally, unless the requested theme includes unsupported Gems.
Therefore, in the case of a simple web site with pages and blog, you can host and edit your content directly on the Github infrastructure and switch your site theme by typing-in the address of the new remote theme. An extra benefit is that you can test your content with several existing themes before committing to one of them.
In addition to easier switching, the jekyll-remote-theme method should automatically bring-in a new version of the remote theme, as soon as you make a change and there is a new version by the maintainer of the theme. If the maintainer of the theme makes a radical change that you don't like then you are always a few keystrokes away from a new theme.
I have several jekyll installations and I am already employing it without intending to switch in the short term, since it is the most elegant and future proof solution, for the time being.
If your existing jekyll installation is pure (i.e., you have edited only pages, posts, configuration) then the switch is seamless. If your existing theme has special layouts (e.g., splash.html and the new one does not have it) then your pages that employ the respective layout become orphans (i.e., basic html with no special formatting). I have switched an existing installation that had been extensively edited, so I got several orphan pages, but I did not get any of the git merge conflicts that are possible with other methods discussed here.