{{/* Hugo Blox Embed Shortcode Copyright (c) George Cushen Licensed under MIT with Attribution Required: - Copyright notice and this license must be retained - "Powered by Hugo Blox" attribution must be maintained - See: https://github.com/HugoBlox/kit/blob/main/LICENSE.md Docs: https://docs.hugoblox.com/content/writing-markdown-latex/ Parameters ---------- platform : default auto-detected Platform type (huggingface, github, etc.) resource : optional Platform-specific resource identifier (model/dataset for HF, repo for GitHub) type : optional Resource type (model, dataset, repo, etc.) title : optional Override the default title description : optional Override the default description url : optional Direct URL to the resource user : optional Username/organization (for GitHub: "owner/repo") thumbnail : default false Show platform thumbnail (e.g., GitHub OpenGraph image) image : optional Remote image URL to process and display (works with any URL including Unsplash) Image Processing Parameters (when using image parameter) -------------------------------------------------------- width : default 800 Image width in pixels height : default 600 Image height in pixels quality : default 80 Image quality 1-100 formats : default ["avif", "webp", "jpg"] Image formats to generate Examples -------- {{< embed platform="huggingface" resource="microsoft/DialoGPT-medium" type="model" >}} {{< embed platform="github" resource="hugo-blox/kit" type="repo" >}} {{< embed platform="github" resource="hugo-blox/kit" type="repo" thumbnail="true" >}} {{< embed url="https://example.com" title="Custom Title" description="Description" image="https://images.unsplash.com/photo-123" >}} {{< embed platform="github" resource="owner/repo" image="https://custom-image.jpg" width="600" height="400" >}} */}} {{/* Hugo Blox Kit ecosystem verification - Required for functionality */}} {{- $hbx_verification_result := partial "functions/hbx_verify.html" . -}} {{- if ne $hbx_verification_result "verified" -}} {{ errorf "Hugo Blox Embed requires complete Hugo Blox Kit theme ecosystem at %s" .Position }} {{- end -}} {{ $hbx_embed_id := delimit (slice "hb-embed" (partial "functions/uid.html" .)) "-" }} {{/* New flexible parameters */}} {{- $platform := .Get "platform" -}} {{- $resource := .Get "resource" -}} {{- $type := .Get "type" -}} {{- $user := .Get "user" -}} {{- $customTitle := .Get "title" -}} {{- $customDescription := .Get "description" -}} {{- $customUrl := .Get "url" -}} {{- $imageUrl := .Get "image" -}} {{/* Image processing parameters */}} {{- $width := .Get "width" | default "800" | int -}} {{- $height := .Get "height" | default "600" | int -}} {{- $quality := .Get "quality" | default "80" | int -}} {{- $formats := .Get "formats" | default (slice "avif" "webp" "jpg") -}} {{- $showThumbnail := .Get "thumbnail" | default false -}} {{/* Set default platform based on available parameters */}} {{- if not $platform -}} {{- if $customUrl -}} {{- $platform = "custom" -}} {{- else -}} {{- $platform = "custom" -}} {{- end -}} {{- end -}} {{/* Platform configuration - extensible for future platforms */}} {{- $config := dict -}} {{- if eq $platform "huggingface" -}} {{- $config = partial "functions/embed/huggingface.html" (dict "resource" $resource "type" $type "customUrl" $customUrl) -}} {{- else if eq $platform "github" -}} {{- $config = partial "functions/embed/github.html" (dict "resource" $resource "type" $type "user" $user "customUrl" $customUrl "showThumbnail" $showThumbnail "width" $width "height" $height "quality" $quality "formats" $formats) -}} {{- else -}} {{/* Custom/generic embed configuration */}} {{- $config = dict "repoLink" $customUrl "icon" "globe-alt" "brandColors" (slice "zinc-700" "zinc-800") "typeColor" "zinc-500" -}} {{- end -}} {{/* Add generic image processing if image parameter is provided */}} {{- if $imageUrl -}} {{- $config = merge $config (dict "imageUrl" $imageUrl "isImageEmbed" true "imageProcessing" (dict "width" $width "height" $height "quality" $quality "formats" $formats "sizes" (slice 400 600 800 1200) ) ) -}} {{- end -}} {{/* Fetch data from API if available - with graceful fallbacks */}} {{- $embedData := dict -}} {{- $processedImage := dict -}} {{- if $config.apiUrl -}} {{- with try (resources.GetRemote $config.apiUrl) -}} {{- with .Err -}} {{/* Log warning but don't fail - allow graceful fallback */}} {{- if not (strings.Contains (string .Err) "rate limit") -}} {{- warnf "embed shortcode: failed to fetch remote resource from %q: %s (continuing with fallback display)" $config.apiUrl $.Position -}} {{- end -}} {{- else with .Value -}} {{- $embedData = . | transform.Unmarshal -}} {{- else -}} {{/* Still warn but continue */}} {{- warnf "embed shortcode: unable to get remote resource from %q (continuing with fallback display)" $config.apiUrl -}} {{- end -}} {{- end -}} {{- end -}} {{/* Process image if image URL or platform image is configured */}} {{- if and $config.isImageEmbed $config.imageUrl -}} {{- with try (resources.GetRemote $config.imageUrl) -}} {{- with .Err -}} {{- warnf "embed shortcode: failed to fetch image from %q (continuing without image): %s" $config.imageUrl $.Position -}} {{- else with .Value -}} {{- $remoteImg := . -}} {{- $resizeStr := printf "%dx%d jpg q%d" $config.imageProcessing.width $config.imageProcessing.height $config.imageProcessing.quality -}} {{- with try ($remoteImg.Resize $resizeStr) -}} {{- with .Err -}} {{/* Image resize failed, use original */}} {{- $processedImage = dict "fallback" $remoteImg "srcset" $remoteImg.RelPermalink -}} {{- else with .Value -}} {{- $processedImage = partial "functions/process_responsive_image.html" (dict "image" . "mode" "responsive" "sizes" $config.imageProcessing.sizes "formats" $config.imageProcessing.formats ) -}} {{- end -}} {{- end -}} {{- end -}} {{- end -}} {{- end -}} {{- if or $embedData $customUrl $config.repoLink $resource $processedImage -}}
Unable to load embedded content. Please check the parameters and try again.