Christmas gifts and timed gift e-mails
- Gifts bought 15 Nov - 6 Jan get a Christmas card ("Boldog karácsonyt és
csillagos 2027-et!", snowflakes) and a Christmas e-mail subject.
- The buyer can time the gift e-mail (e.g. Christmas morning); "Küldés most"
replaces a waiting one, a refund takes it back.
- Admin: timed e-mails by hour (waiting / sent / failed), e-mail state per gift.
- /karacsony landing page; seasonal hints on /csomagok and /ajandek.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
+97
-12
@@ -38,6 +38,8 @@ const GOLD: &str = "#a07a2c";
|
||||
const MUTED: &str = "#5f6578";
|
||||
const LINE: &str = "#d9c9a3";
|
||||
const PAPER: &str = "#fdfaf3";
|
||||
/// The Christmas snowflakes: gold, lighter than the text.
|
||||
const GOLD_SOFT: &str = "#c9a862";
|
||||
|
||||
/// Where the code box starts; the message fills the space above it.
|
||||
const CODE_TOP: f32 = 636.0;
|
||||
@@ -64,6 +66,27 @@ pub struct Card<'a> {
|
||||
pub from_name: Option<&'a str>,
|
||||
/// The buyer's message (line breaks kept).
|
||||
pub message: Option<&'a str>,
|
||||
/// A Christmas gift: the card is festive and wishes a happy new year
|
||||
/// (this one).
|
||||
pub christmas: Option<i32>,
|
||||
}
|
||||
|
||||
/// "2027-et", "2028-at": a year in the accusative, by how its last word sounds.
|
||||
pub fn year_accusative(year: i32) -> String {
|
||||
let ending = match year.rem_euclid(10) {
|
||||
1 | 4 | 7 | 9 => "et",
|
||||
2 => "t",
|
||||
3 | 8 => "at",
|
||||
5 => "öt",
|
||||
6 => "ot",
|
||||
// Tens: "…tízet", "…húszat", "…harmincat"…; hundreds and thousands: "…százat", "…ezret".
|
||||
_ => match (year / 10).rem_euclid(10) {
|
||||
1 | 4 | 7 | 9 => "et",
|
||||
0 if (year / 100).rem_euclid(10) == 0 => "et",
|
||||
_ => "at",
|
||||
},
|
||||
};
|
||||
format!("{year}-{ending}")
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@@ -252,6 +275,11 @@ impl Message {
|
||||
let (text, signature) = match (message, from) {
|
||||
(Some(m), from) => (format!("„{m}”"), from.map(|f| format!("– {f}"))),
|
||||
(None, Some(f)) => (format!("Szeretettel küldi: {f}"), None),
|
||||
(None, None) if card.christmas.is_some() => (
|
||||
"Boldog karácsonyt! Fedezd fel, mit mesélnek rólad a csillagok, és mit hoz neked a következő év."
|
||||
.to_string(),
|
||||
None,
|
||||
),
|
||||
(None, None) => (
|
||||
"Fedezd fel, mit mesélnek rólad a csillagok: a születési képleted, személyre szóló elemzések, \
|
||||
és válaszok a kérdéseidre."
|
||||
@@ -323,6 +351,26 @@ fn star(x: f32, y: f32, r: f32, fill: &str) -> String {
|
||||
)
|
||||
}
|
||||
|
||||
/// A six-armed snowflake of gold lines, centred on (x, y).
|
||||
fn snowflake(x: f32, y: f32, r: f32, color: &str) -> String {
|
||||
let mut d = String::new();
|
||||
for k in 0..6 {
|
||||
let a = (k as f32 * 60.0 - 90.0).to_radians();
|
||||
let (sin, cos) = a.sin_cos();
|
||||
let _ = write!(d, "M{x} {y}L{} {}", x + r * cos, y + r * sin);
|
||||
// Two small branches on each arm.
|
||||
let (bx, by) = (x + r * 0.6 * cos, y + r * 0.6 * sin);
|
||||
for side in [-1.0_f32, 1.0] {
|
||||
let b = a + side * 0.75;
|
||||
let _ = write!(d, "M{bx} {by}L{} {}", bx + r * 0.32 * b.cos(), by + r * 0.32 * b.sin());
|
||||
}
|
||||
}
|
||||
format!(
|
||||
r#"<path d="{d}" fill="none" stroke="{color}" stroke-width="{}" stroke-linecap="round"/>"#,
|
||||
(r / 9.0).max(0.6)
|
||||
)
|
||||
}
|
||||
|
||||
/// The QR code of the redeem link as a path of `size` points at (x, y).
|
||||
fn qr(url: &str, x: f32, y: f32, size: f32) -> String {
|
||||
let Ok(code) = qrcode::QrCode::with_error_correction_level(url, qrcode::EcLevel::M) else {
|
||||
@@ -388,7 +436,7 @@ pub fn svg(card: &Card) -> String {
|
||||
);
|
||||
|
||||
// "AJÁNDÉKUTALVÁNY" between two short lines.
|
||||
let eyebrow = "AJÁNDÉKUTALVÁNY";
|
||||
let eyebrow = if card.christmas.is_some() { "KARÁCSONYI AJÁNDÉK" } else { "AJÁNDÉKUTALVÁNY" };
|
||||
let spacing = 3.2;
|
||||
let ew = width(Face::SansBold, eyebrow, 9.0, spacing) - spacing;
|
||||
let _ = write!(
|
||||
@@ -413,7 +461,12 @@ pub fn svg(card: &Card) -> String {
|
||||
for (x, y, r) in
|
||||
[(124.0, 164.0, 5.0), (462.0, 148.0, 6.5), (470.0, 304.0, 4.0), (134.0, 322.0, 6.0), (420.0, 350.0, 3.0)]
|
||||
{
|
||||
s.push_str(&star(x, y, r, LINE));
|
||||
// Christmas: snowflakes instead of stars, a little bigger.
|
||||
if card.christmas.is_some() {
|
||||
s.push_str(&snowflake(x, y, r * 1.9, GOLD_SOFT));
|
||||
} else {
|
||||
s.push_str(&star(x, y, r, LINE));
|
||||
}
|
||||
}
|
||||
let inner = WHEEL.split_once("viewBox=\"0 0 680 680\">").map_or("", |(_, rest)| rest);
|
||||
let inner = inner.trim_end().trim_end_matches("</svg>");
|
||||
@@ -451,17 +504,32 @@ pub fn svg(card: &Card) -> String {
|
||||
y += 15.0;
|
||||
}
|
||||
|
||||
// A divider with a small diamond.
|
||||
// A divider with a small diamond; at Christmas, the wishes on it.
|
||||
let divider = y + 10.0;
|
||||
let _ = write!(
|
||||
s,
|
||||
r#"<line x1="{}" y1="{divider}" x2="{}" y2="{divider}" stroke="{LINE}" stroke-width="0.7"/><line x1="{}" y1="{divider}" x2="{}" y2="{divider}" stroke="{LINE}" stroke-width="0.7"/><path d="M{cx} {} l3.5 3.5 l-3.5 3.5 l-3.5 -3.5 z" fill="{GOLD}"/>"#,
|
||||
cx - 150.0,
|
||||
cx - 10.0,
|
||||
cx + 10.0,
|
||||
cx + 150.0,
|
||||
divider - 3.5
|
||||
);
|
||||
if let Some(year) = card.christmas {
|
||||
let wish = format!("Boldog karácsonyt és csillagos {}!", year_accusative(year));
|
||||
let ww = width(Face::SerifItalic, &wish, 16.0, 0.0);
|
||||
let _ = write!(
|
||||
s,
|
||||
r#"<line x1="{}" y1="{divider}" x2="{}" y2="{divider}" stroke="{LINE}" stroke-width="0.7"/><line x1="{}" y1="{divider}" x2="{}" y2="{divider}" stroke="{LINE}" stroke-width="0.7"/><text x="{cx}" y="{}" text-anchor="middle" font-family="{SERIF_ITALIC_FAMILY}" font-style="italic" font-weight="500" font-size="16" fill="{GOLD}">{}</text>"#,
|
||||
cx - ww / 2.0 - 70.0,
|
||||
cx - ww / 2.0 - 12.0,
|
||||
cx + ww / 2.0 + 12.0,
|
||||
cx + ww / 2.0 + 70.0,
|
||||
divider + 5.0,
|
||||
escape(&wish)
|
||||
);
|
||||
} else {
|
||||
let _ = write!(
|
||||
s,
|
||||
r#"<line x1="{}" y1="{divider}" x2="{}" y2="{divider}" stroke="{LINE}" stroke-width="0.7"/><line x1="{}" y1="{divider}" x2="{}" y2="{divider}" stroke="{LINE}" stroke-width="0.7"/><path d="M{cx} {} l3.5 3.5 l-3.5 3.5 l-3.5 -3.5 z" fill="{GOLD}"/>"#,
|
||||
cx - 150.0,
|
||||
cx - 10.0,
|
||||
cx + 10.0,
|
||||
cx + 150.0,
|
||||
divider - 3.5
|
||||
);
|
||||
}
|
||||
|
||||
// The message next to the avatar, centred in the room above the code box.
|
||||
let room_top = divider + 22.0;
|
||||
@@ -568,6 +636,7 @@ mod tests {
|
||||
recipient_name: Some("Bea"),
|
||||
from_name: from,
|
||||
message,
|
||||
christmas: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -625,6 +694,22 @@ mod tests {
|
||||
usvg::Tree::from_str(&svg, &usvg::Options::default()).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_christmas_card_wishes_a_happy_new_year() {
|
||||
let contents = contents();
|
||||
let plain = svg(&card(&contents, None, None));
|
||||
assert!(plain.contains("AJÁNDÉKUTALVÁNY") && !plain.contains("karácsony"));
|
||||
let festive = Card { christmas: Some(2027), ..card(&contents, None, None) };
|
||||
let svg = svg(&festive);
|
||||
assert!(svg.contains("KARÁCSONYI AJÁNDÉK") && svg.contains("Boldog karácsonyt és csillagos 2027-et!"));
|
||||
assert!(svg.contains("mit hoz neked a következő év"));
|
||||
assert!(pdf(&festive).unwrap().starts_with(b"%PDF-"));
|
||||
assert_eq!(
|
||||
[2027, 2028, 2030, 2026, 2032, 2035, 2100, 2000].map(year_accusative),
|
||||
["2027-et", "2028-at", "2030-at", "2026-ot", "2032-t", "2035-öt", "2100-at", "2000-et"]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn without_a_message_the_card_still_says_something() {
|
||||
let contents = contents();
|
||||
|
||||
Reference in New Issue
Block a user