# OG images in Hugo

One partial in the head: auto-OG, or a URL signed during the build.

## Where it plugs in

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`

```go-html-template
{{/*
  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 trap

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.

## What it costs

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.
