Missing something on output formats

#1

Hi there,

Only recently using Hugo but really appreciate speed, design and ease of use so far! I am struggling with one particular bit though. I did read the documentation many times and scouted this forum for similar topics but nothing seems to apply.

  • A site is deployed to Netlify and I want to provide support for NetlifyCMS which allows users to add/edit pages from Netlify user interface
  • This requires creating 2 files in the /admin folder of the generated static site, that is /public/admin/index.html and /public/admin/config.yml
  • /public/admin/index.html is purely static and I can simply add it to /content/admin/index.html (I could also use /static/… for that)
  • /public/admin/config.yml however has a few elements that needs to be taken from the Hugo site root config.yml file

And so the config.yml file should be built like a page, using go templates and variables from the .Site config. Example:

  # Netlify CMS configuration for use with ClearStatus backend:
  name: git-gateway
  branch: {{ .Site.Params.repoBranch }}

Output formats should do that fine but it’s not working for me now. Here is what I’ve done:

  • Created /content/admin/config.md with only front matter:
    ---
    title: "Netlify config file"
    date: 2019-04-11
    outputs:
      - netlifyyaml
    ---
  • In root hugo config.yml, added:
    mediaTypes:
      application/netlifyconfig:
        suffixes:
          - "yml"

    outputFormats:
      netlifyyaml:
        isPlainText: true
        isHTML: false
        mediaType: "application/netlifyconfig"
        notAlternative: true

  • in /layouts/admin, I added a template called single.netlifyyaml.yml

Now when I run hugo on this configuration:

  • /public/admin/index.html is copied as is from /content/admin/index.html as expected
  • BUT: the /public/admin/config.yml is NOT created.

Other details:

  • the template single.netlifyyaml.yml seems to be used/parsed because if I voluntarily introduce an error in it, Hugo stops and output the error
  • I also tried adding the template to /layouts/_default/single.netlifyyaml.yml, /public/admin/config.yml is not created.

Any pointer?

Many thanks

0 Likes

#2

Hi again,

So I finally got this work, with a bit of luck actually. Here is what worked:

  1. In the source folder, /content/admin/ you cannot mix dynamic content and static content.

Initially, I had both config.md and index.html in /content/admin. It appears having that static file there blocks processing of the config.md file. As soon as I removed index.html from the source content, the other file, config.md started to be processed and appear in the output.

So you really want to have all your static content in the /static folder.

  1. Having single.netlifyyaml.yml in /layouts/admin does not work. It needs to be located in /layouts/_default.

After applying those changes to the configuration described in my first post, I do get a /public/admin/config.yml file with dynamic content taken out of the site root config.yml file :slight_smile:

0 Likes