Move an old HTML site to Jekyll in an afternoon
Most of the client sites I inherit started life as a folder of HTML files. They work fine until someone asks to change the phone number in the footer, and you find out it lives in 23 files.
Jekyll fixes that without changing what the site is. The output is still plain HTML, CSS and JavaScript, so it can be hosted wherever it's hosted now, but the shared parts live in one place.
Here's the order I use to move a site over in an afternoon. It assumes Ruby is installed and you're comfortable in a terminal.
1. Take stock before you touch anything
Put the current site in Git, or at least zip a copy. Then make three quick lists:
- every page and its URL, because those URLs need to keep working
- the parts repeated on every page, usually the
<head>, header, nav and footer - anything repeated inside pages, like blog posts, team members or services
The last list tells you where collections will help later.
2. Set up an empty Jekyll project
In a new folder, add a Gemfile:
source "https://rubygems.org"
gem "jekyll", "~> 4.3"
group :jekyll_plugins do
gem "jekyll-seo-tag"
gem "jekyll-sitemap"
end
and a _config.yml:
title: Example Studio
description: Handmade furniture in Austin
url: "https://example.com"
plugins:
- jekyll-seo-tag
- jekyll-sitemap
Run bundle install, then bundle exec jekyll serve. You should get an empty site at http://localhost:4000.
3. Copy the old site in as it is
Copy all the HTML, CSS, JavaScript and images into the project, keeping the folder structure. Jekyll copies any file without front matter straight into _site, so the old site should already load at localhost:4000.
This is your safety net. From here on you change one thing at a time and can see straight away if it breaks.
One catch: Jekyll skips folders whose names start with an underscore. If the old site has something like _assets/, rename it or list it under include: in _config.yml.
4. Make one layout
Open the most typical page and split it in two: the page's own content, and everything around it. Everything around it becomes _layouts/default.html:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
{% seo %}
<link rel="stylesheet" href="{{ '/css/styles.css' | relative_url }}">
</head>
<body>
{% include header.html %}
<main>
{{ content }}
</main>
{% include footer.html %}
</body>
</html>
The {% seo %} tag comes from jekyll-seo-tag. It writes the title, description and Open Graph tags from your config and front matter, so you can delete the hand-written ones.
5. Pull out the includes
Move the header and nav markup into _includes/header.html and the footer into _includes/footer.html. The phone number now lives in one file.
If the nav is a list of links, move the links into _data/navigation.yml:
- title: Home
url: /
- title: About
url: /about.html
- title: Contact
url: /contact.html
and loop over them in the include. That also lets you mark the current page:
<nav>
{% for item in site.data.navigation %}
<a href="{{ item.url | relative_url }}" {% if page.url == item.url %}aria-current="page"{% endif %}>
{{ item.title }}
</a>
{% endfor %}
</nav>
6. Convert each page
On every page, delete the repeated head, header and footer, and add front matter at the top:
---
layout: default
title: "About us"
description: "Who we are and how we work"
permalink: /about.html
---
The permalink line keeps the old URL exactly as it was, so links from other sites and search results keep working. If you'd rather switch to clean URLs like /about/, do it later, on purpose, with redirects.
Do the pages one at a time and reload after each. When a page looks wrong, it usually still has its own copy of the nav, or a stylesheet link the layout already adds.
7. Fix asset paths
Relative links like ../css/styles.css break as soon as pages move around. Change them to root paths through the relative_url filter:
<img src="{{ '/images/logo.png' | relative_url }}" alt="Example Studio">
That keeps working if the site is ever served from a subfolder with baseurl set, like a GitHub Pages project site.
8. Turn repeated content into a collection (optional)
If your third list from step 1 had something in it, like six near-identical service cards, move each one into its own file in a folder such as _services/, and register it in _config.yml:
collections:
services:
output: false
Then loop over site.services on the page. Adding a seventh service becomes a new file instead of copied markup. You don't have to do this on day one. The site works without it.
9. Check and ship
Stop the server, run bundle exec jekyll build, and click through every page. Open the browser console and look for 404s on CSS, JavaScript or images. Check that /sitemap.xml exists and that every URL on your first list still loads.
Then deploy the way you already do, because _site is plain static files. On GitHub Pages with Jekyll 4, build with GitHub Actions. Netlify and Cloudflare Pages can run jekyll build for you.
Where a tool helps
Steps 4 to 7 are the slow part, especially when the "shared" header is a little different on every page because people edited them by hand over the years. I got tired of doing that part for client sites, so I made a tool for it, HTMLtoJekyll.
Disclosure: it's my product, so read this section with that in mind.
You upload a ZIP of the old site or paste a public URL. It compares the pages to find the shared header, footer and nav, moves them into _includes and _layouts, writes the front matter, groups repeating pages into collections, and rewrites asset paths with relative_url. Every export is test built with jekyll build, and you download a normal Jekyll project you run with bundle exec jekyll serve.
The first conversion is free and doesn't need a card. It's a conversion, not a redesign. A messy template comes back as a tidier version of the same template, and you still own the project afterward, so the steps above are worth knowing either way. For a five-page site, doing it by hand is about as fast.
Wrapping up
The point of the move isn't Jekyll for its own sake. It's that the next footer change takes one edit, the site still deploys as static files, and nothing about the URLs changed for visitors.
If you hit something odd along the way, the Jekyll forum at talk.jekyllrb.com is friendly, and I'm happy to answer questions in the comments.
Comments
No comments yet. Start the discussion.