From 9cfc07565c224e42e37578c5fcd25c40ad19cfa5 Mon Sep 17 00:00:00 2001 From: MaikelChan Date: Sat, 13 Jan 2024 01:24:45 +0100 Subject: [PATCH] New way to generate UIDs. --- layouts/partials/functions/uid.html | 13 +++++++++++++ layouts/shortcodes/carousel.html | 2 +- layouts/shortcodes/chart.html | 2 +- layouts/shortcodes/gallery.html | 3 +-- layouts/shortcodes/github.html | 2 +- layouts/shortcodes/gitlab.html | 2 +- layouts/shortcodes/typeit.html | 2 +- 7 files changed, 19 insertions(+), 7 deletions(-) create mode 100644 layouts/partials/functions/uid.html diff --git a/layouts/partials/functions/uid.html b/layouts/partials/functions/uid.html new file mode 100644 index 00000000..f4269dc4 --- /dev/null +++ b/layouts/partials/functions/uid.html @@ -0,0 +1,13 @@ +{{ $uid := .Page.RelPermalink }} +{{ $ctx := . }} + +{{ range seq 16 }} + {{ with $ctx }} + {{ $uid = printf "%s-%d" $uid .Ordinal }} + {{ $ctx = .Parent }} + {{ else }} + {{ break }} + {{ end }} +{{ end }} + +{{ return md5 $uid }} \ No newline at end of file diff --git a/layouts/shortcodes/carousel.html b/layouts/shortcodes/carousel.html index 97e51696..ccfb4595 100644 --- a/layouts/shortcodes/carousel.html +++ b/layouts/shortcodes/carousel.html @@ -1,4 +1,4 @@ -{{ $id := delimit (slice "carousel" .Ordinal now.UnixNano) "-" }} +{{ $id := delimit (slice "carousel" (partial "functions/uid.html" .)) "-" }} {{ $aspect := default "16-9" (.Get "aspectRatio") }} {{ $images := .Page.Resources.Match (.Get "images") }} {{ $interval := default "2000" (.Get "interval") }} diff --git a/layouts/shortcodes/chart.html b/layouts/shortcodes/chart.html index 82c92aad..1e172753 100644 --- a/layouts/shortcodes/chart.html +++ b/layouts/shortcodes/chart.html @@ -1,4 +1,4 @@ -{{ $id := delimit (slice "chart" .Ordinal now.UnixNano) "-" }} +{{ $id := delimit (slice "chart" (partial "functions/uid.html" .)) "-" }}