Notes of Hugo
Aug 26 2024: Set a page variable “showthedate”
References
- Configure Hugo
- Content: is it same for Page and Post? And how to hide date
- How to check if dynamically-named variable exists in context?
The page variable date
is required in every post that is further collected in
a list (e.g. Blog, 日志, and TechNote). Take the hugo-ivy theme I currently used
as an example, the appearance of the date in each page (in list) is controlled
by the file themes/hugo-ivy/layouts/partials/meta.html
{{ if not .IsHome }}
<h1>{{ .Title }}</h1>
{{ with .Params.subtitle }}<h1><span class="subtitle">{{ . }}</span></h2>{{ end }}
{{ if .IsPage }}
<h3>
{{ with or (or .Params.author (index .Site.Params.author .Section)) "" }}{{ print . " / " }}{{ end }}
{{ if .Params.date }}{{ .Date.Format "2006-01-02" }}{{ end }}
</h3>
{{ end }}
<hr>
{{ end }}
Let’s make a slight modification
{{ if not .IsHome }}
<h1>{{ .Title }}</h1>
{{ with .Params.subtitle }}<h1><span class="subtitle">{{ . }}</span></h2>{{ end }}
{{ if .IsPage }}
<h3>
{{ with or (or .Params.author (index .Site.Params.author .Section)) "" }}{{ print . " / " }}{{ end }}
<!-- {{ if .Params.date }}{{ .Date.Format "2006-01-02" }}{{ end }} -->
{{ if isset .Params "showthedate" }}
{{ if eq .Params.showthedate true }}
{{ if .Params.date }}{{ .Date.Format "2006-01-02" }}{{ end }}
{{ end }}
{{ else }}
{{ if .Params.date }}{{ .Date.Format "2006-01-02" }}{{ end }}
{{ end }}
</h3>
{{ end }}
<hr>
{{ end }}
We have the following three cases (for the hugo-ivy theme)
-
In the .md or .org file, we don’t have the page variable
showthedate
, then the date will show in the posts (in list). -
If we define the page variable
showthedate
in the .md file+++ showthedate = true +++
or in the .org file (using ox-hugo)
#+hugo_custom_front_matter: :showthedate true
then the date will show in the posts (in list).
-
If we define the page variable
showthedate
in the .md file+++ showthedate = false +++
or in the .org file (using ox-hugo)
#+hugo_custom_front_matter: :showthedate false
then the date will NOT show in the posts (in list).
Aug 30 2024: Highlight the LISP code block using highlight.js
References
- How To Highlight Syntax In Pre Tags Using Highlight.js
- highlight.js => Github page of highlight.js => Supported Languages
- cdnjs-link => libraries of highlight.js
Add this script to themes/hugo-ivy/layouts/partials/head_highlightjs.html
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.6.0/highlight.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.10.0/languages/lisp.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/highlightjs-themes@1.0.0/atelier-forest.dark.css" />
<script>
var preTags = document.getElementsByTagName('pre');
var size = preTags.length;
for (var i=0; i < size; i++) {
preTags[i].innerHTML = '<code>'+preTags[i].innerHTML+'</code>'; // wrap content of pre tag in code tag
}
hljs.highlightAll(); // apply highlighting
</script>
Suppose we want to highlight the latex
code block in the posts, we only need
to search the necessary JS
file from the libraries of highlight.js, and add it
to the above script in themes/hugo-ivy/layouts/partials/head_highlightjs.html
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.10.0/languages/latex.min.js"></script>
Todo
- Read the Hugo Documentation carefully
- Learn to write the shortcode
- Figure out the differences between
- the folders layouts and themes/hugo-ivy/layouts
- the folders static and themes/hugo-ivy/static
- Change the font of blog