(Photo by Christin Hume on Unsplash)
When I was in high school, I was the director of the school magazine club, that makes me be a little bit familiar with publishing. I started to use Hugo since 2017, gradually build the corresponding workflow and tools, and have some notes here. Regardless of entry or application, I hope you can get some clips that can improve your work efficiency :)
Contents
Advantages and Disadvantages
Several advantages of adopting Hugo at that time and continuing to use Hugo as my blog system:
- Open source - https://github.com/gohugoio/hugo
- Open format
- From organizing notes, writing drafts, to Hugo content output, and even organizing slides, all in the common open format - Markdown - can be used throughout, saving me a lot of data conversion time.
- The Hugo content file format is plain text (Front Matter + Markdown), there is a way out if I need to use another blog system in the future.
- The Hugo content file format is plain text, with version control or file synchronization mechanism, I can choose any editor across multiple platforms.
- The original content can be put into version control, while achieving remote backup.
- After observing for a long time, Hugo has a large number of users and shows an increasing trend. It will not become an orphan too soon (I don’t need to switch again too soon).
- The output are static files, and there is no need to maintain a host of a specific specification. By using GitHub Pages or Amazon S3, I can just upload, set the DNS, and done.
- Fast (time saving in various senses) (for example, it only takes 1077 ms to build 343 pages on Macbook Air (M1, 2020), and the average time spending per page is 3.14 ms).
- There is a command line tool (CLI) to facilitate workflow automation.
- Few plugins/expansion kits (I think it’s an advantage, not sacrificing “fastness”).
Disadvantages:
- Companions who participate in collaboration together have a learning curve. e.g. learn Markdown, shortcode code style, git and workflow .
Editor
Visual Studio Code (VSCode)
Hugo has some extensions contributed by the community to various editors.
I mainly use Visual Studio Code on macOS to edit Hugo content files. I did not install Hugo control related packages (I prefer using CLI), but installed some Hugo and Markdown syntax plugins:
- Hugo Language and Syntax Support
- Hugo Shortcode Syntax Highlighting
- Hugo Snippets
- Markdown All in One
- Mermaid Markdown Syntax Highlighting
- Markdown Preview Mermaid Support
- Marp for VS Code - A package for Marp Markdown presentation(Example)
- Path Intellisense - Save time when choosing image file path
Regarding the input of the image file path and preview, I am still looking for other efficient methods. At present, I try to fix the file name naming rule as much as possible, and then copy and paste a large number of ![](/img/2021/2021-06-19-hugo-workflow/filename_here.png)
, and then go to the Hugo local preview (browser) to view it, and hope to have the opportunity to preview it directly in the editor in the future.
Joplin
When it is inconvenient to turn on the computer in some occasions, or when it is too late to turn on the computer, I will use the cross-platform Joplin to edit Markdown, or make a quick note clip first. I will prepare some articles to discuss Joplin in the future.
Joplin is also an open source software, which can achieve my cross-platform needs, so I can synchronize notes across Android phone, iPhone, iPad, Macbook Pro/Air, Windows, and continue the next stage of editing and organizing.
Byword
Before I started using Joplin, I used Byword for a short while. The purpose is the same. It needs to be cross-platform and cross-device, to quickly enter the state of taking notes, and then there is no need to worry about the problem of synchronizing notes across devices. And Byword cannot work on Android devices, which is sometimes a bit troublesome, because my main device is an Android phone when traveling abroad.
Obsidian
More and more friends around me recommended Obsidian, and I couldn’t stop playing it when I started. Although it is not open source software, my bottom line is open data format. I am looking forward to using Obsidian’s ability to immediately preview after inserting pictures to edit Hugo content files, but at least my recipe notes have moved here. It cannot be my main editor force at the moment, because it can only be operated on a computer, and there is no public version on mobile devices. Keep watching on it.
Hugo
Configuration config.toml
The Hugo configuration information can be found at Hugo official document, and Hugo official Discourse discussion area.
At first, I don’t know which file to set it, but after reading a few more articles, you can lock several directory locations, and you can set it up and see each one. It will be a good way to get started.
Because I wanted to practice my English writing, I greedily set Hugo in the direction of multilingualism from the beginning. It’s a good topic of research about the structure, correspondence, translation, segment update and maintenance of the multi-language system.
|
|
Content types
I am using two types of content: post
and note
. The former records opinions in chronological order, while the latter attempts to connect to each other to form a web-like structure, perhaps in the direction of Digital Garden (from cleaning up spider webs to planting flowers and grass?!).
I also created individual archetypes files and individual create new shell scripts corresponding to the two content formats of post
and note
.
The following is a shell example of creating new post: (If you do not have the requirement to separate the image files by directories according to each article, you can ignore this example and just using hugo new
)
|
|
lastmod (last modified)
I use blog as an extension of the note-taking system, so I often have an idea, or the relevance between thoughts, etc., and I will go back and make some changes or adjustments, so I hope to show the date when the article was created and my last modified. After refered to couple articles and implement the lastmod function in my Hugo setup.
- Docs: Configure Front Matter: Configure Dates
- Last Modified Date in Hugo, by Mert Bakır
- Hugo Blog 進化筆記 - 八墨寫信, by Will Liu
- Docs: Function: .Format
Custom shell aliases and functions
Refered from Christian Mohn’s workflow, and did some modification to fit into my edition.
If you are interested in, I will update it at .aliases.local.example
in my dotfiles project. (Currently my dotfiles project is in chaos due to Apple Silicon. Please take care XDD.)
|
|
When editing articles, sometimes a lot of screenshots are required (for example, AWS re:Invent Keynote Notes at the end of each year), after each screenshot, I also need to manually move the files to the Hugo project’s static/img/year/the-article-exclusive-directory
, plus sometimes there are steps such as conversion and compression optimization. It’s really tiring. Therefore, I choosed to turn off Dropbox Screenshots, and make ~/Dropbox/Screenshots
directory path as the default folder of screenshots. Then made a simple tool script. When I was editing an article, I changed the default directory for storing screenshots to the corresponding path where my Hugo static files of the article are stored, switch back to the default directory after my editing.
You can replace the info/success used in the script with echo.
|
|
Images
I use ImageOptim to speed up image loading.
The source of the pictures is mainly Unsplash or a large number of photos accumulated during my trips (I took average one or two thousand photos per day when I go out in the early days, but in recent years it has been more convergent) (well, mostly food and aviation pictures, haha). Each article will be specially processed for ogimage and twitter card, which is done in Front Matter. You may ask that what do you do when you feel lazy or have no time to find a picture? I would say… as a responsible engineer, I will leave a default value wherever I pass by :p
Favicon
Reference to Add Favicon to Hugo-Based Website | Igor Baiborodine.
- Create a new file:
layouts/partials/favicon.html
- Modify
layouts/partials/head.html
to include this new created favicon partials.
- Modify
- Step 1: Add Favicon Using favicon.io
- It’s a easy way to have a base favicon package.
- Then go to next step to have wider manifest coverage.
- Step 2: Add Favicon Using realfavicongenerator.net
- Upload
android-chrome-512x512.png
(generated in Step 1) to generate a full package. - I choose to do the compression at the tab named
Compression
inFavicon Generator Options
section. - Downlod the package. Unzip and place them all at the
static/
folder of the hugo site. - Copy and paste the generated HTML code into
layouts/partials/favicon.html
.
- Upload
Footnotes and Citations
Reference to Hugo Footnotes and Citations - GeekThis.
Enable footnotes parameter in your Hugo config file:
Nowaday, the newer Hugo versions are using Goldmark.
[markup]
defaultMarkdownHandler = "goldmark"
[markup.goldmark]
[markup.goldmark.extensions]
footnote = true
Footnotes markdown format:
That's some text with a footnote.[^1]
[^1]: And that's the footnote.
Adjust CSS for the old school looking:
a.footnote-ref::before {
content: '[';
}
a.footnote-ref::after {
content: ']';
}
Paginator
(Added on 2023-09-19)
Lately, I’ve been trying to create draft posts in Hugo ahead of time by setting the front matter to draft = true
. However, the Hugo theme I’m using is quite outdated, with no recent updates from the upstream, and I’ve made quite a few modifications myself. I currently don’t have the energy to switch to a more modern Hugo theme that has just been released. As a result, after accumulating a certain number of draft posts, my homepage article list would display blank due to a paginator calculation error (wrongly including draft posts in the denominator). With the assistance of GPT-4 and cross-referencing the documentation, I’ve made the necessary modifications, and now the paginator can correctly calculate the numerator and denominator, displaying page content correctly.
layouts/index.html
:
|
|
layouts/partials/pagination.html
:
|
|
Below are the steps to modify the paginator by GPT-4
Thank you for providing the detailed information. Let’s address this issue.
1. Set up Pagination in layouts/index.html:
At the very top of
layouts/index.html
, add the following code:{{ $pages := where (where .Site.RegularPages "Params.hidden" "ne" "true") "Draft" "!=" true }} {{ $paginator := .Paginate $pages }}
This creates a new pagination object named
$paginator
that filters out hidden and draft pages.
2. Update the Range Loop:
Replace the original reference from
.Paginator.Pages
to$paginator.Pages
within yourlayouts/index.html
’srange
loop:Change:
{{ range where .Paginator.Pages "Params.hidden" "ne" "true" }}
To:
{{ range $paginator.Pages }}
Since hidden pages are already filtered out, you don’t need further
where
conditions.
3. Modify layouts/partials/pagination.html:
Replace:
{{ $pag := $.Paginator }}
With:
{{ $pag := $.Site.Paginator }}
Considering that you’ve created
$paginator
inlayouts/index.html
, use$paginator
inpagination.html
.To achieve this, pass
$paginator
to thepagination.html
partial. Update the following:In
layouts/index.html
, change:{{ partial "pagination.html" . }}
To:
{{ partial "pagination.html" $paginator }}
Then, in
layouts/partials/pagination.html
, you can directly use$pag
(as it now points to the$paginator
you passed).
Please implement these changes and regenerate your website. If you encounter any other issues or have concerns, feel free to let me know!
Workflow
(2016. It was taken in a bookstore in Madrid, Spain. The library that I wanted to go to after the meeting was closed that day.)
Pre-work
- Read, read a lot, this part I will describe and decouple more in another article. The basic process design is to extract inspiration that can be transcribed into an article from the notes and after-reading summary, and put it on the to-do list.
- Note, as mentioned earlier, currently my main force is using Joplin and synchronize with Dropbox. Joplin Server is being considered.
- Note, there are also tools such as Instapaper, etc., to be shared in another article in the future.
- Paper notebook, since elementary school, I will always bring large or small paper notebooks around me. I also used note paper for experiments until I met FIELD NOTES I haven’t changed it since. For me the size is moderate, I usually use Original Dot-Graph or Original Graph Paper to facilitate the alignment when writing. Usually take advantage of Black Friday to get some inventory.
- To-do list, previously used OmniFocus, but now I changed to another one for complete cross-platform and collaboration.
Working in progress
- Arrange a time period from the to-do list to write a topic, such as this article.
- Then start to create the Hugo content file in the CLI (in iTerm), and create the static image file directory corresponding to the article. In the future, if I want to modify the slug, I can modify it directly in Front Matter, and the file name and directory name will stay the same. For example, this article, I have changed slug from
hugo-workflow
tomy-hugo-workflow
. - Or if I want to go back and modify existing content files, I can just quickly switch to the Hugo project directory by using custom alias.
|
|
- Open local preview in browser,
|
|
- Because this terminal has been using by the hugo server, I use iTerm2
Cmd
+Shift
+T
key binding to duplicate another terminal tab with the same path.
- After switching to the static image file directory in the Hugo project,
|
|
- Leave or finish editing, no longer need to send screenshots to the static image file directory:
|
|
- When writing, search for relevant materials from the aforementioned note-taking systems, and try to make relevant information or knowledge related by URL, so that readers or myself can cross-reference.
- Compared to systems like WordPress, Hugo allows me to focus on content writing.
- After finishing the draft, I will use Hugo local preview mode to read it several times. If the content is worthy of marking highlight line, I will use custom Hugo Shortcode to draw the highlight line, the example can refer to this article AWS re:Invent Keynote notes.
Post-work
- After finishing the content of the first edition, I will take the time to read it a few more times. Check whether the Chinese and English versions can be switched correctly, whether the corresponding links can arrive smoothly, review whether there are any new requirements observed during the writing process, and update my Hugo workflow to make the future self more efficient (sort of efficiency paranoid…).
- The blog is mainly written for myself (and future family members?!), but it does not pursue the speed of publication (Hugo is fast, but no need to be in a hurry), and is relatively concerned about the verification of the content.
- Take the time out of batches and let ImageOptim organize the images.
- Version control, backup and deployment.
- Currently it is deployed to GitHub Pages and matched with my own domain name. In the future, I might try Amazon S3 + CloudFront to implement some ideas.
- GitHub Pages Docs: You can add a file named
.nojekyll
i your publish root folder, so that GitHub Pages will skip the Jekyll build step and save some build time.
- GitHub Pages Docs: You can add a file named
Bottom line
Hugo and this personal knowledge management workflow may not be suitable for everyone (instead, this sentence pattern is suitable for almost every scene). If you are interested in any of these links, welcome to communicate and discuss together to increase efficiency together :)
If this sharing is helpful to you, feel free to buy me a coffee ☕ 😍