Self-contained posts
telenieko opened this issue · comments
Hi there,
This is "wishlist", dunno how hard would it be to implement it: One of the things I hate most with any site is that assets belonging to one posts can't be kept with it.
I mean, if I write a post with some images or files that go with it I am always forced to put them "somewhere else" and link.
How hard would be something like, for example, to have a "self contained post" You'd have:
- A folder named YYYY-MM-DD-My_post_url/
- Inside it there would be a post.md (or index.md) file which is the post itself
- And then all other media related to the post in the same folder.
Calls to get_asset() would first search for assets in the post folder, then on the assets folder.
Site generation would copy used assets to a common media folder and place the post on YYYY-MM-DD-My_post_url.html
That'd be awesome.
Disclaimer: I am not a mynt user but considering it to rewrite my personal site :)
Cheers,
Marc
It would take a fair bit of restructuring.
It's a neat idea but I think mynt needs to be fleshed out a bit more before something like this is looked at.
Good that you like the idea :D
I'll sort the assets in post-specific folders in the meantime.
Thanks for replying!
No problem.
I have this mapped out for v0.4 when I plan to work on the content system. I'll take a closer look at it then.
Below, under figure I imply an image asset.
In 2011 I've created the separate _figures
folder where I stored these figures in the similar way you described — all images related to a post were put under a folder with the name equal to its slug, excluding date (i.e. _figures/my-first-post/figure1.jpg
).
For this to work, in parallel with _figures
folder support, I've added get_figure(slug, 'figure1.png')
function to mynt, to work along with get_asset
. But later (I see 27 December 2011 in NEWS.md) slug
variable was removed and became not accessible from inside of the posts :( ...
What version are you using?
v0.3
, now. (but I merged it with my fork, though I preferred theirs
in majority of the cases).
Seeing as you've already merged your own changes, the easiest solution would be just adding it back. At line 155 in processors.py add:
item['slug'] = text
oh, sure, thanks a lot! (I found this place yesterday, but I somehow mis-thought that I should use item.slug
this way, and failed)
Hmm, anyway I get it Undefined
this way :(
The code for get_figure
is (renderers/jinja.py, L64):
def _get_figure(self, slug, figure):
print (slug, figure)
return Url.join(self.globals['site']['base_url'],
self.globals['site']['figures_url'],
slug, figure)
I used it as [some text]({{ get_figure(slug, 'logo.png') }})
in the post, and I get:
>> Parsing
(Undefined, 'logo.png')
Traceback (most recent call last):
File "/usr/local/bin/mynt", line 9, in <module>
load_entry_point('mynt==0.3', 'console_scripts', 'mynt')()
. . .
File "/Library/Python/2.7/site-packages/mynt-0.3-py2.7.egg/mynt/renderers/jinja.py", line 68, in _get_figure
slug, figure)
File "/Library/Python/2.7/site-packages/mynt-0.3-py2.7.egg/mynt/utils.py", line 85, in join
url = '/'.join(args)
TypeError: sequence item 2: expected string or Unicode, Undefined found
Err sorry, adding the following after line 149 should do the trick:
frontmatter['slug'] = text
Sorry myself, I've made an accidental pull request to your repository instead of mine (though now you know that there's not a lot of difference there :) ).
It worked great with some lines manipulation, thank you!