Skip to content

Commit 4a49509

Browse files
committed
make library
1 parent f84528b commit 4a49509

4 files changed

Lines changed: 125 additions & 57 deletions

File tree

.github/workflows/ci-typ.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,16 @@ jobs:
4444
run: |
4545
cp -a typ/mdbook/assets/. book/
4646
typst compile typ/book.typ --input lang=en --input target=html book --features bundle,html -f bundle
47-
typst compile typ/book.typ --input lang=en --input target=pdf book/rust_embedded_book_en.pdf
47+
typst compile typ/book.typ --input lang=en --input target=pdf book/book_en.pdf
4848
4949
- name: Build translated book
5050
run: |
51-
typst compile typ/book.typ --input lang=zh --input target=html book/zh --features bundle,html -f bundle
52-
typst compile typ/book.typ --input lang=zh --input target=pdf book/rust_embedded_book_zh.pdf
53-
typst compile typ/book.typ --input lang=de --input target=html book/de --features bundle,html -f bundle
54-
typst compile typ/book.typ --input lang=de --input target=pdf book/rust_embedded_book_de.pdf
55-
typst compile typ/book.typ --input lang=uk --input target=html book/uk --features bundle,html -f bundle
56-
typst compile typ/book.typ --input lang=uk --input target=pdf book/rust_embedded_book_uk.pdf
51+
typst compile typ/book.typ --input lang=zh --input target=html book --features bundle,html -f bundle
52+
typst compile typ/book.typ --input lang=zh --input target=pdf book/book_zh.pdf
53+
typst compile typ/book.typ --input lang=de --input target=html book --features bundle,html -f bundle
54+
typst compile typ/book.typ --input lang=de --input target=pdf book/book_de.pdf
55+
typst compile typ/book.typ --input lang=uk --input target=html book --features bundle,html -f bundle
56+
typst compile typ/book.typ --input lang=uk --input target=pdf book/book_uk.pdf
5757
5858
- name: Check links
5959
run: linkchecker book

typ/book.typ

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#import "config.typ": *
2-
#import "mdbook/lib.typ": book
2+
#import "@local/typbook:0.1.0": book
33

44
#let sources = (
55
"intro/index": (

typ/mdbook/lib.typ

Lines changed: 113 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
//#import "../config.typ": *
31
#import "icons.typ": builtin-icon
42
#import "scripts.typ": builtin-script
53

@@ -154,7 +152,7 @@
154152
]
155153
]
156154
#builtin-script("show-language-list")
157-
#html.a(href: root_pth+"rust_embedded_book_"+lang+".pdf", title: "PDF version of this book", aria-label: "PDF", builtin-icon("pdf", id: "book-pdf"))
155+
#html.a(href: root_pth+"book_"+lang+".pdf", title: "PDF version of this book", aria-label: "PDF", builtin-icon("pdf", id: "book-pdf"))
158156
#html.a(href: "https://github.com/rust-embedded/book", title: "Git repository", aria-label: "Git repository", builtin-icon("github"))
159157
]
160158
]
@@ -185,7 +183,7 @@
185183
#html.div(class: "sidebar-resize-indicator")
186184
]
187185
]
188-
#let toc(sources, lang, default_lang) = document("toc.html")[
186+
#let toc(sources, out, lang, default_lang) = document(out)[
189187
#html.html(lang: lang, class: "light", dir: ltr)[
190188
#html.head[
191189
#html.meta(charset: "utf-8")
@@ -296,59 +294,125 @@
296294
]
297295
]
298296

299-
#let book(
300-
tgt,
297+
#let asset_list = (
298+
"ayu-highlight-3fdfc3ac.css",
299+
"book-609e4cb8.js",
300+
"clipboard-1626706a.min.js",
301+
"css/chrome-d279d366.css",
302+
"css/general-e96d0476.css",
303+
"css/print-9e4910d8.css",
304+
"css/variables-8adf115d.css",
305+
"elasticlunr-ef4e11c1.min.js",
306+
"favicon-8114d1fc.png",
307+
"favicon-de23e50b.svg",
308+
"fonts/fonts-9644e21d.css",
309+
"fonts/OPEN-SANS-LICENSE.txt",
310+
"fonts/open-sans-v17-all-charsets-300-7736aa35.woff2",
311+
"fonts/open-sans-v17-all-charsets-300italic-2c7b95c0.woff2",
312+
"fonts/open-sans-v17-all-charsets-600-486c6759.woff2",
313+
"fonts/open-sans-v17-all-charsets-600italic-1a3e8659.woff2",
314+
"fonts/open-sans-v17-all-charsets-700-c22fe8c7.woff2",
315+
"fonts/open-sans-v17-all-charsets-700italic-238ae959.woff2",
316+
"fonts/open-sans-v17-all-charsets-800-3d2c812a.woff2",
317+
"fonts/open-sans-v17-all-charsets-800italic-ba1521ec.woff2",
318+
"fonts/open-sans-v17-all-charsets-italic-6c9463f7.woff2",
319+
"fonts/open-sans-v17-all-charsets-regular-2e3b1d34.woff2",
320+
"fonts/SOURCE-CODE-PRO-LICENSE.txt",
321+
"fonts/source-code-pro-v11-all-charsets-500-2bdd9410.woff2",
322+
"highlight-493f70e1.css",
323+
"highlight-abc7f01d.js",
324+
"mark-09e88c2c.min.js",
325+
"searcher-09f2665d.js",
326+
"searchindex-8ec871e3.js",
327+
"toc-7ac66f26.js",
328+
"tomorrow-night-4c0ae647.css",
329+
)
330+
331+
#let html_book(
301332
sources,
302333
lang,
303334
languages,
304-
book_title: "The Book",
305-
default_lang: "en",
335+
book_title,
336+
default_lang,
306337
) = {
307338
let sa = source_array(sources)
308-
if tgt == "pdf" [
309-
#set par(justify: true)
310-
#set heading(numbering: "1.")
311-
#show heading.where(level: 1): it => { pagebreak();it }
312-
313-
#show link: it => { text(fill: blue, it) }
314-
#show raw.where(block: true): it => {
315-
block(
316-
fill: rgb("#F6F6F6"),
317-
outset: 5pt,
318-
it
319-
)
339+
if lang == default_lang {
340+
for path in asset_list {
341+
asset(path, read("assets/"+path, encoding: none))
342+
}
343+
}
344+
let prefix = if lang != default_lang { lang+"/" } else { "" }
345+
toc(sources, prefix+"toc.html", lang, default_lang)
346+
for (i, (path, source, title)) in sa.enumerate() {
347+
let (prev_path, _, _) = if i > 0 { sa.at(i - 1) } else { (none, none, none) }
348+
let (next_path, _, _) = sa.at(i + 1, default: (none, none, none))
349+
let out = prefix+path + ".html"
350+
let depth = path.split("/").len() - 1
351+
[
352+
#book_page(source, out, lang, languages, default_lang, to-string(title) + " - " + book_title, depth, sidebar(depth), prev_path, next_path) #lbl(path)
353+
]
354+
if i == 0 {
355+
let depth = 0
356+
book_page(source, prefix+"index.html", lang, languages, default_lang, to-string(title) + " - " + book_title, depth, sidebar(depth), prev_path, next_path)
320357
}
358+
}
359+
}
321360

322-
#v(1fr)
323-
#align(center, text(size: 40pt, [The Embedded Rust Book\ (#languages.at(lang))]))
324-
#v(1fr)
361+
#let pdf_book(title_page, sources) = [
362+
#let sa = source_array(sources)
363+
#set par(justify: true)
364+
#set heading(numbering: "1.")
365+
#show heading.where(level: 1): it => { pagebreak();it }
325366

326-
#outline(depth: 3)
327-
#let part = "main"
328-
#for (path, source, _) in sa {
329-
if part == "main" and path.starts-with("appendix/") {
330-
path = "appendix"
331-
counter(heading).update(0)
332-
set heading(numbering: "A.1.")
333-
source
334-
} else {
335-
source
336-
}
367+
#show link: it => { text(fill: blue, it) }
368+
#show raw.where(block: true): it => {
369+
block(
370+
fill: rgb("#F6F6F6"),
371+
outset: 5pt,
372+
it
373+
)
374+
}
375+
376+
#title_page
377+
378+
#outline(depth: 3)
379+
#let part = "main"
380+
#for (path, source, _) in sa {
381+
if part == "main" and path.starts-with("appendix/") {
382+
path = "appendix"
383+
counter(heading).update(0)
384+
set heading(numbering: "A.1.")
385+
source
386+
} else {
387+
source
337388
}
338-
] else {
339-
toc(sources, lang, default_lang)
340-
for (i, (path, source, title)) in sa.enumerate() {
341-
let (prev_path, _, _) = if i > 0 { sa.at(i - 1) } else { (none, none, none) }
342-
let (next_path, _, _) = sa.at(i + 1, default: (none, none, none))
343-
let out = path + ".html"
344-
let depth = path.split("/").len() - 1
389+
}
390+
]
391+
392+
#let book(
393+
tgt,
394+
sources,
395+
lang,
396+
languages,
397+
book_title: "The Book",
398+
default_lang: "en",
399+
) = {
400+
if tgt == "pdf" {
401+
pdf_book(
345402
[
346-
#book_page(source, out, lang, languages, default_lang, to-string(title) + " - " + book_title, depth, sidebar(depth), prev_path, next_path) #lbl(path)
347-
]
348-
if i == 0 {
349-
let depth = 0
350-
book_page(source, "index.html", lang, languages, default_lang, to-string(title) + " - " + book_title, depth, sidebar(depth), prev_path, next_path)
351-
}
352-
}
353-
}
403+
#v(1fr)
404+
#align(center, text(size: 40pt, [#book_title\ (#languages.at(lang))]))
405+
#v(1fr)
406+
],
407+
sources,
408+
)
409+
} else if tgt == "html" {
410+
html_book(
411+
sources,
412+
lang,
413+
languages,
414+
book_title,
415+
default_lang
416+
)
417+
}
354418
}

typ/mdbook/typst.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[package]
2+
name = "typbook"
3+
version = "0.1.0"
4+
entrypoint = "lib.typ"

0 commit comments

Comments
 (0)