2022 Week 38 How to create a static website with Jekyll and deploy it on GitHubPages
20 Sep 2022 - Aaron
GitHub
Create a GitHub-accountCreate a repository on GitHub
(It has to be public if you use GitHub Free, note that your code will be visible to everyone!)
Local Repository
Clone the repository to a local directory:ssh
$ git clone --recursive SSH_URL
$ git -c http.sslVerify=false clone --recursive HTTPS_URL
Directories
Create two directories: docs and localDev.$ mkdir docs
$ mkdir localDev
localDev will contain our Jekyll project.
Create Jekyll Project
Move to the localDev-directory:$ cd localDev
Create a new Jekyll-project at localDev-directory:
$ jekyll new --skip-bundle .Edit Gemfile
Open the Gemfile that Jekyll created and comment out (#) the line which starts with gem "jekyll"Add the github-pages gem by editing the line starting with # gem "github-pages".
Change this line (# gem "github-pages") to:
gem "github-pages", "~> GITHUB-PAGES-VERSION", group: :jekyll_plugins
You can find the actual version of GitHub-pages here.
Now save and close the Gemfile.
Install bundle
Now still being at the localDev-directory, install the bundle:$ bundle installLearn Jekyll
Follow this guide to learn Jekyll. Make sure that all files and directories you create are in the localDev-directory.Note that building locally will not work according to commenting out gem "Jekyll" at the Gemfile. (Atm I didn't check if this is right)
If it is, you have to not comment it out and do bundle install again. Afterwards you can test locally with jekyll serve.
Build Project
After creating all necessary files and dirs, you can make a production build:Note that all files at _site will be cleared!
$ JEKYLL_ENV=production bundle exec jekyll build
Clear your docs-directory:
$ rm -r ../docs/*
$ cp -r _site/* ../docs
Publish Website
Now publish your repository on GitHub Pages.Select your branch and as folder /docs and hit Save.
Now you have to wait, this can take up to 10 minutes.
On the top of the page a box will appear with the url of your website.
Happy developing!
Sources
- https://docs.github.com/en/pages/setting-up-a-github-pages-site-with-jekyll/creating-a-github-pages-site-with-jekyll
- https://docs.github.com/en/pages/quickstart
- https://docs.github.com/en/get-started/quickstart/set-up-git
- https://docs.github.com/en/pages/setting-up-a-github-pages-site-with-jekyll/testing-your-github-pages-site-locally-with-jekyll
- https://jekyllrb.com/docs/structure/
- https://jekyllrb.com/docs/step-by-step/01-setup/
- https://jekyllrb.com/docs/step-by-step/10-deployment/