Introduction
In addition to Linkedin, I was looking for somewhere to host a site for my academic/working experience with a bit more details. It turns out that using Hugo with Academic theme/framework fits my needs, and it looks pretty nice and clean. So, here is how I setup it up.
What is Hugo?
Hugo is a static site generator written in Go. Hugo is developed by Bjørn Erik Pedersen, Steve Francia, and other contributors. Hugo is an open source project licensed under the Apache License 2.0.
Hugo takes data files, i18n bundles, configuration, templates for layouts, static files, and content written in Markdown and renders a static website. Some notable features are multilingual support, image processing, custom output formats, and shortcodes. Nested sections allow for different types of content to be separated. E.g. for a website containing a blog and a podcast.
– from Wikipedia - Hugo
What is Academic Framework?
The Academic framework enables you to easily create a beautifully simple website using the Hugo static site generator in under 10 minutes. You can see the demo here: View the Demo!
Academic Kickstart provides a minimal template to kickstart your new website by following the simple steps.
Reference Links
- Hugo - https://gohugo.io/
- Hugo Doumentation - https://gohugo.io/documentation/
- Hugo Themes - https://themes.gohugo.io/
- Academic - https://sourcethemes.com/academic/
- Academic Kickstart - https://github.com/sourcethemes/academic-kickstart/
- Academic Documentation - https://sourcethemes.com/academic/docs/
Setup Academic Framework using Hugo
My Environment
- MacBook Pro (13”, 2017) - macOS High Sierra 10.13.6
- Git - 2.17.1 (Apple Git-112)
- Hugo - v0.49.2
- Homebrew - 1.7.7
Homebrew Installation: https://docs.brew.sh/Installation
Homebrew GitHub: https://github.com/Homebrew/brew
Hugo
Download and install Hugo via Homebrew (for macOS users):
1 | $ brew install hugo |
You may also download the appropriate version for your platform from Hugo Releases.
Homebrew is the simplest method and will require the least amount of work to maintain. The drawbacks aren’t severe. The default package will be for the most recent release, so it will not have bug fixes until the next release (i.e., unless you install it with the –HEAD option). Hugo brew releases may lag a few days behind because it has to be coordinated with another team. Nevertheless, brew is the recommended installation method if you want to work from a stable, widely used source. Brew works well and is easy to update.
Academic Kickstart
Fork the Academic Kickstart repository to your GitHub.
Clone your fork:
1
2cd <MY_WORKSPACE>
git clone https://github.com/josephchen3/academic-kickstart.git <MY_HUGO_SITE>Setup upstream for syncing a fork (sync a fork of a repository to keep it up-to-date with the upstream repository):
a. List the current configured remote repository for your fork.1
2
3
4
5cd <MY_HUGO_SITE>
git remote -v
origin https://github.com/josephchen3/academic-kickstart.git (fetch)
origin https://github.com/josephchen3/academic-kickstart.git (push)b. Specify a new remote upstream repository that will be synced with the fork.
1
$ git remote add upstream https://github.com/sourcethemes/academic-kickstart.git
c. Verify the new upstream repository you’ve specified for your fork.
1
2
3
4
5
6git remote -v
origin https://github.com/josephchen3/academic-kickstart.git (fetch)
origin https://github.com/josephchen3/academic-kickstart.git (push)
upstream https://github.com/sourcethemes/academic-kickstart.git (fetch)
upstream https://github.com/sourcethemes/academic-kickstart.git (push)d. Fetch the branches and their respective commits from the upstream repository. Commits to master will be stored in a local branch,
upstream/master
. Check out your fork’s local master branch. Merge the changes fromupstream/master
into your local master branch. This brings your fork’s master branch into sync with the upstream repository, without losing your local changes. If your local branch didn’t have any unique commits, Git will instead perform a “fast-forward“.1
2
3git fetch upstream
git checkout master
git merge -S upstream/masterMore details:
https://help.github.com/articles/configuring-a-remote-for-a-fork/
https://help.github.com/articles/syncing-a-fork/Initialize the theme:
1
git submodule update --init --recursive
Update academic/theme to the latest changes:
1
git submodule update --remote --merge themes/academic/
In case if you want to check out a certain version of the theme, you can do:
1
2
3cd <YOUR_HUGO_SITE>/themes/academic/
git log --no-walk --pretty=oneline --tags --abbrev-commit --decorate ## show all tags
git checkout tags/xxx ## where xxx is the version numberHere’s my script to check and update academic theme.
[Updated on 2019/02/27]: Here’s the official update script.
Demo content
For inspiration, refer to the Markdown content which powers the Demo.
If you wish to initialize your site with the demo content, copy the contents of the themes/academic/exampleSite/
folder to your website root folder, overwriting existing files if necessary. The exampleSite folder contains an example config file and content to help you get started. The following command can be used to accomplish this:
1 | rsync -vau ./themes/academic/exampleSite/* ./ |
Preview Your Site Locally
1 | hugo server # alias: hugo serve |
Configure Hugo
You can find my full config settings at config.toml, menus.toml, and params.toml.
For more information on config files, please see https://gohugo.io/getting-started/configuration/
Hosting and Deployment on GitHub
Deployment on GitHub Pages Directly
Check in or stash all the changes in your local git worktree.
Remove
public/
from.gitignore
file.Setup Git sub module.
1
2
3
4
5rm -irf public
git submodule add -f -b master https://github.com/josephchen3/josephchen3.github.io.git public
git add .
git commit -m "Add submodule"
git push -u origin masterIn case if you use
git
instead ofhttps
for adding sub module, change to following:Line #2 1
$ git submodule add -f -b master git@github.com:<USERNAME>/<USERNAME>.github.io.git public
Generate static files and check in to the GitHub Pages repo.
1
2
3
4
5
6hugo
cd public
git add .
git commit -m "YOUR COMMIT MESSAGE"
git push origin master
cd ..The previous step (Step 4) can be done by the following script.
deploy.sh 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# https://gohugo.io/hosting-and-deployment/hosting-on-github/
echo -e "\033[0;32mDeploying updates to GitHub...\033[0m"
# Build the project.
hugo # if using a theme, replace with `hugo -t <YOURTHEME>`
# Go To Public folder
cd public
# Add changes to git.
git add .
# Commit changes.
# msg="rebuilding site `date`"
msg=":rocket: Hugo Academic site update on `date`"
if [ $# -eq 1 ]
then msg="$1"
fi
git commit -m "$msg"
# Push source and build repos.
git push origin master
# Come Back up to the Project Root
cd ..
Now, you should be able to see your Hugo site on your GitHub Pages, which in my case is https://josephchen3.github.io/. Yay!!
References:
Host on GitHub - https://gohugo.io/hosting-and-deployment/hosting-on-github/
Deployment on GitHub Pages - https://sourcethemes.com/academic/docs/deployment/#github-pages
Deployment on html(gh-pages) Branch
This method is specifically for the case where the sub URL of the site is used. In this case, we need an additional branch from Hugo academic-kickstart repo, called html branch.
Check in or stash all the changes in your local git worktree.
Create an orphan branch for generated static pages.
1
2
3
4
5
6
7git checkout --orphan html
git rm -rf --cached $(git ls-files)
git reset --hard && rm -irf *
echo .DS_Store >> .gitignore
git add .
git commit -S -m "Initializing html branch. Add gitignore file."
git push origin htmlRemove
public/
from .gitignore file.Setup Git subtree for
public/
folder.1
2
3
4
5git checkout master
git submodule update --init --recursive
rm -irf public
git subtree add --prefix=public origin html --squash
git subtree pull --prefix=public origin html --squashNote that here I am using
origin
, because my target subtree comes from the same repository but different branch.Generate static files and check in to the git repo (master branch).
1
2
3
4hugo
git add .
git commit -S -m 'Generate static files under public/ folder.'
git push origin masterUpdate the change to html branch.
1
git subtree push --prefix=public origin html --squash
Reference:
Git subtrees: A tutorial - https://medium.com/@v/git-subtrees-a-tutorial-6ff568381844
Add Submodule to GitHub Pages (for html branch approach)
Setup git submodule in your GitHub page working tree. In my case, it’s like following:
1 | cd jocodoma.github.io/ |
To update git-submodule, do:
1 | cd jocodoma.github.io/ |
Finally, make sure you commit the code and push back to remote repo. Now, you should be able to see your Hugo site on your GitHub Pages, which in this case is https://josephchen3.github.io/cv/. Yay!!
References
https://sourcethemes.com/academic/docs/install/
https://sourcethemes.com/academic/docs/get-started/
https://sourcethemes.com/academic/docs/deployment/
https://sourcethemes.com/academic/docs/