butiran

template customization 1

First theme customization of a new Hugo site following initial setting.

In previous post with title first post again customization is only in layouts/partials/footer.html. Here more customizations in various files are given.

  1. Create content of layouts/posts/single.html is as follow.
    {{ define "main" }}
      

    {{ .Title }}

    {{ $dateMachine := .Date | time.Format "2006-01-02T15:04:05-07:00" }} {{ $dateHuman := .Date | time.Format ":date_long" }} {{- range .Params.authors }} {{- with $.Site.GetPage "taxonomyTerm" (printf "authors/%s" (urlize .)) }}
    {{ .Params.name }}
    {{ end }} {{ end }}
    {{ partial "reading-time.html" . }} ·
    {{ .Content }} {{ partial "terms.html" (dict "taxonomy" "tags" "page" .) }} {{ partial "posts/math.html" . }} {{ end }}
  2. Create content of layouts/partials/reading-time.html is as follow.
    {{ .ReadingTime }} min{{ if (ne .ReadingTime 1) }}s{{ end }} read
    
  3. Create content of layouts/partials/posts/math.html is as follow.
    {{- if or (.Params.math) (.Site.Params.math) (.Params.katex) (.Site.Params.katex) -}}
    
      
      {{/* The loading of KaTeX is deferred to speed up page rendering */}}
      
    
    
    
        
    
      
    {{- end -}}
    
  4. Create content of layouts/_default/baseof.html is as follow.
    
    
    
      {{ partial "head.html" . }}
    
    
      
    {{ partial "header.html" . }} {{ if .HasShortcode "blank/scatter" }} {{ partial "script/inner.html" . }} {{ partial "script/chartjs.html" . }} {{ end }} {{ if .HasShortcode "blank/svgpath" }} {{ partial "script/inner.html" . }} {{ end }}
    {{ block "main" . }}{{ end }}
    {{ partial "footer.html" . }}
    {{ if .Store.Get "hasMermaid" }} {{ end }}
  5. Create content of layouts/_default/_markup/render-codeblock-mermaid.html as follow.
      {{- .Inner | safeHTML }}
    
    {{ .Page.Store.Set "hasMermaid" true }}
  6. Create content of content/authors/viridi/_index.md as follow.
    +++
    name = 'Sparisoma Viridi'
    twitter = '@6unpnp'
    +++
    Sparisoma Viridi is granular physicist who likes doing programming.
    

Without Step 6 for an author page, even when Step 1 is performed, the link will not be shown in a post. Step 4 is for including any partials by checking first the existance of the related shortcodes files. And support for Mermaid in Step 5 is performed using code block render hooks 1 instead of shortcodes 2. There is also support for a KaTeX extension, mhchem 3


  1. Hugo Authors, “Code block render hooks”, Hugo, 14 Jun 2024, url https://gohugo.io/render-hooks/code-blocks/ [20241012]. ↩︎

  2. Navendu Pattekkat, “Adding Diagrams to Your Hugo Blog With Mermaid”, Navendu.me, 26 Aug 2022, url https://navendu.me/posts/adding-diagrams-to-your-hugo-blog-with-mermaid/ [20241012]. ↩︎

  3. KaTeX Contributors, “mhchem extension”, KaTeX, GitHub, 2 Jul 2024, url https://github.com/KaTeX/KaTeX/tree/main/contrib/mhchem [20241012]. ↩︎