diff --git a/.github/workflows/auto-release-typst.yml b/.github/workflows/auto-release-typst.yml index 97dba4b..4bc3002 100644 --- a/.github/workflows/auto-release-typst.yml +++ b/.github/workflows/auto-release-typst.yml @@ -29,8 +29,8 @@ jobs: sudo apt-get install curl git unzip imagemagick libwebp-dev librsvg2-dev fonts-noto-cjk fonts-noto-cjk-extra sudo apt-get remove fonts-noto-color-emoji - curl -OL https://github.com/typst/typst/releases/download/v0.9.0/typst-x86_64-unknown-linux-musl.tar.xz - curl -OL https://github.com/megakite/texmath/releases/download/v0.12.8.3-20231003/texmath-arg + curl -OL https://github.com/typst/typst/releases/download/v0.10.0/typst-x86_64-unknown-linux-musl.tar.xz + curl -OL https://github.com/megakite/texmath/releases/download/v0.12.8.6-20231213/texmath-arg xz -dc typst-x86_64-unknown-linux-musl.tar.xz | tar -x sudo mv ./typst-x86_64-unknown-linux-musl/typst /bin/ chmod +x texmath-arg diff --git a/.github/workflows/test-build-typst.yml b/.github/workflows/test-build-typst.yml index 6c7f2d4..58c624b 100644 --- a/.github/workflows/test-build-typst.yml +++ b/.github/workflows/test-build-typst.yml @@ -30,8 +30,8 @@ jobs: sudo apt-get install curl git unzip imagemagick libwebp-dev librsvg2-dev fonts-noto-cjk fonts-noto-cjk-extra sudo apt-get remove fonts-noto-color-emoji - curl -OL https://github.com/typst/typst/releases/download/v0.9.0/typst-x86_64-unknown-linux-musl.tar.xz - curl -OL https://github.com/megakite/texmath/releases/download/v0.12.8.3-20231003/texmath-arg + curl -OL https://github.com/typst/typst/releases/download/v0.10.0/typst-x86_64-unknown-linux-musl.tar.xz + curl -OL https://github.com/megakite/texmath/releases/download/v0.12.8.6-20231213/texmath-arg xz -dc typst-x86_64-unknown-linux-musl.tar.xz | tar -x sudo mv ./typst-x86_64-unknown-linux-musl/typst /bin/ chmod +x texmath-arg diff --git a/oi-wiki-export-typst/index.js b/oi-wiki-export-typst/index.js index 0112c9c..a114548 100644 --- a/oi-wiki-export-typst/index.js +++ b/oi-wiki-export-typst/index.js @@ -154,7 +154,16 @@ async function main() { result += '{0} {1}\n'.format('='.repeat(depth + 1), escape(key)) } else { labelHistory.push(dirName) + if (depth === 0) { + result += `#import "../oi-wiki.typ": page-header +#pagebreak(to: "odd", weak: true) +#set page(header: none) +` + } result += '{0} {1} <{2}>\n'.format('='.repeat(depth + 1), escape(key), dirName) + if (depth === 0) { + result += '#set page(header: page-header)\n' + } } for (const id in object[key]) { diff --git a/oi-wiki-export-typst/oi-wiki-export.typ b/oi-wiki-export-typst/oi-wiki-export.typ index dd19207..794728c 100644 --- a/oi-wiki-export-typst/oi-wiki-export.typ +++ b/oi-wiki-export-typst/oi-wiki-export.typ @@ -2,6 +2,7 @@ /* BEGIN imports */ #import "constants.typ": * +#import "oi-wiki.typ": page-header /* END imports */ /* BEGIN meta */ @@ -136,72 +137,12 @@ /* BEGIN main */ #set page( - header: locate(loc => { - if calc.odd(loc.page()) { - // NOTE: not able to programatically hide headings on new chapters for now - // issue: https://github.com/typst/typst/issues/1613 - - let section = query( - selector(heading.where(level: 2)).before(loc), - loc - ) - if section == () { - return none - } - - let sect-number(..headings) = { - let levels = headings.pos() - - if levels.len() > 1 { - [#levels.at(0).#levels.at(1)] - } else { - none - } - } - - text(9pt, number-width: "tabular")[ - #emph[ - #counter(heading).display(sect-number) - #h(1em) - #smallcaps(section.last().body) - ] - #h(1fr) - #counter(page).display("1") - ] - } else { - let chapters = query( - selector(heading.where(level: 1)).before(loc), - loc, - ) - // HACK: don't add headers in outlines (Chapter 0) - // This is only a workaround. Detailed mechanism of typst's pagebreaks - // needs to be further researched. - let chapter-counter = counter(heading.where(level: 1)).at(loc) - if chapter-counter == (0,) { - return none - } - - text(9pt, number-width: "tabular")[ - #counter(page).display("1") - #h(1fr) - 第#counter(heading.where(level: 1)).display("一")章 - #h(1em) - #chapters.last().body - ] - } - }) + header: page-header ) #counter(page).update(1) #show heading.where(level: 1): it => { - set page( - header: none, - //fill: luma(95%), - ) - - pagebreak(to: "odd", weak: true) - set text( 25pt, font: ("New Computer Modern", "Noto Serif CJK SC"), diff --git a/oi-wiki-export-typst/oi-wiki.typ b/oi-wiki-export-typst/oi-wiki.typ index f7e4811..a326dd0 100644 --- a/oi-wiki-export-typst/oi-wiki.typ +++ b/oi-wiki-export-typst/oi-wiki.typ @@ -8,6 +8,61 @@ #import "@preview/tiaoma:0.1.0" /* END imports */ +#let page-header = locate(loc => { + if calc.odd(loc.page()) { + // NOTE: not able to programatically hide headings on new chapters for now + // issue: https://github.com/typst/typst/issues/1613 + + let section = query( + selector(heading.where(level: 2)).before(loc), + loc + ) + if section == () { + return none + } + + let sect-number(..headings) = { + let levels = headings.pos() + + if levels.len() > 1 { + [#levels.at(0).#levels.at(1)] + } else { + none + } + } + + text(9pt, number-width: "tabular")[ + #emph[ + #counter(heading).display(sect-number) + #h(1em) + #smallcaps(section.last().body) + ] + #h(1fr) + #counter(page).display("1") + ] + } else { + let chapters = query( + selector(heading.where(level: 1)).before(loc), + loc, + ) + // HACK: don't add headers in outlines (Chapter 0) + // This is only a workaround. Detailed mechanism of typst's pagebreaks + // needs to be further researched. + let chapter-counter = counter(heading.where(level: 1)).at(loc) + if chapter-counter == (0,) { + return none + } + + text(9pt, number-width: "tabular")[ + #counter(page).display("1") + #h(1fr) + 第#counter(heading.where(level: 1)).display("一")章 + #h(1em) + #chapters.last().body + ] + } + } +) #let horizontalrule = align(center, block( sym.ast.op + h(1em) + sym.ast.op + h(1em) + sym.ast.op