Skip tags in HTML output? #57

Closed
opened 4 years ago by basus · 7 comments
basus commented 4 years ago (Migrated from github.com)

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?

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 (Migrated from github.com)

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

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 (Migrated from github.com)

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.

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 (Migrated from github.com)

Seems similar to #58 — ?

Seems similar to #58 — ?
otherjoel commented 4 years ago (Migrated from github.com)

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.

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 (Migrated from github.com)

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.

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`: ```racket (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 (Migrated from github.com)

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)

> 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 (Migrated from github.com)

metas will remain a hash.

`metas` will remain a hash.
This repo is archived. You cannot comment on issues.
No Milestone
No project
No Assignees
1 Participants
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: mbutterick/pollen-users#57
Loading…
There is no content yet.