dapper icon indicating copy to clipboard operation
dapper copied to clipboard

Rewrite output filenames to match URL

Open smls opened this issue 9 years ago • 1 comments

It would be nice if the files in _output/ could be assigned a dir and file name matching their calculated url variable.

I'm trying to create a blog, and was hoping that I could write blog posts as files named like:

_source/posts/0001.md
_source/posts/0002.md

...and have them automatically outputted as:

_output/2015/08/foo-bar-baz.html
_output/2015/08/yada-yada-yada.html

But alas, even though dapper calculates the correct url variable (thanks to the urlpattern setting) it always writes the output files using the same filenames as the source files:

_output/posts/0001.md
_output/posts/0002.md

How is the web server supposed to know about the correct URL to serve them under, then?

smls avatar Aug 17 '15 10:08 smls

As a work-around, I'm now using a _source/rename.sh file with the contents:

---
layout: raw
extension: .sh
---
#!/bin/sh

[%~ MACRO shellquote(str) BLOCK %]'[% str.replace("'", "'\\''") %]'[% END ~%]

[% FOR post in site.pages.grep(->{ this.layout eq 'blogpost' }) ~%]
  mv [% shellquote(post.filename) %] _output[% shellquote(post.url) %].html
[% END ~%]

rm [% page.filename %]

...and then make sure that the makefile runs dapper build && sh _output/rename.sh.

It's not a great solution though, because it means I cannot use dapper serve for testing.

smls avatar Aug 23 '15 19:08 smls