Provide get-doc/get-meta from template.rkt
#57
Closed
opened 10 years ago by malcolmstill
·
6 comments
Loading…
Reference in New Issue
There is no content yet.
Delete Branch '%!s(<nil>)'
Deleting a branch is permanent. It CANNOT be undone. Continue?
Following up from issue 55 I'm using a similar tactic to export categories under which a blog post will come.
What I'm now attempting to achieve is building a pagetree programmatically by reading all
*.pm
files in a directoryposts/
and then rendering it. As part of this process I want to generate category pages (i.e. generateprogramming.html
that lists all posts tagged withprogramming
. As I am storing the categories in thedoc
structure I need to generate thedoc
txexpr programmatically, pull out the categories and collate them across all posts.In order to do this I've tracked down the
get-doc
function which I believe will work, unfortunately it isn't currently exported bytemplate.rkt
. Unless I'm missing something (another way to do this etc.) it would be useful fortemplate.rkt
to exportget-doc
and, indeed,get-metas
. I can imagine there would be other cases where these functions would be required.The code will look something like the following:
If you need to do this, it's not wrong. But don't forget that if Pollen doesn't find an
index.ptree
, it will do exactly what you describe — generate a pagetree from all renderable files. IOW, if directoryposts
containsone.html.pm, two.html.pm ...
, and you doraco pollen render posts
, then all thesepm
files will be rendered. (See also “Using the automatic pagetree”.)I will assume you have your reasons for storing them in
doc
, but IMO categories seem like an excellent thing to store inmetas
, because they are in fact metadata.get-doc
andget-metas
aren’t exposed in the public interface because they’re really just helper functions forselect-from-doc
andselect-from-metas
(which are part of the interface). How are they falling short? (BTW in case of emergency, you can break the glass withrequire/expose
.)BTW it sounds like you’re conceptualizing the generation of your category pages as a side effect of rendering the
posts
directory. You might find it fruitful to flip it around: have separate source files in your project that represent the categories (e.g.,programming.html.pm, pizza.html.pm, disco.html.pm ...
) and put the page-gathering logic in those. Then you can develop & preview them independent of rendering the other pages. (That assumes, however, that you have a fixed list of categories.)The reason I'm trying to do it like this, which I didn't mention above, is that I want to order posts by date. I'd need some logic in
pm->html
to read the date I'm storing inmeta
(again I think I'd needget-doc
orget-meta
to achieve this). Obviously I could manually generate the pagetree but ideally this should be automated.I agree this is metadata and should probably be stored in metas. My reservation is that meta can only hold strings (right?). Seems to me that it would be nice to store arbitrary data, for example store categories as a list of strings under a single key
categories
. Obviously I could store a single space-separated string of categories and then split on space.Again, I want to order the posts by date so I need data from all the posts at a single time. The
select-from
s are great inside of the template that renders a particular post but I don't see how I can use them withoutget-doc
/get-meta
when needing to collate information across more than one markup file. I didn't know aboutrequire/expose
(I've just started learning Racket), cool!My hope would be to not have such a fixed list and it would generate category pages for whatever I throw into the posts.
You've stated elsewhere that you're not looking to personally push Pollen in the direction of blogging, and maybe I'm abusing rather than using it, but I think it's a perfect application. I've messed around with a bunch of other static site generators and they never quite do everything I want them to but Pollen's programmability makes it really simple to basically do whatever I want it to. It's awesome!
I’ve considered the issue before. I agree that because
metas
ultimately becomes a hashtable, it would be nice to be able to write any type of value. The problem is that it would mean losing compatibility with X-expressions, which would cost a lot of simplicity. To justify that loss, I’d need to come up with a compelling example of a datatype that wasn’t tolerably encoded as a string. I've never been able to. (Maybe you can.) For instance, numbers can be converted withstring->number
. And as you say, a list of categories can bestring-split
.I would intuitively think of doing something like
Would that not work for you?
Fair enough. Carry on.
I appreciate the compliment. I endorse Pollen being used as a blogging tool (though also consider
frog
). I’m sure that bloggers will have good suggestions for improving it. But to call something a “blogging system” sets expectations of certain features, which have been implemented by others, before, better. As you say, Pollen’s comparative advantage is its programmability, which I’d like to use to investigate the territory that lies beyond blogs.Can X-expressions be stored in meta?
Nothing I can think of off the top of my head!
<high_embarrassment_factor_mode>
Woops! The
select
s work on paths; I was under the impression that they operated only on txexprs. No need forget-doc
andget-metas
to be exposed then.</high_embarrassment_factor_mode>
That’s a good idea. I’ve pushed a fix to permit that. You can still write your key-value pair as an attribute:
But you can also write it as an element, which allows you to use any X-expression as the value:
You can also store lists of values, like categories:
I’ve pushed a clarification for the docs.