I searched a couple of evenings, how to create a csv file with a list of eg. page names.
I didn’t find a clear solution. I have a website generated by Hugo, but I want to create a csv file with a list of page names, What should be added to the Hugo configuration file, what other template files, etc. should be created? So, what are the steps?
Lets create a list of all pages for the current site containing
- page title
- absolute Url
create a basic site in the current directory in subfolder csv
shorthand to create a site with some default content and templates without the need for a theme.
hugo new theme --themesDir . csv
cd csv
tell hugo to create an additional csv file for the “Home Page” only
add this to hugo.toml
[outputs]
home = ['html', 'csv']
create a template that creates our list as csv
create a file layouts/_default/home.csv.csv
with the following content:
Title;Link
{{ range.RegularPagesRecursive }}
{{- .LinkTitle -}};{{- .Permalink }}
{{ end -}}
generate the site and check the result
just call hugo
and check have a look at public/index.csv
which will be:
Title;Link
Post 3;https://example.org/posts/post-3/
Post 2;https://example.org/posts/post-2/
Post 1;https://example.org/posts/post-1/
hint: study the usage of the template delimiters {{- -}}
and {{ }}
to control white space and and newlines
Excelent!!! This is the example I want. Thnx!!!
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.