<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Hugo diary on nocturne</title><link>https://tiennm99.github.io/nocturne/categories/nhat-ky-hugo/</link><description>Recent content in Hugo diary on nocturne</description><generator>Hugo</generator><language>en</language><lastBuildDate>Sat, 14 Feb 2026 21:00:00 +0700</lastBuildDate><atom:link href="https://tiennm99.github.io/nocturne/categories/nhat-ky-hugo/index.xml" rel="self" type="application/rss+xml"/><item><title>Writing your own Hugo theme</title><link>https://tiennm99.github.io/nocturne/2026/02/14/tu-viet-theme/</link><pubDate>Sat, 14 Feb 2026 21:00:00 +0700</pubDate><guid>https://tiennm99.github.io/nocturne/2026/02/14/tu-viet-theme/</guid><description>&lt;p&gt;A month after &lt;a href="https://tiennm99.github.io/nocturne/2026/01/10/ke-hoach-dau-nam/"&gt;the new-year plan&lt;/a&gt;, &lt;code&gt;nocturne&lt;/code&gt; is good enough to write about on itself. This post records the decisions that shaped the theme, so that when I want to add something later, I remember why I left it out in the first place.&lt;/p&gt;
&lt;h2 id="why-build-your-own"&gt;Why build your own&lt;/h2&gt;&lt;p&gt;Using a ready-made theme is like renting a furnished flat: you can move in today, but moving a shelf means asking the landlord. Every time Hugo changed something, I had to read someone else&amp;rsquo;s code to find out whether the theme still worked.&lt;/p&gt;
&lt;p&gt;Writing your own is slower at first, but afterwards everything has an owner. When a page renders wrong, I know which file to open. When a new Hugo release lands, the list of things that might break is short enough to read in one evening.&lt;/p&gt;
&lt;p&gt;There is one more reason: writing a theme makes you actually learn Hugo. Lookup order, page bundles, render hooks, how multilingual sites fit together; you have to touch each of them at least once.&lt;/p&gt;
&lt;h2 id="keep-it-small"&gt;Keep it small&lt;/h2&gt;&lt;p&gt;The rule of thumb: everything added must answer &amp;ldquo;what does the reader get?&amp;rdquo;. If the answer is &amp;ldquo;it looks a bit fancier&amp;rdquo;, the answer is usually no.&lt;/p&gt;
&lt;h3 id="no-build-step"&gt;No build step&lt;/h3&gt;&lt;p&gt;No Node, no bundler, no PostCSS. The CSS is a handful of plain files that Hugo joins, minifies and fingerprints. The JavaScript is small ES modules, one job each: the theme toggle, the copy button on code blocks, the table of contents that tracks your scroll. All of it together is under ten kilobytes before compression.&lt;/p&gt;
&lt;h3 id="data-not-params"&gt;Data, not params&lt;/h3&gt;&lt;p&gt;The home page is a portfolio, but the personal details are not in &lt;code&gt;hugo.yaml&lt;/code&gt;. The bio and links live in &lt;code&gt;data/profile.yaml&lt;/code&gt;, the featured projects in &lt;code&gt;data/projects.yaml&lt;/code&gt;. The config file is left with the switches that turn features on and off, and it reads at a glance.&lt;/p&gt;
&lt;h3 id="no-shortcodes-of-its-own"&gt;No shortcodes of its own&lt;/h3&gt;&lt;p&gt;The theme ships no shortcodes. A shortcode is Hugo-only syntax; once it is in a post, the post is tied to the theme. Whatever Markdown can express, such as captioned images or callout boxes, the theme handles with render hooks, so the content stays plain Markdown.&lt;/p&gt;
&lt;h2 id="dark-by-default"&gt;Dark by default&lt;/h2&gt;&lt;p&gt;I mostly write and read at night, so the dark look is the default, not an afterthought. The moon and sun button in the top corner switches to light, and the choice is remembered for next time.&lt;/p&gt;
&lt;h3 id="no-white-flash"&gt;No white flash&lt;/h3&gt;&lt;p&gt;The hard part of a dark theme is the moment before the CSS applies: the page flashes white, then goes dark. The cure is a tiny script that runs right in &lt;code&gt;&amp;lt;head&amp;gt;&lt;/code&gt;, before the browser paints anything:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-js" data-lang="js"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;localStorage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getItem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;theme&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;light&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;documentElement&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;setAttribute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;data-theme&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;light&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Because dark is the default, the script only has work to do when the reader has picked light. With JavaScript off, the page is still dark and still readable.&lt;/p&gt;
&lt;h3 id="colours-are-tokens"&gt;Colours are tokens&lt;/h3&gt;&lt;p&gt;Every colour is a CSS variable in a single file: dark values on &lt;code&gt;:root&lt;/code&gt;, light values on &lt;code&gt;:root[data-theme=&amp;quot;light&amp;quot;]&lt;/code&gt;. To change the accent colour in both modes, a site overrides a few variables and never touches the theme.&lt;/p&gt;
&lt;blockquote&gt;
 &lt;p&gt;&lt;strong&gt;Tip&lt;/strong&gt;&lt;/p&gt;
 &lt;p&gt;When picking colours for a dark background, avoid pure white for text. A warm, moderately bright grey is far easier on the eyes over a long read.&lt;/p&gt;
&lt;/blockquote&gt;&lt;h2 id="vietnamese-typography"&gt;Vietnamese typography&lt;/h2&gt;&lt;p&gt;The theme puts Vietnamese first, so the text got the most care.&lt;/p&gt;
&lt;h3 id="fonts-with-every-diacritic"&gt;Fonts with every diacritic&lt;/h3&gt;&lt;p&gt;The font stack starts with Inter and Be Vietnam Pro, then falls back to system fonts. Both cover the full Vietnamese alphabet; when neither is installed, modern system fonts render it well too. What you want to avoid is a font missing a few glyphs like &amp;ldquo;ữ&amp;rdquo; or &amp;ldquo;ặ&amp;rdquo;, leaving a single word set in two typefaces.&lt;/p&gt;
&lt;h3 id="line-height"&gt;Line height&lt;/h3&gt;&lt;p&gt;Vietnamese stacks diacritics above and below the letters. A body line height of 1.7 keeps one line&amp;rsquo;s marks from touching the next. Headings use tighter spacing, since the type is larger and the lines are few.&lt;/p&gt;
&lt;h3 id="anchors-and-dates"&gt;Anchors and dates&lt;/h3&gt;&lt;p&gt;Heading IDs come out as ASCII, so on the Vietnamese page the section &amp;ldquo;Chữ tiếng Việt&amp;rdquo; is &lt;code&gt;#chu-tieng-viet&lt;/code&gt;: short and easy to share. The letter &amp;ldquo;đ&amp;rdquo; is dropped rather than turned into &amp;ldquo;d&amp;rdquo;, so the Vietnamese headings that contain it get a hand-written ID, as in &lt;code&gt;## Nền tối là mặc định {#nen-toi-la-mac-dinh}&lt;/code&gt;. Dates follow each language&amp;rsquo;s format, so a Vietnamese post shows the date the Vietnamese way rather than &amp;ldquo;February 14, 2026&amp;rdquo;.&lt;/p&gt;
&lt;h2 id="whats-left"&gt;What&amp;rsquo;s left&lt;/h2&gt;&lt;p&gt;There is plenty still to do: the archive page, search, a second language. But the core is solid and, more importantly, I understand every line of it. The rest can wait for later posts.&lt;/p&gt;</description></item><item><title>Planning the new year</title><link>https://tiennm99.github.io/nocturne/2026/01/10/ke-hoach-dau-nam/</link><pubDate>Sat, 10 Jan 2026 08:00:00 +0700</pubDate><guid>https://tiennm99.github.io/nocturne/2026/01/10/ke-hoach-dau-nam/</guid><description>&lt;p&gt;At the start of each year I write down three things I want done by the end of June. Never more, because a long list never gets finished. This year one of the three is the Hugo theme I mentioned in &lt;a href="https://tiennm99.github.io/nocturne/2025/08/15/ghi-chu-hugo/"&gt;my notes from August&lt;/a&gt;: &lt;code&gt;nocturne&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id="why-write-my-own"&gt;Why write my own&lt;/h2&gt;&lt;p&gt;The theme I use works, but it is heavy. It has a slider, animations, and a whole folder of JavaScript I have never opened. Writing my own is the only way to know why each line is there.&lt;/p&gt;
&lt;h2 id="goals"&gt;Goals&lt;/h2&gt;&lt;ol&gt;
&lt;li&gt;No build step for CSS or JS: just Hugo and the ES modules browsers already understand.&lt;/li&gt;
&lt;li&gt;Vietnamese first. Other languages are a bonus, not a requirement.&lt;/li&gt;
&lt;li&gt;The home page is a portfolio; the posts are everything else.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id="how-ill-know"&gt;How I&amp;rsquo;ll know&lt;/h2&gt;&lt;p&gt;A goal you cannot check is only a wish, so each one gets a simple test:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;input checked="" disabled="" type="checkbox"&gt; The site runs with &lt;code&gt;hugo server&lt;/code&gt; and no &lt;code&gt;npm install&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;input disabled="" type="checkbox"&gt; A long post reads comfortably on a phone, even with JavaScript off.&lt;/li&gt;
&lt;li&gt;&lt;input disabled="" type="checkbox"&gt; One post in Vietnamese plus an English version, and switching between them never loses your place.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="not-doing"&gt;Not doing&lt;/h2&gt;&lt;p&gt;This list matters as much as the one above: no self-hosted comments, no icon library, no CSS framework. When something is needed, write exactly that part.&lt;/p&gt;
&lt;p&gt;More once the theme has taken shape.&lt;/p&gt;</description></item><item><title>Notes on Hugo and static sites</title><link>https://tiennm99.github.io/nocturne/2025/08/15/ghi-chu-hugo/</link><pubDate>Fri, 15 Aug 2025 09:00:00 +0700</pubDate><guid>https://tiennm99.github.io/nocturne/2025/08/15/ghi-chu-hugo/</guid><description>&lt;p&gt;Hugo is a static site generator written in Go. Coming back to it after a long break, I found a fair amount had changed. These are personal notes, not a tutorial: the things I want to remember before starting on something bigger.&lt;/p&gt;
&lt;h2 id="the-new-layout-convention"&gt;The new layout convention&lt;/h2&gt;&lt;p&gt;Since 0.146, the special folders inside &lt;code&gt;layouts/&lt;/code&gt; start with an underscore: &lt;code&gt;_partials&lt;/code&gt;, &lt;code&gt;_markup&lt;/code&gt;, &lt;code&gt;_shortcodes&lt;/code&gt;. The underscore keeps them apart from section names, so a section called &lt;code&gt;partials&lt;/code&gt; can no longer be mistaken for the folder of partials.&lt;/p&gt;
&lt;h3 id="the-_partials-folder"&gt;The &lt;code&gt;_partials&lt;/code&gt; folder&lt;/h3&gt;&lt;p&gt;Reusable template pieces live here: the header, the footer, a post card. A section is a kind of content; a partial is just a piece of the page.&lt;/p&gt;
&lt;h3 id="the-_markup-folder"&gt;The &lt;code&gt;_markup&lt;/code&gt; folder&lt;/h3&gt;&lt;p&gt;Render hooks for Markdown: headings, links, images, code blocks, tables, blockquotes. Hugo finds them on its own while rendering content; nothing needs registering.&lt;/p&gt;
&lt;h3 id="the-_shortcodes-folder"&gt;The &lt;code&gt;_shortcodes&lt;/code&gt; folder&lt;/h3&gt;&lt;p&gt;Exactly what it says. A shortcode placed here in your site overrides the theme&amp;rsquo;s shortcode of the same name.&lt;/p&gt;
&lt;h2 id="the-asset-pipeline"&gt;The asset pipeline&lt;/h2&gt;&lt;p&gt;Hugo needs no external build tool. &lt;code&gt;resources.Get&lt;/code&gt; picks up a file from &lt;code&gt;assets/&lt;/code&gt;, &lt;code&gt;resources.Concat&lt;/code&gt; joins files, &lt;code&gt;minify&lt;/code&gt; compresses them and &lt;code&gt;fingerprint&lt;/code&gt; puts a hash in the file name. For a small to medium site, that is the whole pipeline.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-yaml" data-lang="yaml"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nt"&gt;markup&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;goldmark&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;parser&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;autoHeadingIDType&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l"&gt;github-ascii&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This one setting solves a big problem for anyone writing in Vietnamese: heading IDs come out as plain ASCII, stable and URL-safe. &amp;ldquo;Thư mục&amp;rdquo; becomes &lt;code&gt;#thu-muc&lt;/code&gt; instead of a long run of percent-encoded bytes. Only &amp;ldquo;đ&amp;rdquo; is dropped rather than turned into &amp;ldquo;d&amp;rdquo;; when it matters, write the ID by hand right after the heading text, as the Vietnamese version of this post does with &lt;code&gt;{#di-tiep}&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id="render-hooks"&gt;Render hooks&lt;/h2&gt;&lt;p&gt;Render hooks let you step into Markdown rendering without writing a Goldmark extension. A small template in &lt;code&gt;_markup/&lt;/code&gt; is enough.&lt;/p&gt;
&lt;p&gt;A few things I reach for:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;a &lt;code&gt;#&lt;/code&gt; anchor link next to each heading;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;rel=&amp;quot;noopener&amp;quot;&lt;/code&gt; on outbound links;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;srcset&lt;/code&gt;, dimensions and &lt;code&gt;loading=&amp;quot;lazy&amp;quot;&lt;/code&gt; on images, so the page does not jump while it loads.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="things-worth-keeping"&gt;Things worth keeping&lt;/h2&gt;&lt;ul&gt;
&lt;li&gt;Plain Markdown is a long-term asset. Any generator can read it.&lt;/li&gt;
&lt;li&gt;Hugo is rarely what makes a build slow. When it is slow, the culprit is usually image processing or an over-eager resource pipeline.&lt;/li&gt;
&lt;li&gt;A light theme makes a light site. Every byte of CSS and JS travels over the network to the reader.&lt;/li&gt;
&lt;li&gt;Writing your own theme is how you get to understand every line. Ready-made themes are convenient, but they bring a lot you never needed.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="whats-next"&gt;What&amp;rsquo;s next&lt;/h2&gt;&lt;p&gt;The project for the coming months: a Hugo theme of my own, small, with no build step and Vietnamese first. It is called &lt;code&gt;nocturne&lt;/code&gt;. I will write it and keep notes along the way in this series.&lt;/p&gt;
&lt;p&gt;The next entry will probably be the actual plan, then the CSS and how to do dark mode without a white flash on first load.&lt;/p&gt;</description></item></channel></rss>