So hugo convert not support config files?

I am not sure what’s wrong with me when exec the command that as below:

C:\Users\senhui.li\Documents\GitRepos\tmp\hugo-test>hugo convert toYAML -h
toYAML converts all front matter in the content directory
to use YAML for the front matter.

Usage:
  hugo convert toYAML [flags] [args]

Flags:
  -h, --help   help for toYAML

Global Flags:
      --clock string               set the clock used by Hugo, e.g. --clock 2021-11-06T22:30:00.00+09:00
      --config string              config file (default is hugo.yaml|json|toml)
      --configDir string           config dir (default "config")
  -d, --destination string         filesystem path to write files to
  -e, --environment string         build environment
      --ignoreVendorPaths string   ignores any _vendor for module paths matching the given Glob pattern
      --logLevel string            log level (debug|info|warn|error)
      --noBuildLock                don't create .hugo_build.lock file
  -o, --output string              filesystem path to write files to
      --quiet                      build in quiet mode
  -M, --renderToMemory             render to memory (mostly useful when running the server)
  -s, --source string              filesystem path to read files relative from
      --themesDir string           filesystem path to themes directory
      --unsafe                     enable less safe operations, please backup first

C:\Users\senhui.li\Documents\GitRepos\tmp\hugo-test>dir
 驱动器 C 中的卷没有标签。
 卷的序列号是 8063-710E

 C:\Users\senhui.li\Documents\GitRepos\tmp\hugo-test 的目录

2025/05/18  17:26    <DIR>          .
2025/05/18  17:26    <DIR>          ..
2025/05/18  17:26    <DIR>          archetypes
2025/05/18  17:26    <DIR>          assets
2025/05/18  17:26    <DIR>          content
2025/05/18  17:26    <DIR>          data
2025/05/18  17:26                83 hugo.toml
2025/05/18  17:26    <DIR>          i18n
2025/05/18  17:26    <DIR>          layouts
2025/05/18  17:26    <DIR>          static
2025/05/18  17:26    <DIR>          themes
               1 个文件             83 字节
              10 个目录 251,589,152,768 可用字节

C:\Users\senhui.li\Documents\GitRepos\tmp\hugo-test>hugo convert toYAML --unsafe
processing 0 content files

C:\Users\senhui.li\Documents\GitRepos\tmp\hugo-test>hugo convert toYAML --unsafe --config hugo.toml
processing 0 content files

And that found the history topic howto-convert-your-front-matter-from-toml-to-yaml discuss abouth the hugo convert CLI design, seems this CLI just support content files. So is there others needs convert the config synatx to YAML. How do you solved this request.

that’s rarley done by me and in case I use use an online converter eg. https://transform.tools/toml-to-yaml

1 Like

Thats that’s a good idea. And I want know how it work in Hugo native CLI.

I would say no here

Thanks I got it.

If you know a bit of Python you can write a config file converter that you can use for not just Hugo but for any other config files you may encounter. I did it for a project once. I wasn’t able to find it so I must have deleted it.

iirc, I just used the standard yaml and json libraries, and used an extra toml library installed via pip. 99% of the work was just validating file extensions from command line arguments and using the load and dump functions of said libraries.

Probably one of the easiest programming projects I took on at least.

1 Like

Or temporarily place this in a template somewhere:

<pre>
{{ os.ReadFile "hugo.toml" | transform.Remarshal "yaml" }}
</pre>

Note that you’ll lose any comments.

3 Likes

and hugo can do :slight_smile:

  • mkdir /myfolder/toml2yaml

  • cd /myfolder/toml2yaml

  • echo "disableKinds = [ 'rss', 'sitemap', 'taxonomy', 'term']" > hugo.toml

  • create a content adapter in content/_content.gotmpl

    {{ with os.ReadFile "hugo.toml" }}
       {{ $content := dict
           "mediaType" "application/json"
           "value" (. | transform.Remarshal "yaml")}}
       }}
       {{ $resource := dict
          "content" $content
          "path" "hugo.json"
       }}
       {{ $.AddResource $resource }}
    {{ end }}
    
  • change to the folder where you have your toml file you want to convert

  • call

    hugo -s /myfolder/toml2yaml -d $PWD
    

p.s. $PWD is powershell for absolute path of current workdir.

now you have your converted file in your current directory as hugo.json

call me goofball :wink:

1 Like

That’s amazing. There is a saying in Chinese proverbs: “There are always more solutions than difficulties.” Haha

@jmooring By the way, there found this method also not support the files which name is _index.md, So it was by design?

I don’t understand your question.

Sorry, I didn’t explain it clearly. The problem is that when I tried to convert the front matter in the post to YAML format using the following command:

hugo convert toYAML --unsafe
processing 5 content files

After I found that the file front matter in the content directory was not converted which there was it name call _index. md file. Other files can be converted correctly。

I am unable to reproduce the problem as described. I examined all of the markdown files in this content structure:

content/
├── posts/
│   ├── post-1/
│   │   ├── a.jpg
│   │   └── index.md
│   ├── _index.md
│   └── post-2.md
└── _index.md

Yeah, it was seems my mistake use way, I build the code and step on this repo : hugo-forum-topic-54772, Please check it .

Thanks.

Check what? Hugo is behaving as expected.

Haha, I mean check it sure not a bug.

I have already tested this. If you think there’s a bug, then you need to provide a reproducible example.

Ok I got it. Thanks

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.