mbutterick / pollen-users

please use https://forums.matthewbutterick.com/c/typesetting/ instead
https://forums.matthewbutterick.com/c/typesetting/
52 stars 0 forks source link

Skip tags in HTML output? #57

Closed basus closed 4 years ago

basus commented 4 years ago

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 the doc for the source file to find the more tag and break for the excerpt. But I don't want the more tag showing up in the HTML output. Is there a way to keep the more tag in the doc, but remove it when generating the HTML?

sorawee commented 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

basus commented 4 years ago

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.

mbutterick commented 4 years ago

Seems similar to #58 — ?

otherjoel commented 4 years ago

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.

basus commented 4 years ago

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.

odanoburu commented 4 years ago

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)

mbutterick commented 4 years ago

metas will remain a hash.