fix: links

This commit is contained in:
George Cushen 2023-11-07 23:09:38 +00:00
commit 9b2e271c7c
830 changed files with 4612 additions and 1131 deletions

View file

@ -0,0 +1,41 @@
{{/* Audio Shortcode for Hugo Blox Builder. */}}
{{/* Load audio from page dir falling back to media library at `assets/media/` and then to remote URI. */}}
{{/* Supports primarily MP3 and MP4. */}}
{{/*
Docs: https://hugoblox.com/docs/content/writing-markdown-latex/#audio
Parameters
----------
src :
Path to file or url for the audio file.
If a local file, first it is searched in the page directory, and then in `assets/media/` .
id : optional
Custom id "audio-{id}" to associate to the <audio> tag.
*/}}
{{ $destination := .Get "src" }}
{{ $is_remote := strings.HasPrefix $destination "http" }}
{{- $asset := "" -}}
{{- if not $is_remote -}}
{{- $asset = (.Page.Resources.ByType "audio").GetMatch $destination -}}
{{- if not $asset -}}
{{- $asset = resources.Get (path.Join "media" $destination) -}}
{{- end -}}
{{- end -}}
{{ if $asset }}
{{ $destination = $asset.RelPermalink }}
{{ else }}
{{ $destination = $destination | safeURL }}
{{ end }}
{{ $audio_type := strings.TrimPrefix "." (path.Ext $destination) | lower }}
{{/* Set MP3 mime type to mpeg. */}}
{{ $audio_type = replace $audio_type "mp3" "mpeg" }}
<audio controls {{ with (.Get "id") }}id="audio-{{.|anchorize}}"{{end}}>
<source src="{{$destination}}" type="audio/{{$audio_type}}">
</audio>

View file

@ -0,0 +1,3 @@
<div class="bilibili">
<iframe src="//player.bilibili.com/player.html?bvid={{ .Get `id` }}&page={{ .Get `p` | default 1 }}" allow="fullscreen"></iframe>
</div>

View file

@ -0,0 +1,16 @@
{{/*
Docs: https://hugoblox.com/docs/content/writing-markdown-latex/#callouts
Parameters
----------
#0 : optional, positional
Add the class "alert-{#0}" to the <div> container of the callout element.
Default Hugo Blox Builder available styles are "note" and "warning".
Otherwise you can create your own class (see `assets/scss/blox-bootstrap/elements/_callout.scss`).
*/}}
<div class="alert alert-{{ .Get 0 }}">
<div>
{{ .Inner | markdownify | emojify }}
</div>
</div>

View file

@ -0,0 +1,27 @@
{{/*
Docs: https://hugoblox.com/docs/content/writing-markdown-latex/#charts
Parameters
----------
data :
Plotly JSON file name (without ".json" extension, since it is appended automatically to the name).
Expects the JSON file to be placed in the page folder.
*/}}
{{ $json := printf "./%s.json" (.Get "data") }}
{{ $id := delimit (shuffle (seq 1 9)) "" }}
<div id="chart-{{$id}}" class="chart"></div>
<script>
(function() {
let a = setInterval( function() {
if ( typeof window.Plotly === 'undefined' ) {
return;
}
clearInterval( a );
Plotly.d3.json({{$json}}, function(chart) {
Plotly.plot('chart-{{$id}}', chart.data, chart.layout, {responsive: true});
});
}, 500 );
})();
</script>

View file

@ -0,0 +1,23 @@
{{/*
Docs: https://hugoblox.com/docs/content/writing-markdown-latex/#cite
Parameters
----------
page : required
Path to Markdown page to be referenced.
view : optional, default "compact"
A built-in Hugo Blox Builder view or an installed community view.
*/}}
{{ $page := .Page }}
{{ $item := .Get "page" }}
{{/* Default compact view. */}}
{{ $view := (.Get "view") | default "compact" }}
{{/* Hugo stores all shortcode args as strings, however `render_view` expects legacy numeric views 1-4 to be int */}}
{{ $view = cond (in (slice "1" "2" "3" "4") $view) (int $view) $view }}
{{ with site.GetPage $item }}
{{ partial "functions/render_view" (dict "page" $page "item" . "view" $view "index" 0) }}
{{ end }}

View file

@ -0,0 +1,33 @@
{{/*
Docs: https://hugoblox.com/docs/content/writing-markdown-latex/#call-to-action-buttons
Parameters
----------
cta_text :
Text to display in the CTA button.
cta_link :
Link to action when CTA button is clicked.
cta_new_tab : default "false"
If "true", open the link in a new tab.
cta_alt_text : optional
Alternate text to display in the CTA button.
cta_alt_link : optional
Link to alternative action when CTA button is clicked.
cta_alt_new_tab : optional, default "false"
If "true", open the alternative link in a new tab.
*/}}
<ul class="cta-group">
{{ if (.Get "cta_text") }}
<li>
<a href="{{.Get "cta_link"}}" {{if eq (.Get "cta_new_tab") "true" }}target="_blank" rel="noopener"{{end}} class="btn btn-primary px-3 py-3">{{ (.Get "cta_text") | markdownify | emojify }}</a>
</li>
{{ end }}
{{ if (.Get "cta_alt_text") }}
<li>
<a href="{{.Get "cta_alt_link"}}" {{if eq (.Get "cta_alt_new_tab") "true" }}target="_blank" rel="noopener"{{end}}>
{{ (.Get "cta_alt_text") | markdownify | emojify }} <i class="fas fa-angle-right"></i>
</a>
</li>
{{end}}
</ul>

View file

@ -0,0 +1,5 @@
{{/*
Docs: https://hugoblox.com/docs/content/writing-markdown-latex/#emojis
*/}}
<div class="emoji-list">{{ .Inner }}</div>

View file

@ -0,0 +1,116 @@
{{/* Figure Shortcode for Hugo Blox Builder. */}}
{{/* Load image from page dir falling back to media library at `assets/media/` and then to remote URI. */}}
{{/* Note: Uses `{{-` to unindent HTML so that Figure shortcode can be nested within a `{{%` Markdown shortcode,
such as Callout, without the HTML being rendered as a Markdown code block. */}}
{{/*
Docs: https://hugoblox.com/docs/content/writing-markdown-latex/#single-image
Parameters
----------
src :
Path to file or url for the image.
If a local file, first it is searched in the page directory, and then in `assets/media/` .
caption : optional
Caption to add to the figure.
title : optional
DEPRECATED. Legacy alias for 'caption'.
lightbox : default "true"
If 'lightbox' is "true" and no 'link' is specified, the figure is made zoomable.
link : optional
Link to open on click instead of zooming on click.
id : optional
Custom id "figure-{id}" to associate to the <figure> tag.
The id defaults to the caption if unset.
alt : optional
Screen reader text. Defaults to the caption if unset.
theme : optional
One of ["light", "dark"]. Respectively adds the class ["img-light", "img-dark"] to <figure>.
If "light", image is inverted when browsing in dark mode; the opposite otherwise.
class : optional
Optional additional class for <figure>.
max_width : optional
`max-width` style attribute for the <div class="w-100"> tage inside <figure>.
For example, "fit-content" makes the <div> of the same width of the contained image.
width : optional
`width` attribute of <img>. It defaults to image width.
height : optional
`height` attribute of <img>. It defaults to image height.
numbered : default "false"
If "true", the caption is numbered.
*/}}
{{ $destination := .Get "src" }}
{{ $is_remote := strings.HasPrefix $destination "http" }}
{{ $caption := .Get "caption" | default (.Get "title") | default "" }}{{/* Support legacy `title` option. */}}
{{ $zoom := eq (.Get "lightbox" | default "true") "true" }}
{{ $id := anchorize (.Get "id" | default ($caption | plainify)) }}
{{ $alt := .Get "alt" | default ($caption | plainify) }}
{{ $link := .Get "link" }}
{{ $zoom = cond (ne $link "") false $zoom }}
{{ $img_class := "" }}
{{ if eq (.Get "theme" | lower) "light" }}{{ $img_class = printf "%s img-light" $img_class }}{{end}}
{{ if eq (.Get "theme" | lower) "dark" }}{{ $img_class = printf "%s img-dark" $img_class }}{{end}}
{{/* Workaround Hugo v0.81 error on Windows when `resources.Get (path.Join "media" <URL>)` */}}
{{- $img := "" -}}
{{- if not $is_remote -}}
{{- $img = (.Page.Resources.ByType "image").GetMatch $destination -}}
{{- if not $img -}}
{{- $img = resources.Get (path.Join "media" $destination) -}}
{{- end -}}
{{- end -}}
<figure {{ with .Get "class" }}class="{{.}}"{{end}} {{ with $id }}id="figure-{{ . }}"{{ end }}>
<div class="d-flex justify-content-center">
<div class="w-100" {{ with .Get "max_width" }}style="max-width: {{.}}"{{end}}>
{{- if $link -}}
<a href="{{ $link }}" {{ if strings.HasPrefix $link "http" }} target="_blank" rel="noopener"{{ end }}>
{{- end -}}
{{- if $img -}}
{{- $isSVG := eq $img.MediaType.SubType "svg" -}}
{{- $isGIF := eq $img.MediaType.SubType "gif" -}}
{{- if $isSVG | or $isGIF -}}
<img alt="{{ $alt }}"
src="{{ $img.RelPermalink }}"
loading="lazy"
{{- if $zoom }} data-zoomable{{end}}
{{- with .Get "width" }} width="{{.}}"{{end}}
{{- with .Get "height" }} height="{{.}}"{{end}}
{{- with $img_class }} class="{{.}}"{{end}} />
{{- else }}
{{- $img_lg := $img.Fit "1200x1200 webp" -}}
{{- $img_md := $img_lg.Fit "760x760 webp" -}}{{/* Match `.docs-article-container` max-width */}}
{{- $img_sm := $img_md.Fit "400x400 webp" -}}
{{- $width := (.Get "width") | default $img_md.Width -}}
{{- $height := (.Get "height") | default $img_md.Height -}}
<img alt="{{ $alt }}" srcset="
{{ $img_sm.RelPermalink }} 400w,
{{ $img_md.RelPermalink }} 760w,
{{ $img_lg.RelPermalink }} 1200w"
src="{{ $img_sm.RelPermalink }}"
width="{{ $width }}"
height="{{ $height }}"
loading="lazy"
{{- if $zoom }} data-zoomable{{end}}
{{- with $img_class }} class="{{.}}"{{end}} />
{{- end }}
{{- else -}}
<img src="{{ $destination | safeURL }}" alt="{{ $alt }}" loading="lazy" {{ if $zoom }}data-zoomable{{end}}
{{- with .Get "width" }} width="{{.}}"{{end}} {{- with .Get "height" }} height="{{.}}"{{end}}
{{- with $img_class }} class="{{.}}"{{end}} />
{{- end -}}
{{- if $link -}}
</a>
{{- end -}}
</div>
</div>
{{- if $caption -}}
{{/* Localize the figure numbering (if enabled). */}}
{{- $figure := split (i18n "figure" | default "Figure %d:") "%d" -}}
<figcaption{{ if eq (.Get "numbered") "true" }} data-pre="{{- trim (index $figure 0) " " -}}&nbsp;" data-post="{{ index $figure 1 }}&nbsp;" class="numbered"{{ end }}>
{{ $caption | markdownify | emojify }}
</figcaption>
{{- end -}}
</figure>

View file

@ -0,0 +1,60 @@
{{/* Gallery Shortcode for Hugo Blox Builder. */}}
{{/* Load gallery images from media library. */}}
{{/* https://github.com/HugoBlox/hugo-blox-builder */}}
{{/*
Docs: https://hugoblox.com/docs/content/writing-markdown-latex/#image-gallery
Parameters
----------
album : default "gallery"
Album folder in `assets/media/albums/` to load images from.
order : default "asc"
Sort images by title ascending (asc) or descending (desc).
resize_options : default "750x750"
Resize options passed to Hugo `.Fit` function (https://gohugo.io/content-management/image-processing/).
*/}}
{{/* For gallery nested in landing page sections */}}
{{ $.Page.Store.Set "has_gallery" true }}
{{/* Get album folder or default to `media/albums/gallery/`. */}}
{{ $album := (.Get "album") | default "gallery" }}
{{ $album_path := path.Join "media" "albums" $album "*" }}
{{/* Gallery options */}}
{{ $sort_order := .Get "order" | default "asc" }}
{{ $resize_options := printf "%s webp" (.Get "resize_options" | default "750x750") }}
<div class="gallery-grid">
{{/* Attempt to automatically load gallery images from page bundle */}}
{{ $images := resources.Match $album_path }}
{{ range (sort $images "Name" $sort_order) }}
{{ $image := .Fit $resize_options }}
{{/* Check if the user set a caption for this image */}}
{{ $filename := path.Base .Name }}
{{ $caption := "" }}
{{ if $.Page.Params.gallery_item }}
{{ range (where (where $.Page.Params.gallery_item "album" $album) "image" $filename) }}
{{ $caption = .caption }}
{{ end }}
{{ end }}
{{ $image_size := "gallery-item--medium" }}
{{if in .Name "-f." }}
{{ $image_size = "gallery-item--full" }}
{{else if in .Name "-s." }}
{{ $image_size = "" }}
{{else if in .Name "-l." }}
{{ $image_size = "gallery-item--large" }}
{{end}}
<div class="gallery-item {{$image_size}}">
<a data-fancybox="gallery-{{$album}}" href="{{ .RelPermalink }}" {{ with $caption }}data-caption="{{.|markdownify|emojify|safeHTMLAttr}}"{{ end }}>
<img src="{{ $image.RelPermalink }}" loading="lazy" alt="{{ plainify $caption | default $filename }}" width="{{ $image.Width }}" height="{{ $image.Height }}">
</a>
</div>
{{else}}
{{ errorf "Unable to load gallery `%s` in `%s`." $album_path .Page.File.Filename }}
{{end}}
</div>

View file

@ -0,0 +1,12 @@
{{/*
Docs: https://hugoblox.com/docs/content/writing-markdown-latex/#embed-documents
Parameters
----------
src : str
Google Docs URL for embedding.
*/}}
<div class="responsive-wrap">
<iframe src="{{ .Get "src" }}" frameborder="0" width="960" height="569" allowfullscreen="true" mozallowfullscreen="true" webkitallowfullscreen="true"></iframe>
</div>

View file

@ -0,0 +1,5 @@
{{/*
Docs: https://hugoblox.com/docs/content/writing-markdown-latex/#highlight-quote
*/}}
<mark>{{ .Inner | markdownify | emojify }}</mark>

View file

@ -0,0 +1,25 @@
{{/*
Docs: https://hugoblox.com/docs/content/writing-markdown-latex/#inline-image
Parameters
----------
name :
Icon name.
pack : default "fas"
Icon pack.
padding_left : default "0"
Left padding.
padding_right : default "1"
Right padding.
*/}}
{{- if (.Get "name") -}}
{{- $icon := .Get "name" -}}
{{- $pack := or (.Get "pack") "fas" -}}
{{- $pack_prefix := $pack -}}
{{- if in (slice "fab" "fas" "far" "fal") $pack -}}
{{- $pack_prefix = "fa" -}}
{{- end -}}
{{- $padding_right := (.Get "padding_right") | default 1 -}}{{/* Defaulting to 1 prevents no spacing when minimizing HTML. */}}
<i class="{{ $pack }} {{ $pack_prefix }}-{{ $icon }} {{with (.Get "padding_left")}}pl-{{.}}{{end}} {{with $padding_right}}pr-{{.}}{{end}} {{if ne (.Get "fixed_width") "false"}}fa-fw{{end}}"></i>
{{- end -}}

View file

@ -0,0 +1,9 @@
{{/*
Docs: https://hugoblox.com/docs/content/writing-markdown-latex/#tags-and-categories
*/}}
<ul class="list-unstyled">
{{ range site.Taxonomies.categories }}
<li><a href="{{.Page.RelPermalink}}">{{.Page.Title}}</a></li>
{{ end }}
</ul>

View file

@ -0,0 +1,21 @@
{{/*
Docs: https://hugoblox.com/docs/content/writing-markdown-latex/#list-child-pages
Parameters
----------
show_summary : bool, default "true"
If "true", show also the summary in addition to the title.
*/}}
{{ $show_summary := ne (.Get "show_summary") "false" }}
{{ if gt (len $.Page.Pages) 0}}
<ul class="list-unstyled">
{{ range $.Page.Pages }}
<li>
{{/* Fallback to filename as title (useful for default Obsidian note structure) */}}
<h5><a href="{{.RelPermalink}}">{{ .LinkTitle | default (title .File.TranslationBaseName) }}</a></h5>
{{if $show_summary | and .Summary}}<p>{{.Summary | plainify | emojify}}</p>{{end}}
</li>
{{end}}
</ul>
{{end}}

View file

@ -0,0 +1,9 @@
{{/*
Docs: https://hugoblox.com/docs/content/writing-markdown-latex/#tags-and-categories
*/}}
<ul class="list-unstyled">
{{ range site.Taxonomies.tags }}
<li><a href="{{.Page.RelPermalink}}">{{.Page.Title}}</a></li>
{{ end }}
</ul>

View file

@ -0,0 +1,5 @@
{{/*
Docs: https://hugoblox.com/docs/content/writing-markdown-latex/#math
*/}}
{{ .Inner }}

View file

@ -0,0 +1,19 @@
{{/*
Docs: https://hugoblox.com/docs/content/writing-markdown-latex/#mention-a-user
Parameters
----------
#0 : positional
User account in Hugo Blox Builder to mention.
*/}}
{{- $username := .Get 0 -}}
{{- $username_url := $username | urlize -}}
{{- $taxonomy := "authors" -}}
{{- $profile_page := site.GetPage (printf "/%s/%s" $taxonomy $username_url) -}}
{{- $name := $profile_page.Title | default ($username|markdownify) -}}
{{- with $profile_page -}}
<a href="{{$profile_page.RelPermalink}}">{{$name}}</a>
{{- else -}}
{{- $name -}}
{{- end -}}

View file

@ -0,0 +1,19 @@
{{/*
Docs: https://hugoblox.com/docs/content/writing-markdown-latex/#toggle-list
Parameters
----------
text :
Spoiler title.
class : optional
Additional class for <details> tag.
style : optional
Additional style for <details> tag.
*/}}
{{- $id := printf "spoiler-%d" .Ordinal -}}
<details class="spoiler {{ .Get "class" }}" {{ with .Get "style" }}style="{{ . | safeCSS }}"{{ end }} id="{{$id}}">
<summary>{{ .Get "text" | markdownify | emojify }}</summary>
<p>{{ .Inner | markdownify | emojify }}</p>
</details>

View file

@ -0,0 +1,11 @@
{{/*
Docs: https://hugoblox.com/docs/content/writing-markdown-latex/#link-to-a-page
Parameters
----------
#0 : positional
URL for the link (if local path, it is relative to the page folder).
#1 : optional, positional
Pass "newtab" as the second argument to open the link in a new tab.
*/}}
<a href="{{ .Get 0 | relURL }}"{{ if len .Params | eq 2 }} target="_blank"{{ end }}>{{ .Inner }}</a>

View file

@ -0,0 +1,51 @@
{{/* Table Shortcode for Hugo Blox Builder. */}}
{{/* Load a CSV table from page dir falling back back to remote URL */}}
{{/* Defaults to expecting a comma-separated CSV with a header row. */}}
{{/*
Docs: https://hugoblox.com/docs/content/writing-markdown-latex/#csv-table
Parameters
----------
src :
Path or url to the csv table. Path is relative to the folder where the shortcode is called.
delimiter : default ","
Field delimiter.
header : default "true"
If "true", the first row is rendered as the header.
caption : optional
Caption for the table.
*/}}
{{ $src := .Get "path" }}
{{ $delimiter := .Get "delimiter" | default "," }}
{{ $useHeaderRow := (eq (lower (.Get "header")) "true") | default true }}
{{ $caption := .Get "caption" }}
{{ $is_remote := strings.HasPrefix $src "http" }}
{{ if not $is_remote }}
{{ $src = path.Join "content" $.Page.File.Dir $src }}
{{ end }}
{{ $rows := getCSV $delimiter $src }}
<table class="table">
{{ if $useHeaderRow }}
{{ $headerRow := index $rows 0 }}
{{ $rows = after 1 $rows }}
<tr> {{ range $headerRow }} <th>{{ . | markdownify | emojify }}</th> {{ end }} </tr>
{{ end }}
{{ range $rows }}
<tr>
{{ range . }}
{{ if (findRE "^\\d+$" .) }}
<td data-table-dtype="number">{{ . }}</td>
{{ else }}
<td data-table-dtype="text">{{ . | markdownify | emojify }}</td>
{{ end }}
{{ end }}
</tr>
{{ end }}
{{ if $caption }}
<caption>{{ $caption | markdownify | emojify }}</caption>
{{ end }}
</table>

View file

@ -0,0 +1,17 @@
{{/*
Docs: https://hugoblox.com/docs/content/writing-markdown-latex/#table-of-contents
Parameters
----------
hide_on : optional
Hide TOC for a certain screen size.
For instance, with `hide_on="xl"`,
the in page TOC only appears when the right sidebar of the book layout is hidden.
show_on : optional
Same as above, but for showing the TOC only on certain screen size.
*/}}
<details class="toc-inpage d-print-none {{with .Get "hide_on"}}d-{{.}}-none{{end}} {{with .Get "show_on"}}d-none d-{{.}}-block{{end}}" open>
<summary class="font-weight-bold">{{ i18n "table_of_contents" }}</summary>
{{ $.Page.TableOfContents }}
</details>

View file

@ -0,0 +1,53 @@
{{/* Video Shortcode for Hugo Blox. */}}
{{/* Load video from page dir falling back to media library at `assets/media/` and then to remote URI. */}}
{{/*
Docs: https://hugoblox.com/docs/content/writing-markdown-latex/#videos
Parameters
----------
src :
Path to file or url for the video file.
If a local file, first it is searched in the page directory, and then in `assets/media/` .
poster : optional
Path or url for the preview image.
Defaults to {src without file extension}.jpg .
If not found, defaults to "".
controls : optional
If present, display video controls, otherwise the video is set to autoplay.
id : optional
Custom id "video-{id}" to associate to the <video> tag.
*/}}
{{ $destination := .Get "src" }}
{{ $video_ext_with_dot := path.Ext (.Get "src") }}
{{ $video_ext := strings.TrimPrefix "." $video_ext_with_dot }}
{{ $video_type := $video_ext }}
{{ $destination_preview := (.Get "poster") | default (replace $destination $video_ext_with_dot ".jpg") }}
{{ $is_remote := strings.HasPrefix $destination "http" }}
{{- $asset := "" -}}
{{- $asset_preview := "" -}}
{{- if not $is_remote -}}
{{- $asset = (.Page.Resources.ByType "video").GetMatch $destination -}}
{{- $asset_preview = (.Page.Resources.ByType "image").GetMatch $destination_preview -}}
{{- if not $asset -}}
{{- $asset = resources.Get (path.Join "media" $destination) -}}
{{- $asset_preview = resources.Get (path.Join "media" $destination_preview) -}}
{{- end -}}
{{ $video_type = $asset.MediaType.SubType }}
{{- end -}}
{{ if $asset }}
{{ $destination = $asset.RelPermalink }}
{{ else }}
{{ $destination = $destination | safeURL }}
{{ end }}
{{ $poster := (.Get "poster") | default "" }}
{{ if $asset_preview }}
{{ $poster = $asset_preview.RelPermalink }}
{{ end }}
<video {{if (.Get "controls")}}controls{{else}}autoplay loop{{end}} {{with $poster}}poster="{{.}}"{{end}} {{ with (.Get "id") }}id="video-{{.|anchorize}}"{{end}}>
<source src="{{$destination}}" type="video/{{$video_type}}">
</video>