diff options
Diffstat (limited to 'layouts/shortcodes')
| -rw-r--r-- | layouts/shortcodes/actions.html | 26 | ||||
| -rw-r--r-- | layouts/shortcodes/contact.html | 65 | ||||
| -rw-r--r-- | layouts/shortcodes/div-close.html | 2 | ||||
| -rw-r--r-- | layouts/shortcodes/div.html | 4 | ||||
| -rw-r--r-- | layouts/shortcodes/dropcap.html | 15 | ||||
| -rw-r--r-- | layouts/shortcodes/em.html | 2 | ||||
| -rw-r--r-- | layouts/shortcodes/figure.html | 27 | ||||
| -rw-r--r-- | layouts/shortcodes/gal-img.html | 16 | ||||
| -rw-r--r-- | layouts/shortcodes/gallery.html | 13 | ||||
| -rw-r--r-- | layouts/shortcodes/gravatar.html | 67 | ||||
| -rw-r--r-- | layouts/shortcodes/image.html | 23 | ||||
| -rw-r--r-- | layouts/shortcodes/img.html | 84 | ||||
| -rw-r--r-- | layouts/shortcodes/quote.html | 32 | ||||
| -rw-r--r-- | layouts/shortcodes/strike.html | 2 | ||||
| -rw-r--r-- | layouts/shortcodes/svg.html | 5 | ||||
| -rw-r--r-- | layouts/shortcodes/video.html | 72 |
16 files changed, 187 insertions, 268 deletions
diff --git a/layouts/shortcodes/actions.html b/layouts/shortcodes/actions.html index 296a211..7badab3 100644 --- a/layouts/shortcodes/actions.html +++ b/layouts/shortcodes/actions.html @@ -1,7 +1,19 @@ -{{ $link := .Get "url" }} -{{ $desc := .Get "desc" }} -{{ $outclass := .Get "outclass" }} -{{ $inclass := .Get "inclass" }} -<ul class="actions{{ with $outclass }} {{ . }}{{ end }}"> - <li><a href="{{ $link }}" class="button{{ with $inclass }} {{ . }}{{ end }}">{{ $desc }}</a></li> -</ul> +{{- $url := .Get "url" -}} +{{- $desc := .Get "desc" | default "Download" -}} +{{- $outclass := .Get "outclass" | default "" -}} +{{- $inclass := .Get "inclass" | default "" -}} + +{{- if $url -}} +<div class="my-6 {{ $outclass }}"> + <a + href="{{ $url }}" + class="inline-flex items-center gap-2 px-4 py-2 rounded border border-accent/30 text-accent font-medium hover:border-accent/50 hover:bg-accent/10 transition-colors {{ $inclass }}" + download + > + <i data-feather="download" class="w-4 h-4"></i> + {{ $desc }} + </a> +</div> +{{- else -}} + {{- errorf "actions shortcode: 'url' parameter is required" -}} +{{- end -}} diff --git a/layouts/shortcodes/contact.html b/layouts/shortcodes/contact.html new file mode 100644 index 0000000..6c5748f --- /dev/null +++ b/layouts/shortcodes/contact.html @@ -0,0 +1,65 @@ +<form id="contact-form" x-data="contactForm()" @submit.prevent="submitContactForm" class="space-y-6"> + <!-- Name Field --> + <div> + <label for="name" class="block text-sm font-medium text-text mb-2"> + {{ i18n "name" }} + </label> + <input + id="name" + type="text" + x-model="formData.name" + required + class="w-full px-4 py-2 bg-bg border border-border/50 rounded-lg text-text placeholder-text-dim focus:outline-none focus:border-accent focus:ring-1 focus:ring-accent transition-colors" + :aria-busy="isSubmitting" + /> + </div> + + <!-- Email Field --> + <div> + <label for="email" class="block text-sm font-medium text-text mb-2"> + {{ i18n "email" }} + </label> + <input + id="email" + type="email" + x-model="formData.email" + required + class="w-full px-4 py-2 bg-bg border border-border/50 rounded-lg text-text placeholder-text-dim focus:outline-none focus:border-accent focus:ring-1 focus:ring-accent transition-colors" + :aria-busy="isSubmitting" + /> + </div> + + <!-- Message Field --> + <div> + <label for="message" class="block text-sm font-medium text-text mb-2"> + {{ i18n "message" }} + </label> + <textarea + id="message" + x-model="formData.message" + rows="5" + required + class="w-full px-4 py-2 bg-bg border border-border/50 rounded-lg text-text placeholder-text-dim focus:outline-none focus:border-accent focus:ring-1 focus:ring-accent transition-colors resize-none" + :aria-busy="isSubmitting" + ></textarea> + </div> + + <!-- Status Message --> + <div + x-show="statusMessage" + x-text="statusMessage" + :class="statusClass" + class="px-4 py-3 rounded-lg text-sm transition-all" + ></div> + + <!-- Submit Button --> + <button + type="submit" + :disabled="isSubmitting" + class="w-full px-4 py-2 bg-accent text-bg font-medium rounded-lg hover:bg-accent/90 disabled:opacity-50 disabled:cursor-not-allowed transition-colors" + > + <span x-show="!isSubmitting">{{ i18n "submit" }}</span> + <span x-show="isSubmitting">{{ i18n "sending" }}</span> + </button> +</form> + diff --git a/layouts/shortcodes/div-close.html b/layouts/shortcodes/div-close.html deleted file mode 100644 index ea7e47c..0000000 --- a/layouts/shortcodes/div-close.html +++ /dev/null @@ -1,2 +0,0 @@ -</div> - diff --git a/layouts/shortcodes/div.html b/layouts/shortcodes/div.html deleted file mode 100644 index 0c0b755..0000000 --- a/layouts/shortcodes/div.html +++ /dev/null @@ -1,4 +0,0 @@ -{{ if .Get "class" }} -<div class="{{ with .Get "class" }}{{ . }}{{ end }}"> -{{ end }} - diff --git a/layouts/shortcodes/dropcap.html b/layouts/shortcodes/dropcap.html index 80cbefe..6114678 100644 --- a/layouts/shortcodes/dropcap.html +++ b/layouts/shortcodes/dropcap.html @@ -1,14 +1 @@ -{{/* - * The dropcap shortcode: - * - * Usage: - * - * {{< dropcap class="some class" >}} - * your paragraph that will have a drop cap here - * {{< /dropcap >}} - * - */}} - -<p class="has-dropcap {{ with .Get "class"}}{{.}}{{ end }}"> - {{ .InnerDeindent }} -</p> +<span class="text-2xl font-bold first-letter:text-3xl">{{ .Inner }}</span> diff --git a/layouts/shortcodes/em.html b/layouts/shortcodes/em.html index 11f399a..a3a096c 100644 --- a/layouts/shortcodes/em.html +++ b/layouts/shortcodes/em.html @@ -1 +1 @@ -<mark>{{ .Inner | markdownify }}</mark> +<em>{{ .Inner }}</em> diff --git a/layouts/shortcodes/figure.html b/layouts/shortcodes/figure.html deleted file mode 100644 index 4cf2e7b..0000000 --- a/layouts/shortcodes/figure.html +++ /dev/null @@ -1,27 +0,0 @@ -{{/* - * This version of the figure shortcode needs to be closed and doesn't - * add an image itself, but relies on the img.html shortcode to provide - * a responsive image instead. - */}} -<figure{{ with .Get "class" }} class="{{ . }}"{{ end }}> - {{- if .Get "link" -}} - <a href="{{ .Get "link" }}"{{ with .Get "target" }} target="{{ . }}"{{ end }}{{ with .Get "rel" }} rel="{{ . }}"{{ end }}> - {{- end -}} - {{.InnerDeindent}} - {{- if .Get "link" }}</a>{{ end -}} - {{- if or (or (.Get "title") (.Get "caption")) (.Get "attr") -}} - <figcaption> - {{ with (.Get "title") -}} - <h4>{{ . }}</h4> - {{- end -}} - {{- if or (.Get "caption") (.Get "attr") -}}<p> - {{- .Get "caption" | markdownify -}} - {{- with .Get "attrlink" }} - <a href="{{ . }}"> - {{- end -}} - {{- .Get "attr" | markdownify -}} - {{- if .Get "attrlink" }}</a>{{ end }}</p> - {{- end }} - </figcaption> - {{- end }} -</figure> diff --git a/layouts/shortcodes/gal-img.html b/layouts/shortcodes/gal-img.html deleted file mode 100644 index ae7d23e..0000000 --- a/layouts/shortcodes/gal-img.html +++ /dev/null @@ -1,16 +0,0 @@ -{{- $src := .Get "src" -}} -{{- $source := resources.Get $src -}} -{{- $alt := .Get "alt" -}} -{{- $caption := .Get "caption" -}} -{{- $location := .Get "location" -}} -{{- $fullsize := $source -}} -{{- $thumb := $source.Resize "400x webp" -}} -<figure class="photo-card" - data-photo-index="{{ .Ordinal }}" - data-src="{{ $fullsize.RelPermalink }}" - data-alt="{{ $alt }}" - data-caption="{{ $caption }}" - data-location="{{ $location }}"> - <img src="{{ $thumb.RelPermalink }}" alt="{{ $alt }}" loading="lazy"> - {{ with $caption }}<figcaption>{{ . }}</figcaption>{{ end }} -</figure> diff --git a/layouts/shortcodes/gallery.html b/layouts/shortcodes/gallery.html index f9e546e..b66c327 100644 --- a/layouts/shortcodes/gallery.html +++ b/layouts/shortcodes/gallery.html @@ -1,3 +1,12 @@ -<div class="photo-grid" data-lightbox="true"> - {{ .Inner }} +{{- $cols := .Get "cols" | default "2" -}} + +<div class="my-8 grid gap-4" style="grid-template-columns: repeat({{ $cols }}, 1fr)"> + {{- range $line := strings.Split .Inner "\n" -}} + {{- if strings.Contains $line "![" -}} + {{- $image := strings.TrimSpace $line -}} + {{- if $image -}} + {{ $image | markdownify | safeHTML }} + {{- end -}} + {{- end -}} + {{- end -}} </div> diff --git a/layouts/shortcodes/gravatar.html b/layouts/shortcodes/gravatar.html index 56e2514..3a1ebcc 100644 --- a/layouts/shortcodes/gravatar.html +++ b/layouts/shortcodes/gravatar.html @@ -1,52 +1,17 @@ -{{/* - * The gravatar shortcode: - * All arguments are optional, main ones are mail and size and have a fallback set in place. - * Args: - * mail: [string] The email address. Falls back to .Site.Params.author_email which should be set in your config file. - * size: [int] The size of the fetched image. Defaults to 200 if not set. - * class: [string] The class to give to the figure block. - * link: [string] The address to link the picture to. - * target: [string] Where to open the link. One of "_blank", "_self", "_parent", "_top". - * caption: [string] Caption text to show with the image. Supports Markdown. - * - * Usage: - * {{< gravatar mail="some@address.com" size=150 class="some class" link="https://example.com" target="_blank" rel="author" caption="Here's a picture of a dog." >}} - * - * Output: - * <figure class="some class"> - * <a href="https://example.com" target="_blank" rel="author"> - * <img src="https://www.gravatar.com/avatar/emailhash?s=150" alt="Here's a picture of a dog." /> - * </a> - * <figcaption> - * <p> - * Here's a picture of a dog. - * </p> - * </figcaption> - * </figure> - * - */}} +{{- $email := .Get "email" -}} +{{- $size := .Get "size" | default "256" | int -}} +{{- $alt := .Get "alt" | default "User avatar" -}} +{{- $class := .Get "class" | default "w-32 h-32 rounded-full" -}} -{{- $mailhash := $.Site.Params.author_email -}} -{{- if .Get "mail" -}}{{- $mailhash = .Get "mail" -}}{{- end -}} -{{- $hash := $mailhash | lower | md5 -}} - -<figure{{ with .Get "class" }} class="{{ . }}"{{ end }}> -{{- if .Get "link" -}} - <a href="{{ .Get "link" }}"{{ with .Get "target" }} target="{{ . }}"{{ end }}{{ with .Get "rel" }} rel="{{ . }}"{{ end }}> -{{- end }} - <img src="https://www.gravatar.com/avatar/{{- $hash -}}?s={{- with .Get "size" }}{{.}}{{ else }}200{{ end }}" - {{- if or (.Get "alt") (.Get "caption") }} - alt="{{ with .Get "alt" }}{{ . }}{{ else }}{{ .Get "caption" | markdownify| plainify }}{{ end }}" - {{- end -}} - /> -{{- if .Get "link" -}} - </a> -{{- end }} -{{- if .Get "caption" -}} - <figcaption> - <p> - {{- .Get "caption" | markdownify -}} - </p> - </figcaption> -{{- end }} -</figure> +{{- if $email -}} + {{- $hash := md5 (strings.TrimSpace (strings.ToLower $email)) -}} + {{- $gravatarURL := printf "https://www.gravatar.com/avatar/%s?s=%d&d=identicon" $hash $size -}} + <img + src="{{ $gravatarURL }}" + alt="{{ $alt }}" + class="{{ $class }}" + loading="lazy" + /> +{{- else -}} + {{- errorf "gravatar shortcode: 'email' parameter is required" -}} +{{- end -}} diff --git a/layouts/shortcodes/image.html b/layouts/shortcodes/image.html new file mode 100644 index 0000000..84dec3f --- /dev/null +++ b/layouts/shortcodes/image.html @@ -0,0 +1,23 @@ +{{- $src := .Get "src" -}} +{{- $alt := .Get "alt" | default "Image" -}} +{{- $caption := .Get "caption" -}} +{{- $class := .Get "class" | default "w-full h-auto rounded-lg border border-border" -}} +{{- $link := .Get "link" -}} +{{- $figureClass := .Get "figure-class" -}} + +{{- if or $src .Inner -}} + <figure class="my-8{{- with $figureClass }} {{ . }}{{- end -}}"> + {{- if .Inner -}} + {{- .Inner -}} + {{- else -}} + {{- if $link -}}<a href="{{ $link }}">{{- end -}} + <img src="{{ $src }}" alt="{{ $alt }}" class="{{ $class }}" loading="lazy" /> + {{- if $link -}}</a>{{- end -}} + {{- end -}} + {{- if $caption -}} + <figcaption class="mt-3 text-center text-sm text-text-dim italic">{{ $caption }}</figcaption> + {{- end -}} + </figure> +{{- else -}} + {{- errorf "image shortcode: 'src' parameter or inner content is required" -}} +{{- end -}} diff --git a/layouts/shortcodes/img.html b/layouts/shortcodes/img.html deleted file mode 100644 index fbf96c0..0000000 --- a/layouts/shortcodes/img.html +++ /dev/null @@ -1,84 +0,0 @@ -{{/* - Taken from https://www.brycewray.com/posts/2022/06/responsive-optimized-images-hugo/ -*/}} - -{{- $respSizes := .Site.Params.imageSizes -}} -{{- $src := .Get "src" -}} -{{- $source := resources.Get $src -}} -{{- $alt := .Get "alt" -}} -{{- $divClass := .Get "divClass" -}} -{{/* - The styling in $imgClass, below, makes - an image fill the container horizontally - and adjust its height automatically - for that, and then fade in for the LQIP effect. - Feel free to adjust your CSS/SCSS as desired. -*/}} -{{- $imgClass := "animate-fade" -}} -{{- $dataSzes := "(min-width: 1024px) 100vw, 50vw" -}} -{{/* - Now we'll create the 20-pixel-wide LQIP - and turn it into Base64-encoded data, which - is better for performance and caching. -*/}} -{{- $LQIP_img := $source.Resize "20x jpg" -}} -{{- $LQIP_b64 := $LQIP_img.Content | base64Encode -}} -{{/* - $CFPstyle is for use in styling - the div's background, as you'll see shortly. -*/}} -{{- $CFPstyle := printf "%s%s%s%v%s" "background: url(data:image/jpeg;base64," $LQIP_b64 "); background-size: cover; background-repeat: no-repeat; width: " $source.Width "px;" -}} -{{/* - Then, we create a 640-pixel-wide JPG - of the image. This will serve as the - "fallback" image for that tiny percentage - of browsers that don't understand the - HTML `picture` tag. -*/}} -{{- $actualImg := $source.Resize "640x jpg" -}} -<div class="picture{{with $divClass}} {{.}}{{end}}" style="{{ $CFPstyle | safeCSS }}"> -{{/* - Now we'll build the `picture` which modern - browsers use to decide which image, and - which format thereof, to show. Remember to - put `webp` first, since the browser will use - the first format it **can** use, and WebP files - usually are smaller. After WebP, the fallback - is the universally safe JPG format. -*/}} - <a href="{{ $source.RelPermalink }}"> - <picture> - <source - type="image/webp" - srcset=" - {{- with $respSizes -}} - {{- range $i, $e := $respSizes -}} - {{- if ge $source.Width . -}} - {{- if $i }}, {{ end -}}{{- ($source.Resize (printf "%vx%v" $e " webp") ).RelPermalink }} {{ . }}w - {{- end -}} - {{- end -}} - {{- end -}}" - sizes="{{ $dataSzes }}" - /> - <source - type="image/jpeg" - srcset=" - {{- with $respSizes -}} - {{- range $i, $e := . -}} - {{- if ge $source.Width . -}} - {{- if $i }}, {{ end -}}{{- ($source.Resize (printf "%vx%v" . " jpg") ).RelPermalink }} {{ . }}w - {{- end -}} - {{- end -}} - {{- end -}}" - sizes="{{ $dataSzes }}" - /> - <img class="{{ $imgClass }}" - src="{{ $actualImg.RelPermalink }}" - width="{{ $source.Width }}" - height="{{ $source.Height }}" - alt="{{ $alt }}" - loading="lazy" - /> - </picture> - </a> -</div> diff --git a/layouts/shortcodes/quote.html b/layouts/shortcodes/quote.html index 05d0c94..1ed5c3c 100644 --- a/layouts/shortcodes/quote.html +++ b/layouts/shortcodes/quote.html @@ -1,19 +1,15 @@ -<blockquote class="blockquote"> - <p> - {{.Inner}} - </p> - {{ if .Get "source" }} - <footer class="blockquote-footer"> - <cite title="by: {{ with .Get "source"}}{{.}}{{ end }}"> - {{ with .Get "src"}} - by - <a href="{{.}}" target="_blank" rel="noopener noreferrer"> - {{ end }} - {{ with .Get "source" }}{{.}}{{ end }} - {{ with .Get "src"}} - </a> - {{ end }} - </cite> - </footer> - {{ end }} +{{- $source := .Get "source" -}} +{{- $src := .Get "src" -}} + +<blockquote class="my-8 pl-6 border-l-4 border-accent/50 italic text-text-dim"> + <p class="text-lg">{{ .Inner }}</p> + {{- if $source -}} + <footer class="mt-4 text-sm not-italic text-text-dim"> + {{- if $src -}} + — <a href="{{ $src }}" class="text-accent hover:underline">{{ $source }}</a> + {{- else -}} + — {{ $source }} + {{- end -}} + </footer> + {{- end -}} </blockquote> diff --git a/layouts/shortcodes/strike.html b/layouts/shortcodes/strike.html index 415036a..275b7c1 100644 --- a/layouts/shortcodes/strike.html +++ b/layouts/shortcodes/strike.html @@ -1 +1 @@ -<strike>{{ .Inner | markdownify }}</strike> +<s>{{ .Inner }}</s> diff --git a/layouts/shortcodes/svg.html b/layouts/shortcodes/svg.html deleted file mode 100644 index d042bb0..0000000 --- a/layouts/shortcodes/svg.html +++ /dev/null @@ -1,5 +0,0 @@ -<span class="inline-svg{{ with .Get "class" }} {{ . }}{{ end }}"> -{{- $fname := print "SVGs/" ( .Get "name" ) ".svg" -}} -{{ $icon := resources.Get $fname }} -{{ $icon.Content | safeHTML }} -</span> diff --git a/layouts/shortcodes/video.html b/layouts/shortcodes/video.html index aa30a13..1e2645d 100644 --- a/layouts/shortcodes/video.html +++ b/layouts/shortcodes/video.html @@ -1,37 +1,37 @@ -{{/* - * The video shortcode: - * All arguments are optional, except for src which is where you define your video file - * This shortcode supports webm, mp4, and other HTML5 video formats. - * Args: - * src: [string] Path to video file (required) - * class: [string] The class(es) to give to the video block. - * width: [int] The width of the video - * height: [int] The height of the video - * autoplay: [bool] true or false for autoplay - defaults to false - * loop: [bool] true or false for loop - defaults to false - * muted: [bool] true or false for mute - defaults to false - * - * Usage: - * {{< video src="my-video.mp4" width=600 height=400 autoplay=true loop=true muted=true class="responsive-video" >}} - * - * Output: - * <video class="responsive-video" controls preload="auto" width="600" height="400" autoplay loop muted playsinline> - * <source src="my-video.mp4" type="video/mp4"> - * </video> - * - */}} +{{- $src := .Get "src" -}} +{{- $id := .Get "id" -}} +{{- $title := .Get "title" | default "Video" -}} +{{- $class := .Get "class" | default "" -}} -{{ $ext := (.Get "src") | path.Ext }} -{{ $filetype := slicestr $ext 1}} - -<video{{ with .Get "class" }} class="{{ . }}"{{ end }} - controls - preload="auto" - {{ with .Get "width" }}width="{{.}}"{{ end }} - {{ with .Get "height" }}height="{{.}}"{{ end }} - {{ if eq (.Get "autoplay") "true" }}autoplay {{ end }} - {{ if eq (.Get "loop") "true" }}loop {{ end }} - {{ if eq (.Get "muted") "true" }}muted {{ end }} - playsinline > - <source src="{{ ( .Get "src" ) }}" type="video/{{ $filetype }}"> -</video> +{{- if $id -}} + <div class="my-6{{- with $class }} {{ . }}{{- end -}}"> + <iframe + class="w-full aspect-video" + src="https://www.youtube.com/embed/{{ $id }}" + title="{{ $title }}" + allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" + allowfullscreen + ></iframe> + </div> +{{- else if $src -}} + {{- $ext := $src | path.Ext -}} + {{- $filetype := slicestr $ext 1 -}} + {{- $videoURL := $src -}} + {{- $resource := .Page.Resources.GetMatch $src -}} + {{- if $resource -}}{{- $videoURL = $resource.RelPermalink -}}{{- end -}} + <video + {{- with $class }} class="{{ . }}"{{ end }} + controls + preload="auto" + playsinline + {{- with .Get "width" }} width="{{ . }}"{{ end }} + {{- with .Get "height" }} height="{{ . }}"{{ end }} + {{- if eq (.Get "autoplay") "true" }} autoplay{{ end }} + {{- if eq (.Get "loop") "true" }} loop{{ end }} + {{- if eq (.Get "muted") "true" }} muted{{ end }} + > + <source src="{{ $videoURL }}" type="video/{{ $filetype }}"> + </video> +{{- else -}} + {{- errorf "video shortcode: either 'src' or 'id' parameter is required" -}} +{{- end -}} |
