There! I made it. My blog. Now, it took me an hour to set it all up. At least.
Then I had to spindle around it for another two days to have a theme and all sorted out.
I asked AI (did I hear ‘I hate droids!’ from the other room?) to help me a bit. Here is what I got with some redaction.
Steps to Create a Jekyll Blog Create a New Directory for Your Blog:
mkdir my-jekyll-blog
cd my-jekyll-blog
Initialize a New Jekyll Site: You can use the official Jekyll Docker image to generate a new site. Run the following command:
docker run -p 4000:4000 -v $(pwd):/srv/jekyll jekyll/jekyll new .
This command:
Maps port 4000 on your host to port 4000 in the container. Mounts the current directory to /srv/jekyll in the container, which is where Jekyll expects the site files. Runs the jekyll new . command inside the container to create a new Jekyll site in the current directory. Start the Jekyll Server: After the initial setup, you can start the Jekyll server by running:
docker run -p 4000:4000 -v $(pwd):/srv/jekyll -it jekyll/jekyll jekyll serve --watch
This command:
Keeps the container interactive (-it). Watches for changes in your site files and automatically rebuilds the site. Runs the jekyll serve command inside the container to start the server. Access Your Blog: Open a web browser and navigate to http://localhost:4000. You should see the default Jekyll welcome page.
Edit Your Blog Content: You can now edit the files in the current directory. The changes will be automatically picked up by the Jekyll server, and you can view them by refreshing the browser.
Build the Site for Production: When you are ready to deploy your site, you can build the static site by running:
docker run -v $(pwd):/srv/jekyll -it jekyll/jekyll jekyll build
This command will generate the static files in the _site directory.
Deploy Your Site: You can deploy the _site directory to any static hosting service, such as GitHub Pages, Netlify, Vercel, or any other hosting platform that supports static files. Or in case you are self-hosting jekyll and want to publish directly after pushing to remote you can try this.
In your project.git folder on remote server create a file post-receive (there suppose to be post-receive.sample but I was missing it)
#!/bin/bash
#for debugging
#set -ex
# the work tree, where the checkout/deploy should happen
TARGET="/home/webuser/deploy-dir"
# the location of the .git directory
GIT_DIR="/home/webuser/project.git"
BRANCH="master"
while read oldrev newrev ref
do
# only checking out the master (or whatever branch you would like to deploy)
if [ "$ref" = "refs/heads/$BRANCH" ];
then
echo "Ref $ref received. Deploying ${BRANCH} branch on server..."
git --work-tree="${TARGET}" --git-dir="${GIT_DIR}" checkout -f ${BRANCH}
else
echo "Ref $ref received. Doing nothing: only the ${BRANCH} branch may be deployed on this server."
fi
donesrc: https://gist.github.com/nonbeing/f3441c96d8577a734fa240039b7113db#file-post-receive
Remember to update paths! Now push something to the origin. You should see line staring with remote: Ref... in the output.
Let’s try updating the script to do an actual deployment. I want to build a static content and sync a web folder on the same machine.
Let’s modify the snippet a bit:
(...)
echo "Ref $ref received. Deploying ${BRANCH} branch on server..."
git --work-tree="${TARGET}" --git-dir="${GIT_DIR}" checkout -f ${BRANCH}
docker run --rm -v /home/git/blog.git.deploy:/srv/jekyll -eJEKYLL_UID=$(id -u) -eJEKYLL_GID=$(id -g) jekyll/jekyll jekyll build
cp -a ${TARGET}/_site/* /var/www/blog/
(...)
Not to self: sync the content a bit better. Perhaps use rsync or something.
To work with docker you might want to add git user to the docker group so it can use docker run …
Also note we’re changing the UID of the jekyll user so it can work with .jekyll-cache folder in the ${TARGET}
Then one more thing to remember: chown git:www-data -R /var/www/blog
Ok. All set. How to post something?
You’ll find this post in your _posts directory. Go ahead and edit it and re-build the site to see your changes. You can rebuild the site in many different ways, but the most common way is to run jekyll serve, which launches a web server and auto-regenerates your site when a file is updated.
Jekyll requires blog post files to be named according to the following format:
YEAR-MONTH-DAY-title.MARKUP
Where YEAR is a four-digit number, MONTH and DAY are both two-digit numbers, and MARKUP is the file extension representing the format used in the file. After that, include the necessary front matter. Take a look at the source for this post to get an idea about how it works.
Check out the Jekyll docs for more info on how to get the most out of Jekyll. File all bugs/feature requests at Jekyll’s GitHub repo. If you have questions, you can ask them on Jekyll Talk.
