Chiawei Chen

Site Editing Cheatsheet

2023-01-26


math mode

math: true

enable KaTeX\KaTeX block on page, powered by KaTeX.js

syntax

inline mode

The quadratic polynomial \\(ax^2 + bx + c \\) has discriminant \\(b^2 - 4 a c\\).

will produce

The quadratic polynomial ax2+bx+cax^2 + bx + c has discriminant b24acb^2 - 4 a c.

display mode

achieved this by katex shortcode .

{{< katex >}}
x_{1,2} = \frac{ - b \pm \sqrt{b^2 - 4ac} }{ 2a }
{{< /katex >}}

will produce

The quadratic formula for the roots of the quadratic polynomial:

x1,2=b±b24ac2ax_{1,2} = \frac{ - b \pm \sqrt{b^2 - 4ac} }{ 2a }

table of contents

enable toc on page.

show_toc: true

escaping hugo shortcode

change your shortcode from

{{< year >}}

to

{{< /*year*/ >}}

table

Has 3 optional arguments, id, class and title.

{{< table title="Environment" class="table mx-auto border border-slate-500" >}}
| key  | value     |
| ---- | --------- |
| host | localhost |
{{< /table >}}
Click to Open hugo-shortcode-table.html
{{ $htmlTable := .Inner | markdownify }}
{{ $label := i18n "table_label" | default "Table" }}
{{ $tag := "<table>" }}
{{ $newTag := "<table" }}
{{ with .Get "id" }}
{{ $newTag = printf "<table id='%s'" . }}
{{ end }}
{{ with .Get "class" }}
{{ $newTag = print $newTag " " . }}
{{ end }}
{{ $newTag = print $newTag " itemscope itemtype='https://schema.org/Table'>" }}
{{ with .Get "title" }}
{{ $caption := printf "<caption itemprop='about'><strong>%s</strong> %s</caption>" $label . }}
{{ $newTag = print $newTag $caption }}
{{ end }}
{{ $htmlTable := replace $htmlTable $tag $newTag }}
{{ $htmlTable | safeHTML }}
{{/* inspire by https://gist.github.com/djibe/7a8ba9516f4495dbd6fdf1d1de7a60fe#file-hugo-shortcode-table-html and improved by kuaz */}}

details

Creates a details HTML element. You can pass your title to summary element to setup title argument.

Has 3 arguments:

{{< details title="\*Hello, Planet." >}}
[[Official]*ハロー、プラネット。](https://www.youtube.com/watch?v=oVb6Gkf-IJM)
{{< /details >}}

will produce

Click to Open *Hello, Planet. [Official]*ハロー、プラネット。
Click to Open hugo-shortcode-details.html
{{ $open := .Get "open" | default "false" }}
{{ $markdownify := .Get "markdownify" | default "true" }}
<details
{{ if eq $open "true"}}
open
{{ end }}
>
<summary>
{{ i18n "click_to_open" | default "Click to Open" }}
{{ with .Get "title" }}
{{ . | markdownify }}
{{ end }}
</summary>
{{ if eq $markdownify "true"}}
{{ .Inner | markdownify }}
{{ else }}
{{ .Inner }}
{{ end }}
</details>

gist

A simple gist shortcode.

{{< gist author="exkuretrol" hash="88a4dfda6f4f25dc09c6ab472f4a44bb" >}}
<script
src={{ printf "https://gist.github.com/%s/%s.js" (.Get "author") (.Get "hash") }}
></script>