Skip to content

Commit

Permalink
feat: initial dialogue support, featuing Leah!
Browse files Browse the repository at this point in the history
  • Loading branch information
ashhhleyyy committed Apr 10, 2024
1 parent d31b7c0 commit 76cf484
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 1 deletion.
Binary file added art/leah-confused.kra
Binary file not shown.
17 changes: 17 additions & 0 deletions assets/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,23 @@ blockquote {
color: var(--foreground-dim);
}

.inline-note {
user-select: none;
}

blockquote.dialogue {
display: flex;
flex-direction: row;
align-items: center;
gap: 1em;
padding: 0.5em 1em;
}

blockquote.dialogue img {
user-select: none;
min-width: 96px;
}

pre {
overflow-x: auto;
border: var(--accent) 1px solid;
Expand Down
Binary file added assets/images/characters/leah/confused.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/characters/leah/happy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/characters/leah/surprised.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 20 additions & 1 deletion src/templates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,25 @@ async fn rewrite_html(path: &str, html: &str) -> String {
html,
Settings {
element_content_handlers: vec![
// This is applied in the first pass so that images get rewritten in the second one.
element!("dialogue", |el| {
if let (Some(character), Some(mood)) = (el.get_attribute("character"), el.get_attribute("mood")) {
el.set_tag_name("blockquote")?;
el.set_attribute("class", "dialogue")?;
el.remove_attribute("character");
el.remove_attribute("mood");
let image = maud::html! {
// TODO: improve alt text when i rework asset handling
img width=(96) height=(96) src=(format!("/assets/images/characters/{character}/{mood}.png")) alt=(format!("{character}, {mood}"));
};
el.prepend("<span><b>Leah</b>:", ContentType::Html);
el.prepend(&image.0, ContentType::Html);
el.append("</span>", ContentType::Html);
} else {
el.replace("<blockquote>Oops! Invalid dialogue elemment.</blockquote>", ContentType::Html);
}
Ok(())
}),
element!("fedi-post", |el| {
if let (Some(server), Some(id)) =
(el.get_attribute("data-server"), el.get_attribute("data-id"))
Expand Down Expand Up @@ -301,7 +320,7 @@ async fn rewrite_html(path: &str, html: &str) -> String {
let ref_no = el.get_attribute("ref_no").unwrap();
let id = format!("~fn{target_id}~{ref_no}");
let html = maud::html! {
a href=(format!("#~fn{target_id}")) id=(id) {
a class="inline-note" href=(format!("#~fn{target_id}")) id=(id) {
sup {
(target_id)
}
Expand Down

0 comments on commit 76cf484

Please sign in to comment.