posativ/acrylamid — pull request #159 by hooli (2013-05-27 20:13:55+00:00)
Title: Copyres - new metadata attribute to copy resources (eg images/video) with post

Hi

It would be useful to keep images etc (resources) together with it's associated markdown file, since then the images will appear in any markdown editor if they are kept in the same directory.

To support this, I've added a metadata attribute called "copyres". It can actually be used in three ways:
1) Just include copyres: in the markdown file, and any file with the same name and an extension of "_[0-9]*.*" will be copied across.
The default wildcard can be changed with COPYRES_WILDCARD

2) Specify a wildcard
copyres: ../holiday/london*.png
The wildcard will work from the directory of the entry, and copy those files into the same directory as the post. Hence images can be linked:
![London](london1.png) etc

3) Specify an array of wildcards
copyres: [ ../pics/*.png , work*.pdf ]
Note, entries shouldn't be in quotes (I keep on forgetting this!)

Also, only files that match will be copied, directories are ignored.

Other points:

a) The list of files that were match is stored with the entry, and can be accessed via "respaths" and "resfilenames" if you want to iterate over them

{% for item in entry.resfilenames %}
res: {{ item }}
{% endfor %}

The files will always be in the same directory as the post, and respaths is the source path + filename

b) Assets don't get included in the sitemap since they are generated afterwards, so I've added a new namespace for events called "resource" and filtered them out of the sitemap.
There is a config setting SITEMAP_RESOURCE_EXT which can be used to pick certain file types out (eg PDFs).
Note images/audio and video should not be included.

Any comments / suggestions welcome.

TODO:

I had a look at refs.py , but was unsure how best to include it.
It would be useful if resfilenames is used in a template that any changes in the list of files is picked up.
Currently you would need to change the post if a new file was added that the wildcard finds.