One partial in the head: auto-OG, or a URL signed during the build.
Hugo cannot make HTTP requests at build time in any way you would want to rely on — and with this module it does not have to. The partial either points the auto-OG endpoint at the page permalink, with no secret at all, or signs a template URL with Hugo's own `crypto.HMAC`. The image is rendered on the first crawler hit.
layouts/partials/head.html
{{/*
hugo.toml:
[module]
[[module.imports]]
path = "github.com/dziulatex/shareglint-hugo"
[params.shareglint]
account = "acc_..."
Build: HUGO_SHAREGLINT_SIGNING_SECRET=sign_... hugo
*/}}
{{ if .IsPage }}
{{/* A blog-og card signed during the build with crypto.HMAC. */}}
{{ partial "shareglint/og-image.html" (dict
"page" .
"template" "blog-og"
"fields" (dict "title" .Title "author" .Params.author "site" site.Title)
"alt" .Title) }}
{{ else }}
{{/* Auto-OG: /u/acc_....png?url=<permalink> - no secret needed. */}}
{{ partial "shareglint/og-image.html" . }}
{{ end }}
The same thing as one plain HTTP call — no dependency to install.
scripts/og.sh
#!/usr/bin/env bash
set -euo pipefail
# For every post without an og_image field: generate one and write it back.
for file in content/posts/*.md; do
grep -q '^og_image:' "$file" && continue
title=$(grep -m1 '^title:' "$file" | sed 's/^title:[[:space:]]*//; s/^"//; s/"$//')
url=$(curl -sS -X POST "https://shareglint.com/v1/images?wait=true" \
-H "Authorization: Bearer $SHAREGLINT_KEY" \
-H "Content-Type: application/json" \
-d "$(jq -n --arg t "$title" '{template:"blog-og",modifications:{title:$t,site:"yourblog.com"}}')" \
| jq -r .url)
# Append to the front matter, right below the first '---' line.
sed -i "0,/^---$/{s|^---$|---\nog_image: \"$url\"|}" "$file"
echo "$file -> $url"
done
Hugo's `getenv` only reads variables that start with `HUGO_`, so the secret must be called `HUGO_SHAREGLINT_SIGNING_SECRET` — set it in CI, never in `hugo.toml`. Without it the build prints a warning and falls back to the auto-OG URL.
With ?wait=true the finished image arrives on the same connection — usually in about a second.
{
"id": "img_01m08s3ez1zcv28h335g9923bw",
"status": "completed",
"url": "https://cdn.shareglint.com/renders/img_01m08s3ez1zcv28h335g9923bw.png",
"duration_ms": 912
}
A hundred images a month free, then $9 for two thousand. The same post rendered twice returns the existing URL and uses no quota — so rebuilding your site costs nothing.