Output a non-html page


Hugo documentation says:

Hugo can output content in multiple formats, including calendar events, e-book formats, Google AMP, and JSON search indexes, or any custom text format.

I’m trying to make Hugo build my markdown into “any other text format”, and here is the situation:

  1. I defined the following configuration in config.toml:

    suffixes = [“mc”]

    name = “MyCustom”
    mediaType = “text/mycustom”
    isPlainText = true
    isHTML = false

    page = [“MyCustom”]
    home = [“MyCustom”]

  2. I created a markdown file as a source at content/data.md.

And I’m stuck at the step of creating a template. As far as I understood the docs, I am to create a set of template files, say at the layouts/_default folder.

But what should I write into the template files to have a non-html output? If I write, say {{ .Content }}, the output is HTML, and I can’t find any ways to customize it.

Use hugo --debug, you can see what hugo is looking for.

don’t forget to activate the outputs like this

    home                  = [ "HTML", "ATOM", "JSON"]
    section               = [ "HTML" ]
    page                  = [ "HTML" ]
    taxonomy              = [ "HTML" ]
    taxonomyTerm          = [ "HTML" ]

<I’ve uploaded a condensed version of my site, made an json and atom-feed.
Look how it works.

needed hom.json.json and home.atom.xml in layouts/_default.

repo sample is

Well, still didn’t find a solution. In your json templates you use {{ .Plain }}. It gives, certainly, non-HTML, but still a non-customizable text.

I’m looking for a way to do a pinpoint customization of Titles/Paragraphs/LiteralBlocks/QuoteBlocks and all the other markdown stuff output.

What do you want to do with customizable text??

Well, the big picture is the following:

We have a static documentation bundle we need to render for multiple environments and to multiple formats. One of the formats we need for output - is markdown. A simple markdown, but with resolved Hugo shortcodes. What actually I’m trying to do - is to make Hugo take_source_markdown -> do_the_usual_hugo_transforms -> output_markdown.

Others correct me if I’m wrong, but as far as I know, this is not possible.

You can generate different text files with templates and partials. There are some limits with the builtin functions of hugo - it is not a complete programming language. I used json for exporting page information. Sometimes it is better to change the importing system ;-).

You could try .RawContent instead of .Content: https://gohugo.io/variables/page/#page-variables

raw markdown content without the front matter.

1 Like

.RawContent has hugo shortcodes unresolved, so also doesn`t work.

Hmm. This is ex-hugo, but maybe you could use pandoc on your generated HTML files.