So my web development has taken an interesting path, not that different to some others.
I start back in 1907 doing hand coded html, then moved to hand coded php, then dreamweaver, then CMS.
Eventually making it to Wordpress then back to PHP, and now to Jekyll
My path to adopting Jekyll has been a long one. Every now and then I get a bee in my bonnet about how bloated Wordpress is for many of my web tasks.
It’s great for what it was designed for! Helen uses Wordpress in all her websites, and it is a perfect tool for her.
She’s not technical, and just wants to publish articles that she types in an online editor; perfect for Wordpress!
I am technical! and I don’t need all the things that come with Wordpress, in fact what I really want is the fastest loading website possible.
In comes Jekyll (plus bootstrap, jquery, and popper.js ).
So I faffed about on my Macbook and started converting paulwillard.nz to a Jekyll site.
after a few days I realised I’d lost track of what I had installed, and where I had got to with dev.
So I thought I’d start from scratch again, and this time document the steps to get a really simple boostrap site up and running.
Before I continue I’ve got to give credit to a site that has really helped my journey.
I have no idea who this Michael Rose character is, but I reckon he’s taken the same web development path as me, going by his posts!
So here we go:
I start with a dead clean fresh install of Debian Stretch
Installing NodeJS and ruby
Let’s install the deb source key:
curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | sudo apt-key add -
and add to our packages sources.list:
Now let’s install some packages:
Environment setup
Let’s install all our gems to our home directory:
Install Jekyll
Let’s install Jekyll:
gem install jekyll bundler
Create a Jekyll site
Let’s start with a blank site:
jekyll new mysite --blank
and add some JS packages from node:
_config.yml Setup
Let’s do a basic _config.yml
This will tell Jekyll to search a few different paths for sass
and tell Jekyll to include node_modules by setting exclude to 0 (by default Jekyll excludes node_modules)
default.html Layout
Lets create a pretty simple starter default layout:
main.scss ( CSS )
In our _layout/default.html we’ve told the browser to load css from assets/css/main.css, so we better create that:
first create the directory mkdir -p assets/css
.
Now let’s put some text in the file:
Note: the file has the extension scss, Jekyll will preprocess the CSS and make a .css file
you must include the first two lines “—”, this tells Jekyll to preprocess the file
index.html ( Your new webpage )
Let’s create an index.html file.
Note: include the frontmatter, the first 4 lines
This tells Jekyll the layout to use (default.html) and gives the page a title (used in the above layout).
Jekyll build and server
we’re done! Let’s build the site, then serve it using the inbuilt Jekyll server:
jekyll build && jekyll serve --host=0.0.0.0
Advanced CSS
Using inline CSS
I like to “inline” my CSS, rather than include a css file.
It’s pretty easy to tell Jekyll to inline the CSS.
Let’s make an _includes directory mkdir _includes
.
Now let’s populate a css file in the includes directory:
Note: the file extension is .css
this file has no frontmatter
We don’t need the old file anymore so let’s remove it rm assets/css/main.scss
.
finally, in your _layouts/default.html replace the css line with:
We’re done! Let’s build and serve:
jekyll build && jekyll serve --host=0.0.0.0
Compressing (Minify ) CSS
If you’re like me and like to have the fastest possible website, you’re going to want to minify your css
That’s super easy too! Just add a small config to your _config.yml :
We’re done! Let’s build and serve:
jekyll build && jekyll serve --host=0.0.0.0
Open your browser and check out the source code the Jekyll produces!
Final notes
– host ?
You may be wondering why I use jekyll serve --host=0.0.0.0
?
Why do I use that –host bit?
Well by default Jekyll serves up on localhost, and my development server is remote (i.e. I can’t use localhost).
I could port forward localhost 4000 to the development server (I mean, I’m probably on it anyway doing development).
ssh -L 4000:localhost:4000 development.server.nz
Including node_modules directory ?
No, I don’t actually include the entire node_modules directory. I have a build script that shuffles files around into the right place first.
I put this file in the root of mysite then excute using ./ctl.sh -b && ./ctl.sh -s
5 Comments