Render custom data file based on page meta data

Trying to render a data file based on meta date in each page (e.g. tags, etc) that I can use to update data in a database.

I have tried creating a standalone page that would essentially do this, however I don’t want this file exposed on the site itself.

I imagine the file would generate during the site building process.

Thanks

Hi there,

I’m not sure I understand what you want to do. Do you have an example site setup with what you are trying?

Let’s say you have a recipe site with params in the header of the page markdown like this

Ingredients:

  • 1 lb of beef

  • 3 tsp of curry

I want to grab this data from each page and put it in a file, so I can update a secondary data store, preliminary for API use cases.

Bryan

I want content creators to only have to enter markdown in order to update an API.

Make sense?

Bryan

Have a read about Output Formats as well as this forum topic.

Not familiar with these feature

I’ll take a look

Mainly looking for a site map but with tags

Bryan

Found an article.

https://bart.degoe.de/use-hugo-output-formats-to-generate-lunr-index-files/

Oversimplified gist of the article is…
First, modify config.toml.

[outputs]
    home = ["HTML", "JSON"]

Then add file layouts/index.json.
(Note, I’m just trying to get “page” kind of resources.)

[
{{- $pages := .Site.Pages -}}
{{- $last := "" -}}
{{- range (last 1 $pages) -}}
    {{- $last = .RelPermalink -}}
{{- end -}}
{{- range $page := $pages -}}
    {{- if eq .Kind "page" }}
    {
        "title": "{{ .Title }}",
        "section": "{{ .Section }}",
        "link": "{{ .RelPermalink }}",
        "type": "{{ .Type }}",
        "words": {{ .WordCount }}
    }
    {{- if ne $last .RelPermalink -}},{{- end }}
    {{- end -}}
{{- end }}
]

Lastly, get generated file via
http://localhost:1313/index.json