Middleman doesn't like periods in filenames

It seems like Middleman doesn’t like arbitrary periods in filenames. Suppose I write filenames like these:

  • 1.1-introduction.md
  • 1.2-installation.md

The __middleman/sitemap will produce the following resource information :

Path book/chapter-01/1.1-introduction
URL /book/chapter-01/1.1-introduction
Source File source/book/chapter-01/1.1-introduction.md

Path book/chapter-01/1.1-installation
URL /book/chapter-01/1.1-installation
Source File source/book/chapter-01/1.1-installation.md

As you can see, there is no .html at the end of the final paths (and this is with directory indexes disabled). When I try to visit one of these paths, I get a printout of the unrendered page source.

Can anyone confirm that periods are not allowed in filenames? Does anybody know of settings or workarounds that will allow them?

Try writing the filenames with html in them, like this:

1.1-introduction.html.md

Actually, yes, if I use .html.md, the issue goes away. Good suggestion.

But wouldn’t this be considered a middleman bug? Middleman seems to support markdown files with a single extension in all other cases except this one.

I’m also curious as to why middleman uses the two-extension naming convention (where the last extension converts to the first one). Don’t static site page always need to end up formatted as html?

I’m still interested in seeing if I can find a way to get this to work with the plain .md extension, since I may need to reference user-generated markdown files, and I’d prefer not to impose naming rules if I don’t have to. I guess it’s possible to use a rake task like this, but that looks looks pretty heavy-handed.

If anybody has other ideas, let me know.

Don’t know the design philosophy behind this, but some static files ends up as css, and sitemaps and rss feeds ends up as xml. Since you can use the same templating language (for example .erb) when producing them, I suppose specifying what kind of file it is, makes it easier.

Possibly you can use manipulate_resource_list http://middlemanapp.com/advanced/custom/ to change your .md files into .html.md in the sitemap. I haven’t tested, but I suppose that depends on execution order, and if the template engine gets its info from the sitemap or the actual file.

Another possibility is to duplicate the files and change the suffix of the copy to .html.md. You can detect new/changed .md files with app.files.changed (in manipulate_resource_list). Then you remove the .md files from the build directory with a after_build. Not elegant, but should get the job done.

1 Like

Those are some good ideas. Thanks a ton.

By the way, I didn’t know that you could build CSS or XML files from templates. I thought it was just HTML. Do you know of a list documented somewhere showing what formats you can build from templates?

I tested a little, and it seams that you can ignore the .md file. It will still be watched for changes. This should be a better method then removing it with after_build.

I think you can build anything that Tilt will not try to convert. The formats (i.e. suffixes) recognized by Tilt can be found at the bottom of http://middlemanapp.com/basics/templates/ So it should for example be possible to build javascript files.

The most usual usage seams to be to add an .erb suffix, and use erb tags to include a helper or variable from Middleman (in your case, the files would have the suffixes .html.md.erb ). XML files are easiest to build with .xml.builder.

One drawback with .html.md.erb is that most (all?) Markdown editors will not recognize it as an markdown file.