Closed basus closed 4 years ago
There are several ways to do that. The way I did is to call decode
at the root
function, which will recursively visit every node in your document tree. You then can match the more
tag.
See an example here: https://github.com/sorawee/my-website/blob/master/rkt/decoders.rkt#L50
Thanks for that pointer. But if I call decode
on a root
tag that removes more
tags, they get removed from the file's doc
. I originally thought I wanted the more
to stay in the doc
, but not be there in the HTML output. But now that I think about it, I could generate the summary as part of expanding the source file to its doc
, instead of when making the index. That would probably be more efficient anyway.
Seems similar to #58 — ?
I recently noticed that it is possible to update current-metas
from within pollen.rkt
, which means you can fiddle with the metas
export for the current page in the same way we’re used to fiddling with doc
. So for things like excerpts one good approach would be to make/update an excerpt
meta within your tag functions, and remove the extra tags from doc
. Then it’s super easy to grab the excerpt when you want it.
So this turned out to be pretty easy to do. I realized that I do (select* 'root doc)
to get the argument to ->html
. But that's just a list of tagged X-expressions, so I can just run it through a filter
before passing it to ->html
. For the moment I just have a basic predicate function to hand to filter
:
(define not-more? (λ (x) (and (txexpr? x) (not (equal? 'more (get-tag x))))))
but this could be easily extended to drop other tags, or do more interesting transformations.
All that being said, I agree with @otherjoel that for the purpose of generating an excerpt, I should generate an excerpt
meta and have doc
be something that can be converted without processing to HTML.
I recently noticed that it is possible to update
current-metas
from within pollen.rkt
is there a public function used to do this? as far as I see, we'd have to use hash functions directly, right? (and then things might break if the implementation of metas changes)
metas
will remain a hash.
I'm currently using a
more
tag in my source files to indicate where to break a file for generating excerpts. I'm currently looking through thedoc
for the source file to find themore
tag and break for the excerpt. But I don't want themore
tag showing up in the HTML output. Is there a way to keep themore
tag in thedoc
, but remove it when generating the HTML?