Munzir Alradi
ع
Munzir Alradi
Home About Services Work Blog Tutorials Contact Light Tunnel العربية
Tools

Building a Static Site with Hugo

How the first version of this site was built, themed and deployed — templates, content and continuous deployment.

2021 8 min read 58 photos
Line icon of a text page on a pale teal grid

HUGO

i build the website using hugo freamework, and here is about hugo

The Hugo logo

Hugo is a general-purpose website framework. Technically speaking, Hugo is a static site generator. Unlike systems that dynamically build a page with each visitor request, Hugo builds pages when you create or update your content.

what makes hugo beutiful is its ability to enable you to hand code your own website without worrying about setting up complicated runtimes, dependencies and databases.

Download hugo

you can download hugo by navigating to there page from here and then click github

The GitHub link circled in the Hugo site top bar

click latest release

in right bar you will find link for the latest release of hugo click that and it will take you to another page

The latest release marked in the right bar of the Hugo repository
  • here you will find all version of hugo depending on your operation system, and since i am using windows i will donload windows 64 version
Picking the Windows 64-bit zip out of the release downloads

unzip folder

now once you downloaded hugo its time to make it accessible from command line, so first unzip the files and add them to a reachable location

The opened archive holding hugo.exe, LICENSE and README.md

after downloading ffmpeg unzip the folder and save it in a reachable location such as c:/user/

add to path

now lets add it to our system path to make it recognize where its located to make it reachable from command line

  • open control panel then navigate to system
Opening System from the Control Panel
  • then click advance system setting
Clicking Advanced system settings
  • then from the top bar click advance and open environment variable
Opening Environment Variables from the Advanced tab
  • from the system variable open path, and add new then the location of hugo folder that you saved on
Clicking New on the system Path to add the hugo folder

hugo in command line

once everything is clear its time to test hugo in command line by typing

hugo version

hugo version printing the installed Hugo build

hugo new site

now its time to create our website, start by typing in command line

hugo new site ./

hugo new site stopping with an error and printing its usage

it give me error becouse there is files already exist in the folder, lets try with –force

hugo new site ./ –force

The same command with --force creates the new Hugo site

open atom to see the files that have been created

now all our tools already accessable from the comand line you can just type atom . to open atom text editor on this folder

Atom opened on the folder with the files hugo created

hugo server

Hugo provides its own webserver which builds and serves the site. While hugo server is high performance, it is a webserver with limited options. Many run it in production, but the standard behavior is for people to use it in development and use a more full featured server such as Nginx or Caddy.

‘hugo server’ will avoid writing the rendered and served content to disk, preferring to store it in memory.

by typing hugo server, hugo will show a local server in your computer it will be like a website in the internet, so it give you the ability to work on

your side offline and then just push the update using git.

hugo server building the site and serving it on localhost

Edit config

the first thing to do is to edit config file, change the base url to your page and add your name or website name to the title and copy write

Frames 01–02

    The default config.toml with the example base url and title
    config.toml edited with my own base url, title and copyright

Bootstrap

The Bootstrap logo

Bootstrap is a free front end framework that’s getting more and more popular among front end developers. It’s effortless to use and saves developers a lot of time from having to manually write syntaxes over and over again.

download boostrap

you can download the latest version of bootstrap from their website here

The Download button on the Bootstrap home page

extract files

once you download the latest version extract the files, you will find tow file js , css

The extracted archive holding just a css and a js folder

from the files now we need only the bootstrap.min.js and bootstrap.min.js copy the files and go to your website folder and create folder with the name static and the folder assists and paste them in

Frames 01–03

    Picking bootstrap.min.js out of the js folder
    Picking bootstrap.min.css out of the css folder
    Both files placed in static/assets, under css and js

index.html

this HTML file file is the main website page that is going to reflect on all other pages, so we have to work on it one time and then the rest of the documentation will be on mark down

index.html open in the layouts folder with the page skeleton

adding css

In order to user the bootstrap css you have to add this line to the top of the html file and it should be before the head tag

The bootstrap stylesheet link sitting in the head tag

adding js

And for the javascript file the way to load it has to be at the end before the closing body tag and after the footer tag

The src is attribute = the location of the bootstrap css file {{ .Site.baseUrl }} its shorct for hugo to load the website main url

The bootstrap script tag after the footer, before the closing body

adding navigation bar

From the bootstrap nav bar I copy all the code then I started to change the insite links and text Becouse now I understand what is happen in the code I can easly navigate between and start building it

The nav bar example and its code on the bootstrap docs page

adding container to navigation bar

In bootstrap there is tow type of continers 1- is the fluid that to make the content fit the page with all its length2- and the other one is the normal container which is by default is responsive so I used the regular one

<a href we added here a link to the site url so we go back to the home age And then we added a button In htm you have to specify some of the element like type And each element you can name attribute

Data-bs-toggle is java script built in variable used specially for bootstrap

Aria-control is accessabilty control but ists important if you want to build service website something we will not talk about today so will delete it

The toggler button with its data-bs and aria attributes

Span is general purpose

The same nav on the regular container, aria attributes removed

adding about me page

Staring with the static pages the final project and about me page , I added {{ .Site.BaseURL }} to navigate to the home page then added the extention for the page

About Me and Final Project nav links built on the base url

Then for the drop down I added all assignments for the up coming weeks topics so can build it once

The assignments dropdown code, a link for every week topic
The group assignments dropdown code, Week 01 to Week 20

adding old project page

Then Lastely I Added a Wep page to show my old Projects

The nav item pointing at the old projects page

And now this how my web page look like now

Frames 01–02

    The nav bar rendered, links stacked under my name
    The assignments dropdown open on the rendered page

partial

Next we took all the nav tag codes and paste it in the partial navigatin.html

The nav code moved into the partials navigation.html file

And then we linked that file to the index html by hugo short code {{ partial “navigation” . }}

And it remain same

index.html calling the navigation partial in its place

adding header

Next I add header just a welcome and small paragraph

Then added a container to make the text responsive and another class py-5 to make a space from the navigation bar
In bootstrap you can add classes and separate them with spaces

Class display-1 is to make the text bigger Class lead is to make the paragraph bigger to match the head lead

Frames 01–02

    The header with the container and py-5 classes
    The same header with display-1 and lead classes added

And its look like this

The rendered Welcome header sitting under the nav bar

add some pictures like cards

Next in the main I want to add some pictures like cards to make the wepsite look beeter and for easy navigation

The standard grid of bootstrap is 12 colom

Then added after the picture another div and give it a class “card-body” to insert more element 1- a card title (Assignment 01 ) 2- a small description ( this assignment for the principle and practices ) 3- a link to the page with a button “ view “ (View )

The card markup: thumbnail, card title, description and View button

And here how it looks now

The first card rendered under the welcome header

tow column’s

And here I made a tow columns and added a container class to the main tag to make it aligned with the other and then add another colom and changed the links and information for project management

mobile view and desktop view

Frames 01–02

    Two cards side by side in the desktop view
    The same two cards stacked in the mobile view

In footer I added a container class to make aligned and a make use of hugo functions and variable that ia set before like copyright, and the I added another function called now to make the year automatically updated now is a function in hugo that give you time in second since the begaining of unix, and format is going to take the input and convert it to a specific format and in go 2006 is going to convert it to year format

The footer code with .Site.Copyright and now.Format for the year

And here how its look like

.content

Then copied all the index.html to the default folder And replaced the main with hugo function {{ .Content }}

single.html in the default folder with main replaced by .Content

Short codes

Then added a new short code to orgnise the images in the markdown files

The image short code file in the shortcodes folder

And here how we add them in the mark down

Calling the image short code from a markdown page

image responsive

Also we can add the image like this to make it responsive

The image-responsive short code used in the same markdown file

To fit the device with

The viewport meta tag that fits the page to the device width

autoplay video short code

I added here a new short code for the video autoplay in order to make the video autopalys

The video-autoplay short code called from the markdown

youtube embeded video short code

The embed short code taking a youtube link

tiktok embeded video short code

The tiktok embed short code file holding the blockquote

instgram embeded video short code

The instagram embed short code file holding the blockquote

and here how it look like

The instagram and tiktok embeds rendered on the page

git add git commit -m and git push

I made some cleaning for the folders that I don’t want and the git status to see what is the files that have been modified

Then gitt add . To add all the files to committed

git commit -m ” ” . And then a massage for committing

git push , Then pushed the website

Frames 01–02

    git status listing the deleted and the modified files
    git add, git commit and git push finishing the upload

Show the website in git gitlab.

Now gitlab finished compiling the website and ready to be live

The pushed commit and the files shown in the gitlab repository

And now its live

The site live at the fabacademy address

Type to search