Blog/Connect Hugo Site
You can connect your Hugo site to AnyPost so that Hugo automatically pulls your generated articles when you build your site. This is possible through content adapters



Note: Keep your API key secure. It provides access to your articles.
We can now set up the content adapter in your Hugo project.
In Hugo content adapters reside in the content directory with each adapter having the name _content.gotmpl
articles:mkdir -p content/articles
This is how your Hugo folder structure should now roughly look:touch content/articles/_content.gotmpl

content/articles/_content.gotmpl and add the following code:{{/* Get remote data from AnyPost API */}} {{ $data := dict }} {{ $url := "YOUR_API_URL_HERE" }} {{ $opts := dict "headers" (dict "Authorization" "Bearer YOUR_API_KEY_HERE") }} {{ with try (resources.GetRemote $url $opts) }} {{ with .Err }} {{ errorf "Unable to get remote resource %s: %s" $url . }} {{ else with .Value }} {{ $data = . | transform.Unmarshal }} {{ else }} {{ errorf "Unable to get remote resource %s" $url }} {{ end }} {{ end }} {{/* Add pages and page resources */}} {{ range $data }} {{/* Add page */}} {{ $content := dict "mediaType" "text/markdown" "value" .content }} {{ $dates := dict "date" (time.AsTime .created_at) }} {{ $page := dict "content" $content "dates" $dates "kind" "page" "path" .slug "title" .title }} {{ $.AddPage $page }} {{ end }}
Important: Replace YOUR_API_URL_HERE and YOUR_API_KEY_HERE with the values you copied fromAnyPost in Step 1.
Create a layout template to display your individual articles:
mkdir -p layouts/articles
touch layouts/articles/page.html
layouts/articles/page.html and add:{{ define "main" }} <article> <h1>{{ .Title }}</h1> <div class="content"> {{ .Content }} </div> </article> {{ end }}
Tip: Customize this template to match your site's design and include additional metadata like publish date, author, or tags.
Test your integration locally:
hugo server -D
Hugo will fetch your articles from AnyPost and generate pages for each one
Visit http://localhost:1313 to see yourAnyPost-generated articles!
Once you've verified everything works locally, you can build your static site:
hugo
All static pages will be in the public/ folder, ready to deploy. Your folder should look something like this:

Add query parameters to your API URL to control pagination and filtering:
{{ $url := "https://your-app.com/api/articles/your-site?limit=50&offset=0" }}
limit — Number of articles to fetch (max 100, default 20)offset — Skip this many articles (for pagination)from — Filter articles from this date (ISO format: 2024-01-01)to — Filter articles until this date (ISO format: 2024-12-31)hugo.toml config file:[markup.goldmark.renderer] unsafe = true
Need help? Reach out to support and we'll get you connected.
Leave your $5,000 monthly agency bills behind. AnyPost automates your content creation and publishing so you can focus on what really matters: growing your business.