This content originally appeared on DEV Community and was authored by rahul d
Setup a blog with Hugo and Github Pages
It was long my desire to write a blog with stuff that interests me.
Lately i was studying Golang and i came across Hugo which is a really nice and fast site generation utility.
using Hugo and Github Pages in order to host it. Why?
- it’s free
- it’s Github
- it’s easy and fast
Steps
The following steps are needed for the initial setup and creation of the blog:
- Github repository for source code of the blog
- Github Pages repository for the generated site
- Setup Hugo
- Create blog
- Publish blog to Github Pages
1. Github repository for source code of the blog
Follow the instruction on Github Pages to create a repository with your Github username. Clone it to your local drive.
3. Setup Hugo
Download Hugo to your local drive. Unpack it to a folder and set the path in your OS to the executable. Almost all OS are supported!!!
4. Create blog
- Create a folder for your blog source code and
cd
into it. - Execute
hugo new site
. - Execute
git init
- Add as remote repository the repository created in Step 1. (
git remote add origin https://github.com/{username}/{repository}.git
) - Add
.gitignore
file to exclude the pathpublic/
, which is the default directory of the generated static files - Execute
git add
. - Execute
git commit -m "initial commit"
- Execute
git push -u origin master
5. Publish blog to Github Pages
When we are ready to deploy our blog we do the following:
- Execute
hugo -d {path}
, where path is the cloned repository path from step 2 -
cd
into the above path - Execute
git add .
- Execute
git commit -m "initial commit"
- Execute
git push origin master
After this we can enjoy our newly created blog underhttp://{username}.github.io
where username should be replaced with your Github’s username.
Code Model
class Tag(models.Model):
name = models.CharField(max_length=100, unique=True)
slug = models.SlugField(max_length=50, unique=True, blank=True)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
def save(self, *args, **kwargs):
if not self.slug:
self.slug = slugify(self.name)
super().save(*args, **kwargs)
def __str__(self):
return self.name
This content originally appeared on DEV Community and was authored by rahul d