Change default content type for previewing site with "nanoc view"

101 Views Asked by At

I generate HTML files without any filetype extension with the following route in nanoc’s Rules file:

route '/blog/*/' do
  item.identifier.chop
end

So the file /content/blog/hello-world.html gets generated as /output/blog/hello-world, leading to the URL path /blog/hello-world.

When using nanoc’s built-in preview server (nanoc view, which uses adsf and WEBrick, as far as I understand), these extension-less HTML files get interpreted as plain text.

For previewing with nanoc view, how can I set the default content type (i.e. text/html) for files without filetype extensions?

(When publishing this site, I set the correct content type in Apache’s .htaccess file so that the files get interpreted as HTML, but WEBrick/adsf don’t seem to support .htaccess.)

1

There are 1 best solutions below

2
On

You should be writing those to /output/blog/hello-world/index.html instead. That makes them work seamlessly in nanoc view, Apache (with no .htaccess), even by just opening the site files in your browser (assuming you're using relativized links).