Commit bc55a26

HPCesia <me@hpcesia.com>
2026-08-15 14:31:28
Post ToC as sidenote
1 parent 5b5075e
Changed files (2)
src
contents
_lib
styles
src/contents/_lib/lib.typ
@@ -1,4 +1,15 @@
-#let post-template(body, lang: "en", region: none) = {
+#import "@preview/bullseye:0.1.0": match-target
+
+#import "./components/sidenote.typ": sidenote
+
+///
+///
+/// - body (content):
+/// - lang (str): pass to `set text(lang: lang)`
+/// - region (str, none): pass to `set text(region: region)`
+/// - toc (bool): whether to show post TOC
+/// -> content
+#let post-template(body, lang: "en", region: none, toc: true) = {
   set text(lang: lang, region: region)
 
   import "./templates/footnote.typ": footnote-template
@@ -17,6 +28,8 @@
       description: frontmatter.at("desc", default: none),
     )
     if frontmatter.title != "" { title() }
+
+    if toc { match-target(html: sidenote(outline(), block: true), paged: ()) }
   }
 
   body
src/styles/article/sidenote.scss
@@ -8,6 +8,14 @@ article .sidenote {
     clear: right;
     margin-right: calc(-1/3 * 100% - 1rem);
   }
+  @media (max-width:48rem) {
+    &:not(:has(nav[role="doc-toc"])) {
+      width: 90%;
+      float: left;
+      margin-inline: 1rem 0.5rem;
+      margin-block: 0.5rem;
+    }
+  }
 
   & > :first-child {
     margin-top: 0;
@@ -15,4 +23,7 @@ article .sidenote {
   & > :last-child {
     margin-bottom: 0;
   }
+  > nav[role="doc-toc"] > :first-child {
+    margin-top: 0;
+  }
 }