# Tags

Tags!
patch-note
August 22, 2023

Just another little update to the site. Added tags to posts! Check them out in the head of each post.

There’s also some more polish all around.

- A 404 page
- A link back to the top of the page
- Image labels

Put a label on this cat.

You do it with this syntax which is apparently part of Markdown.

    ![](/static/embeds/2023-08-22_tags/cat.webp 'Put a label on this cat.')

This required hooking into how `pulldown-cmark` handles tags, which is only a little awkward. There’s no built-in way to do so, but working with Rust iterators makes it easy to turn image tags into raw html tags. Note how the match turns all `Event::Start(Tag::Image)` into `Event::Html`.

    fn parse_markdown_custom<'a, I: Iterator<Item = pulldown_cmark::Event<'a>>>(
    	iter: I,
    ) -> impl Iterator<Item = pulldown_cmark::Event<'a>> {
    	use pulldown_cmark::{CowStr, Event, Tag};
    	iter.map(|event| match event {
    		Event::Start(Tag::Image(_link_type, url, title)) => {
    			let v = html! {
    				img src=(url) title=(title);
    				@if title.as_ref().trim().len() > 0 {
    					p class="markdown-image-title" { (title) }
    				}
    			};
    			Event::Html(CowStr::from(v.0))
    		}
    		v => v,
    	})
    }

↑ Top

Download My Site
Keep it around
← Previous
Estimated-Content-Length Should Exist
An HTML header problem without a solution
Next →