How to fill templates in marksdown with different extension?

I am experimenting with a directory based archetype. I would like it to generate a rmd (R Markdown) file which will be rendered through R to a md file. For hugo it should look like a plain md file.
I want to fill in the title and date such as in the markdown template, but the file should be served as raw text.

I was unable to find any information how to expand templates in files with other extensions. At the moment I use the extension md - but now I need to add the file to the ignoreFiles - which is not a problem, though if I would like to share it I would need to manually copy it to a non-md extension.
I thought I could solve it through setting mediaTypes - but I was unable to figure it out.

I wonder if you could help me with that.

In case it’s interesting here’s the repo I’m working at: https://github.com/bdcaf/r-hugo-papercss-template

I’m not sure I completely understand what you’re trying to do, but:

Your config.yaml has an error with mediaTypes. Write it like this:

mediaTypes:
  "text/plain":
    suffixes:
      - rmd

Note the quotes and space between “-” and “rmd”.
Now hugo server serves the rmd files as plain text.

If you want to render md files as plain text as well you can achieve it by:

mediaTypes:
  "text/plain":
    suffixes:
      - md
      - rmd

outputs:
  page:
    - md

outputFormats:
  md:
    mediaType: "text/plain"
    isPlainText: true  # probably doesn't affect anything

And by defining a _default/single.md template with content

{{ .RawContent }}

Note that Hugo still tries to parse the markdown so all your shortcodes need to work.

However I don’t know of any way how to do the reverse - parse rmd files as markdown. There is no “inputFormats” configuration to choose between plain text / html / or markdown parser.

Thanks I will try this settings.
The information in https://gohugo.io/templates/output-formats/ is quite confusing for me. I chose text/plain as it seemed to be the most fitting for markdown.

Unfortunately this didn’t help. Maybe I need to clarify what I want to do.

In R you can generate markdown from a “rmarkdown” template. Usually it has the extension .rmd. (The conversion happens in Makefile line 23).
I want to have an archetype that I currently call r-bundle which contains some code files. In these files - most important source.rmd but also others I would like to have some strings expanded. think title: "{{ humanize .Name | title }}". So that I can create an entry doing hugo new -k r-bundle post/test-post.
Then I call make all_rmd - which will then create the markdown with shortcodes for linking inside the bundle.
For that kind of posts it is common to provide the source code - so ideally I would like to provide the .rmd file.

Currently I have an either-or situation. If I use the extension .md for my source code the short codes will be filled in - but I will need to ignore the “unrendered” source - unfortunately then I will need to trick again to make the plain source downloadable again.
Alternatively I can have the input file as .rmd - but templates will not expand.

Since this is more of a Blogdown question, you’ll probably have better luck posting your question to https://community.rstudio.com/

Edit: Well, I take that back, looks like you’re using something more custom

Am not at my laptop to test, but am curious if you create archetypes/default.rmd and fill it in with the front matter you want, then run

hugo new -k r-bundle post/test-post.rmd

What happens?


If that doesn’t work, my other idea is to write a Makefile function that creates the post the traditional hugo way, then renames it to .rmd

Yeah I didn’t mention. I actually want to learn a more general approach which I then could expand to other languages.

You are right - an archetype .rmd does give me a file where the template pattern are expanded.

I am thinking - while blogdown does not serve my need I could write some external script to fill in my template.

Anyway from the documentation I had the impression hugo might have that already implemented.