diff --git a/assets/css/_shortcodes/_cardlink.scss b/assets/css/_shortcodes/_cardlink.scss index 7df2e127..25287013 100644 --- a/assets/css/_shortcodes/_cardlink.scss +++ b/assets/css/_shortcodes/_cardlink.scss @@ -76,11 +76,19 @@ white-space: nowrap; } - &icon-globe { + &icon-shortcut { width: 4rem; height: 4rem; flex-shrink: 0; margin-left: 0.25rem; + + &:is(i) { + text-align: center; + font-size: 3rem; + display: inline-flex; + align-items: center; + justify-content: center; + } } [data-theme='dark'] & { diff --git a/layouts/partials/function/get-remote-image.html b/layouts/partials/function/get-remote-image.html index 6ba346ba..9881f76a 100644 --- a/layouts/partials/function/get-remote-image.html +++ b/layouts/partials/function/get-remote-image.html @@ -1,10 +1,13 @@ {{- /* cache remote image locally */ -}} {{- $resource := 0 -}} {{- $suffixList := slice ".jpeg" ".jpg" ".png" ".gif" ".bmp" ".tif" ".tiff" ".webp" ".avif" ".svg" -}} -{{- $suffixValid := (dict "Path" . "Suffixes" $suffixList | partial "function/suffix-validation.html") -}} +{{- $suffixValid := (dict "Path" .Path "Suffixes" $suffixList | partial "function/suffix-validation.html") -}} +{{- /* maybe could add domain validation */ -}} +{{- $pass := $suffixValid | or .Pass -}} -{{- if $suffixValid -}} - {{- with $remoteResource := resources.GetRemote . -}} +{{- if $pass -}} + {{- with $remoteResource := resources.GetRemote .Path -}} + {{ printf "Remote image: %v" $remoteResource.ResourceType -}} {{- with .Err -}} {{- warnf "%s" . -}} {{ else }} diff --git a/layouts/partials/function/resource.html b/layouts/partials/function/resource.html index 6f7c9919..755c1eb8 100644 --- a/layouts/partials/function/resource.html +++ b/layouts/partials/function/resource.html @@ -15,7 +15,7 @@ {{- else -}} {{- $cacheRemoteImages := .CacheRemoteImages | default false -}} {{- if $cacheRemoteImages -}} - {{- $resource = partial "function/get-remote-image.html" .Path -}} + {{- $resource = partial "function/get-remote-image.html" (dict "Path" .Path) -}} {{- end -}} {{- end -}} diff --git a/layouts/partials/plugin/link.html b/layouts/partials/plugin/link.html index e853a72f..02857fb2 100644 --- a/layouts/partials/plugin/link.html +++ b/layouts/partials/plugin/link.html @@ -4,7 +4,8 @@ {{- if eq .Noreferrer false -}} {{- $noreferrer = false -}} {{- end -}} -{{- if (urls.Parse .Destination).Host | or .Newtab -}} +{{- $url := urls.Parse .Destination -}} +{{- if $url.IsAbs | or .Newtab -}} {{- $rel = cond $noreferrer "external nofollow noopener noreferrer" "external nofollow" -}} {{- $external = true -}} {{- end -}} @@ -40,7 +41,17 @@ {{- dict "Class" "fa-solid fa-download fa-fw ms-1 text-secondary" | partial "plugin/icon.html" -}} {{- end -}} {{- else -}} - + {{- $cardIcon := .CardIcon -}} + {{- if $url.Host | and (eq $cardIcon "") -}} + {{- $favicon := partial "function/get-remote-image.html" (dict "Path" (add "https://www.google.com/s2/favicons?sz=64&domain=" $url.Host) "Pass" true) -}} + {{- if $favicon -}} + {{- $cardIcon = $favicon.RelPermalink -}} + {{- end -}} + {{- end -}} + + {{- $attrs := `class="cl-backdrop"` -}} + {{- $attrs = printf ` style="--cl-bg-url: url(%v);"` (resources.Get "images/fixit.svg" | minify).RelPermalink | add $attrs -}} + @@ -59,9 +70,17 @@ {{- if .Download -}} - + {{- else -}} - + {{- with $cardIcon -}} + {{- if (strings.HasPrefix . "fa") -}} + + {{- else -}} + card icon + {{- end -}} + {{- else -}} + + {{- end -}} {{- end -}} {{- end -}} diff --git a/layouts/shortcodes/link.html b/layouts/shortcodes/link.html index 10c20ed9..061b5174 100644 --- a/layouts/shortcodes/link.html +++ b/layouts/shortcodes/link.html @@ -10,11 +10,13 @@ {{- $options = dict "Rel" (.Get "rel") | merge $options -}} {{- $options = dict "Download" (.Get "download") | merge $options -}} {{- $options = dict "Card" (.Get "card") | merge $options -}} + {{- $options = dict "CardIcon" (.Get "card-icon") | merge $options -}} {{- $options = dict "Noreferrer" (.Get "noreferrer") | merge $options -}} {{- else -}} {{- $options = dict "Content" (.Get 1 | default (.Get 0)) | merge $options -}} {{- $options = dict "Title" (.Get 2) | merge $options -}} {{- $options = dict "Card" (.Get 3) | merge $options -}} + {{- $options = dict "CardIcon" (.Get 4) | merge $options -}} {{- end -}} {{- $options = dict "ExternalIcon" (.Get "external-icon" | default .Site.Params.externalIcon) | merge $options -}} {{- partial "plugin/link.html" $options -}}