diff --git a/README.md b/README.md index 71c33f1..600770c 100644 --- a/README.md +++ b/README.md @@ -4,12 +4,4 @@ This repo contains my attempt at this year's Advent of Code (2024) I will try and do some problems (probably not all of them) using Typst -## Progress: -#### Stars: 0 / 50 -| Mon | Tue | Wed | Thu | Fri | Sat | Sun | -|:------------------:|:-----------------:|:------------------:|:------------------:|:------------------:|:------------------:|:------------------:| -| | | | | | | 1
:star: | -| 2 | 3 | 4 | 5 | 6 | 7 | 8 | -| 9 | 10 | 11 | 12 | 13 | 14 | 15 | -| 16 | 17 | 18 | 19 | 20 | 21 | 22 | -| 23 | 24 | 25 | | | | | \ No newline at end of file +![progress](progress.png) \ No newline at end of file diff --git a/progress.png b/progress.png new file mode 100644 index 0000000..218ee03 Binary files /dev/null and b/progress.png differ diff --git a/progress.typ b/progress.typ new file mode 100644 index 0000000..b6f1518 --- /dev/null +++ b/progress.typ @@ -0,0 +1,13 @@ +#import "/src/utils.typ": make-progress, template, star-state + +#show: template +#set page(height: auto, margin: 1cm) +#let progress = yaml("/progress.yaml") +#star-state.update(s => { + let p = progress + for (k, v) in p.pairs() { + p.at(k) = v.stars + } + return p +}) +#make-progress(links: false) \ No newline at end of file diff --git a/progress.yaml b/progress.yaml new file mode 100644 index 0000000..bbf170a --- /dev/null +++ b/progress.yaml @@ -0,0 +1,2 @@ +1: + stars: 1 \ No newline at end of file diff --git a/src/main.typ b/src/main.typ index 3d466b6..7b319d7 100644 --- a/src/main.typ +++ b/src/main.typ @@ -55,41 +55,7 @@ #v(1fr) -#context { - let stars = star-state.final() - let star-cnt = stars.values().sum(default: 0) - let first-weekday = datetime( - year: 2024, - month: 12, - day: 1 - ).weekday() - let cells = ([],) * (first-weekday - 1) - - for i in range(1, 26) { - let cell = [#i] - if str(i) in stars.keys() { - cell = stack( - dir: ttb, - spacing: 0.2em, - cell, - h(3pt) + ((emoji.star,)* stars.at(str(i))).join() - ) - cell = link(label("day-" + str(i)), cell) - } - - cells.push(cell) - } - - [*Stars: #star-cnt / 50*] - table( - columns: (1fr,)*7, - inset: 0.8em, - align: center + horizon, - fill: (_, y) => if y > 0 and calc.rem(y, 2) == 0 {gray.lighten(70%)}, - table.header([*Mon*], [*Tue*], [*Wed*], [*Thu*], [*Fri*], [*Sat*], [*Sun*]), - ..cells - ) -} +#make-progress() #pagebreak() @@ -105,4 +71,11 @@ ) ) -#make-day(1, stars: 1) \ No newline at end of file +#let progress = yaml("/progress.yaml") + +#for i in range(1, 26) { + if str(i) in progress.keys() { + let day = progress.at(str(i)) + make-day(i, stars: day.stars) + } +} diff --git a/src/utils.typ b/src/utils.typ index 68f8de8..91fc9fb 100644 --- a/src/utils.typ +++ b/src/utils.typ @@ -1,4 +1,3 @@ -#let star-cnt = counter("stars") #let star-state = state("stars", (:)) #let get-input-path(day) = { @@ -73,7 +72,6 @@ #let make-day(day, stars: 0) = { star-state.update(s => s + (str(day): stars)) - star-cnt.update(v => v + stars) day-template( stars: stars, day, @@ -82,6 +80,44 @@ ) } +#let make-progress(links: true) = context { + let stars = star-state.final() + let star-cnt = stars.values().sum(default: 0) + let first-weekday = datetime( + year: 2024, + month: 12, + day: 1 + ).weekday() + let cells = ([],) * (first-weekday - 1) + + for i in range(1, 26) { + let cell = [#i] + if str(i) in stars.keys() { + cell = stack( + dir: ttb, + spacing: 0.2em, + cell, + h(3pt) + ((emoji.star,)* stars.at(str(i))).join() + ) + if links { + cell = link(label("day-" + str(i)), cell) + } + } + + cells.push(cell) + } + + [*Stars: #star-cnt / 50*] + table( + columns: (1fr,)*7, + inset: 0.8em, + align: center + horizon, + fill: (_, y) => if y > 0 and calc.rem(y, 2) == 0 {gray.lighten(70%)}, + table.header([*Mon*], [*Tue*], [*Wed*], [*Thu*], [*Fri*], [*Sat*], [*Sun*]), + ..cells + ) +} + #let template(body) = { set text(font: "Source Sans 3") body