grace/typst_web_magic

Typst SSG powering grace.pink and words.gay

git clone https://git.gae.moe/grace/typst_web_magic

Grace Yoderadded template, readme, and minor changes5b6c1ba

main
2.0 KiB57 linesraw

#import "metadata.typ": author-text, format-date, date-key#import "pdf.typ": pdf-header

#let post-header(ctx) = [ #context { let info = ctx.page if target() == "html" { html.elem("header", attrs: (class: "content-box post-header"))[ #if info.title != none { html.h1(info.title) } #if info.subtitle != none { html.p(class: "post-subtitle", info.subtitle) } #if info.by.len() > 0 { html.p(class: "post-author", [By #author-text(info.by)]) } #if info.date != none { let time = html.elem("time", attrs: (datetime: date-key(info)), format-date(info.date)) html.p(class: "post-date", time) } #if info.description != none { html.p(info.description) } ] } else { pdf-header(ctx) } } ]

#let post-card(ctx, info) = context { let title = if info.title == none { [Untitled post] } else { info.title } let by = if info.author == ctx.site.by.map(author => author.name) { () } else { info.by } if target() != "html" { return list.item[ #link(info.url, title) #if info.date != none [— #format-date(info.date)] #if by.len() > 0 [· #author-text(by)] #if info.subtitle != none [#emph(info.subtitle)] #if info.description != none [#info.description] ] } html.elem("article", attrs: (class: "content-box post-card"))[ #html.h2(class: "post-card-title", html.a(href: info.href, title)) #if info.subtitle != none { html.p(class: "post-card-subtitle", info.subtitle) } #if info.date != none or by.len() > 0 { html.p(class: "post-card-meta")[ #if info.date != none { html.elem("time", attrs: (datetime: date-key(info)), format-date(info.date)) } #if info.date != none and by.len() > 0 [ · ] #if by.len() > 0 [#author-text(by)] ] } #if info.description != none { html.p(class: "post-card-description", info.description) } #if info.pdf { html.p(class: "post-card-links")[ #html.a(href: "/" + info.pdf-path)[View as PDF] ] } ] }

1#import "metadata.typ": author-text, format-date, date-key
2#import "pdf.typ": pdf-header
3
4#let post-header(ctx) = [
5  #context {
6    let info = ctx.page
7    if target() == "html" {
8      html.elem("header", attrs: (class: "content-box post-header"))[
9        #if info.title != none { html.h1(info.title) }
10        #if info.subtitle != none { html.p(class: "post-subtitle", info.subtitle) }
11        #if info.by.len() > 0 { html.p(class: "post-author", [By #author-text(info.by)]) }
12        #if info.date != none {
13          let time = html.elem("time", attrs: (datetime: date-key(info)), format-date(info.date))
14          html.p(class: "post-date", time)
15        }
16        #if info.description != none { html.p(info.description) }
17      ]
18    } else {
19      pdf-header(ctx)
20    }
21  }
22]
23
24#let post-card(ctx, info) = context {
25  let title = if info.title == none { [Untitled post] } else { info.title }
26  let by = if info.author == ctx.site.by.map(author => author.name) { () } else { info.by }
27  if target() != "html" {
28    return list.item[
29      #link(info.url, title)
30      #if info.date != none [— #format-date(info.date)]
31      #if by.len() > 0 [· #author-text(by)]
32
33      #if info.subtitle != none [#emph(info.subtitle)]
34
35      #if info.description != none [#info.description]
36    ]
37  }
38  html.elem("article", attrs: (class: "content-box post-card"))[
39    #html.h2(class: "post-card-title", html.a(href: info.href, title))
40    #if info.subtitle != none { html.p(class: "post-card-subtitle", info.subtitle) }
41    #if info.date != none or by.len() > 0 {
42      html.p(class: "post-card-meta")[
43        #if info.date != none {
44          html.elem("time", attrs: (datetime: date-key(info)), format-date(info.date))
45        }
46        #if info.date != none and by.len() > 0 [ · ]
47        #if by.len() > 0 [#author-text(by)]
48      ]
49    }
50    #if info.description != none { html.p(class: "post-card-description", info.description) }
51    #if info.pdf {
52      html.p(class: "post-card-links")[
53        #html.a(href: "/" + info.pdf-path)[View as PDF]
54      ]
55    }
56  ]
57}