<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>shortcode on nocturne</title><link>https://tiennm99.github.io/nocturne/tags/shortcode/</link><description>Recent content in shortcode on nocturne</description><generator>Hugo</generator><language>en</language><lastBuildDate>Thu, 20 Aug 2026 19:30:00 +0700</lastBuildDate><atom:link href="https://tiennm99.github.io/nocturne/tags/shortcode/index.xml" rel="self" type="application/rss+xml"/><item><title>Hugo's built-in shortcodes</title><link>https://tiennm99.github.io/nocturne/2026/08/20/shortcodes/</link><pubDate>Thu, 20 Aug 2026 19:30:00 +0700</pubDate><guid>https://tiennm99.github.io/nocturne/2026/08/20/shortcodes/</guid><description>&lt;p&gt;A shortcode is a small template you call from the middle of Markdown, written as &lt;code&gt;{{&amp;lt; name params &amp;gt;}}&lt;/code&gt;. Hugo ships a set of them, and this post tries each one in turn. Every section shows the source first and the result right after.&lt;/p&gt;
&lt;p&gt;The shortcodes that embed third-party content (YouTube, Vimeo, X, Instagram) are left out: they pull in code from someone else&amp;rsquo;s servers as soon as the page opens, and a demo site should not push that on its visitors.&lt;/p&gt;
&lt;h2 id="why-nocturne-has-no-shortcodes-of-its-own"&gt;Why nocturne has no shortcodes of its own&lt;/h2&gt;&lt;p&gt;A post that uses a theme&amp;rsquo;s own shortcode is tied to that theme: switch themes and the build fails on that post, and you are left fixing files one by one. nocturne wants your content to stay plain Markdown that reads fine on GitHub, in your editor, and wherever you move it next.&lt;/p&gt;
&lt;p&gt;Everything the theme does to your content goes through render hooks instead: captioned images, GitHub-style alerts, scrolling tables, links to &lt;code&gt;.md&lt;/code&gt; files. You write standard Markdown and the theme handles the presentation. If you really need a shortcode, put it in your site&amp;rsquo;s &lt;code&gt;layouts/_shortcodes/&lt;/code&gt; — it belongs to your content, not to the theme.&lt;/p&gt;
&lt;h2 id="figure"&gt;figure&lt;/h2&gt;&lt;p&gt;An image with a caption and a link, written as a shortcode rather than Markdown image syntax:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-markdown" data-lang="markdown"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;{{&amp;lt; figure
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; src=&amp;#34;https://tiennm99.github.io/nocturne/img/tinh-tu-static.png&amp;#34;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; alt=&amp;#34;A test card with six vertical colour bars&amp;#34;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; caption=&amp;#34;A test card, stored in the static folder.&amp;#34;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; link=&amp;#34;https://en.wikipedia.org/wiki/Test_card&amp;#34;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&amp;gt;}}
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;figure&gt;&lt;a href="https://en.wikipedia.org/wiki/Test_card"&gt;&lt;img src="https://tiennm99.github.io/nocturne/img/tinh-tu-static.png"
 alt="A broadcast test card: six vertical bars in red, green, yellow, blue, magenta and cyan, crossed by a diagonal rainbow streak"&gt;&lt;/a&gt;&lt;figcaption&gt;
 &lt;p&gt;A test card, stored in the static folder. Click the image to read about test cards.&lt;/p&gt;
 &lt;/figcaption&gt;
&lt;/figure&gt;

&lt;p&gt;For an image in the bundle, the Markdown syntax &lt;code&gt;![alt](image.jpg &amp;quot;caption&amp;quot;)&lt;/code&gt; produces the same &lt;code&gt;&amp;lt;figure&amp;gt;&lt;/code&gt; and adds a &lt;code&gt;srcset&lt;/code&gt; on top; see &lt;a href="https://tiennm99.github.io/nocturne/2026/06/12/hinh-anh/"&gt;the post about images&lt;/a&gt;.&lt;/p&gt;
&lt;blockquote&gt;
 &lt;p&gt;&lt;strong&gt;Sites in a subfolder&lt;/strong&gt;&lt;/p&gt;
 &lt;p&gt;&lt;code&gt;figure&lt;/code&gt; looks for &lt;code&gt;src&lt;/code&gt; in the bundle and then in &lt;code&gt;assets/&lt;/code&gt;, but it does not add the base path to files in &lt;code&gt;static/&lt;/code&gt;. The demo lives under &lt;code&gt;/nocturne/&lt;/code&gt;, so &lt;code&gt;src=&amp;quot;/img/tinh-tu-static.png&amp;quot;&lt;/code&gt; would point outside the site; that is why the example above uses a full URL. Markdown image syntax has no such problem, because the theme&amp;rsquo;s render hook adds the base path for you.&lt;/p&gt;
&lt;/blockquote&gt;&lt;h2 id="details"&gt;details&lt;/h2&gt;&lt;p&gt;A collapsible block whose content is still written in Markdown:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-markdown" data-lang="markdown"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;{{&amp;lt; details summary=&amp;#34;Show the top of hugo.yaml&amp;#34; &amp;gt;}}
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;...
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;{{&amp;lt; /details &amp;gt;}}
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;details&gt;
 &lt;summary&gt;Show the top of hugo.yaml&lt;/summary&gt;
 &lt;p&gt;The first three lines of &lt;code&gt;hugo.yaml&lt;/code&gt; for an English site using nocturne:&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;theme&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l"&gt;nocturne&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="nt"&gt;languageCode&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l"&gt;en&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="nt"&gt;defaultContentLanguage&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l"&gt;en&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;The full required block is in the &lt;a href="https://github.com/tiennm99/nocturne/blob/main/docs/config.md" rel="noopener noreferrer"&gt;configuration docs&lt;/a&gt;.&lt;/p&gt;
&lt;/details&gt;

&lt;p&gt;Add &lt;code&gt;open=true&lt;/code&gt; to have the block open when the page loads.&lt;/p&gt;
&lt;h2 id="highlight"&gt;highlight&lt;/h2&gt;&lt;p&gt;The same highlighter as fenced code blocks, with the options passed as shortcode parameters:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-markdown" data-lang="markdown"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;{{&amp;lt; highlight go &amp;#34;linenos=inline,hl_lines=3&amp;#34; &amp;gt;}}
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;...
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;{{&amp;lt; /highlight &amp;gt;}}
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-go" data-lang="go"&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt;1&lt;/span&gt;&lt;span class="cl"&gt;&lt;span class="kd"&gt;func&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="w"&gt; &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="ln"&gt;2&lt;/span&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt;	&lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;==&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;&amp;#34;&amp;#34;&lt;/span&gt;&lt;span class="w"&gt; &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 hl"&gt;&lt;span class="ln"&gt;3&lt;/span&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt;		&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;&amp;#34;friend&amp;#34;&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="ln"&gt;4&lt;/span&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt;	&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="ln"&gt;5&lt;/span&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt;	&lt;/span&gt;&lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;&amp;#34;Hello, &amp;#34;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;name&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="ln"&gt;6&lt;/span&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;In a post, a fenced block such as &lt;code&gt;```go {hl_lines=3}&lt;/code&gt; is tidier; &lt;code&gt;highlight&lt;/code&gt; earns its keep when the code sits inside a template or another shortcode.&lt;/p&gt;
&lt;h2 id="qr"&gt;qr&lt;/h2&gt;&lt;p&gt;Generates a QR code at build time, as a PNG served with the site:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-markdown" data-lang="markdown"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;{{&amp;lt; qr text=&amp;#34;https://tiennm99.github.io/nocturne/&amp;#34; alt=&amp;#34;...&amp;#34; /&amp;gt;}}
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;img src="https://tiennm99.github.io/nocturne/qr_bab63491ad8219.png" width="148" height="148" alt="QR code linking to the nocturne demo site"&gt;
&lt;p&gt;Scan it with your phone to open this demo.&lt;/p&gt;
&lt;h2 id="param"&gt;param&lt;/h2&gt;&lt;p&gt;Reads a parameter, looking in the page&amp;rsquo;s front matter first and then in the site&amp;rsquo;s &lt;code&gt;params&lt;/code&gt;:&lt;/p&gt;
&lt;table&gt;
 &lt;thead&gt;
 &lt;tr&gt;
 &lt;th style="text-align: left"&gt;Source&lt;/th&gt;
 &lt;th style="text-align: left"&gt;Result&lt;/th&gt;
 &lt;/tr&gt;
 &lt;/thead&gt;
 &lt;tbody&gt;
 &lt;tr&gt;
 &lt;td style="text-align: left"&gt;&lt;code&gt;{{&amp;lt; param &amp;quot;author&amp;quot; &amp;gt;}}&lt;/code&gt;&lt;/td&gt;
 &lt;td style="text-align: left"&gt;Your Name&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td style="text-align: left"&gt;&lt;code&gt;{{&amp;lt; param &amp;quot;toc.minWordCount&amp;quot; &amp;gt;}}&lt;/code&gt;&lt;/td&gt;
 &lt;td style="text-align: left"&gt;400&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td style="text-align: left"&gt;&lt;code&gt;{{&amp;lt; param &amp;quot;description&amp;quot; &amp;gt;}}&lt;/code&gt;&lt;/td&gt;
 &lt;td style="text-align: left"&gt;figure, details, highlight, qr, param, ref and relref — the shortcodes Hugo ships with, all working in nocturne without the theme adding any of its own.&lt;/td&gt;
 &lt;/tr&gt;
 &lt;/tbody&gt;
&lt;/table&gt;&lt;p&gt;The last row is a small trap: the site has &lt;code&gt;params.description&lt;/code&gt;, but this post has a &lt;code&gt;description&lt;/code&gt; in its front matter too, so &lt;code&gt;param&lt;/code&gt; returns the post&amp;rsquo;s own. The dot in &lt;code&gt;toc.minWordCount&lt;/code&gt; reaches into a nested parameter.&lt;/p&gt;
&lt;h2 id="ref-and-relref"&gt;ref and relref&lt;/h2&gt;&lt;p&gt;These two look up a page by its path under &lt;code&gt;content/&lt;/code&gt; and return its URL. If the page does not exist the build fails, so a broken link can never go live.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;ref&lt;/code&gt; returns the full URL: &lt;code&gt;https://tiennm99.github.io/nocturne/2026/07/03/khoi-code/&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;relref&lt;/code&gt; returns the path without the host: &lt;code&gt;/nocturne/2026/07/03/khoi-code/&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Most of the time they sit inside a Markdown link, optionally with a &lt;code&gt;#&lt;/code&gt; fragment pointing at a heading:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-markdown" data-lang="markdown"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;[&lt;span class="nt"&gt;A Markdown tour&lt;/span&gt;](&lt;span class="na"&gt;{{&amp;lt; relref &amp;#34;/post/2026/05/07/sample&amp;#34; &amp;gt;}}&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;[&lt;span class="nt"&gt;its Alerts section&lt;/span&gt;](&lt;span class="na"&gt;{{&amp;lt; relref &amp;#34;/post/2026/05/07/sample#alerts&amp;#34; &amp;gt;}}&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The result: &lt;a href="https://tiennm99.github.io/nocturne/2026/08/20/shortcodes//nocturne/2026/05/07/sample/"&gt;A Markdown tour&lt;/a&gt; and &lt;a href="https://tiennm99.github.io/nocturne/2026/08/20/shortcodes//nocturne/2026/05/07/sample/#alerts"&gt;its Alerts section&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;In nocturne, a Markdown link straight to the file, such as &lt;code&gt;[post](/post/2026/05/07/sample/index.md)&lt;/code&gt;, gives the same URL without any shortcode; &lt;code&gt;ref&lt;/code&gt; and &lt;code&gt;relref&lt;/code&gt; still pay off when you want the build to stop the moment the target page disappears.&lt;/p&gt;</description></item></channel></rss>