Serve file as both raw and Markdownized-HTML

As the title states, I would like to serve a page/file as both raw (just text) and Markdown processed into HTML.

My reasoning is that I have some files that I would like to show on the website and I would also like to give the user a “Download this file” link, similar to the “Raw” link for files on Github or Bitbucket.

So far I’ve been fairly unsuccessful. The furthest that I’ve gotten has been that I think it involves a proxy, like so:

page '/file.txt', :layout => 'my_layout', :proxy => '/file.html'

However the ‘layout’ option is ignored and the raw file is still served.

This raised a good question for which is, in Middleman, is there a way to manually define how a page will be processed when defining it via ‘page’? Or if not, is there any other way to achieve my goal?

My understanding is that the processing of a file is quite hard coded, and tied to the file’s suffix.

Do you want the raw files to contain the Markdown codes or not?

If you want them “as is”, including frontmatter and Markdown codes, one approach could be to use after_build to just copy the files into the build directory.

If you want to remove the Markdown coding, you could use the same approach but apply some (regex?) transformations to the text.

There are a lot of things that can go wrong with regex, so another possibility would be to use the built html file, read it with Nokogiri, do the transformations you want (like replacing <p> with newlines) and then save it to a file.

The files are written in Markdown.

I had not thought of using after_build. It should work in my case since I have a small number of files, but it could get annoying if it had to duplicate many of them.

In any case, thanks for the solution.