|
1 | | - |
2 | | -//#import "../config.typ": * |
3 | 1 | #import "icons.typ": builtin-icon |
4 | 2 | #import "scripts.typ": builtin-script |
5 | 3 |
|
|
154 | 152 | ] |
155 | 153 | ] |
156 | 154 | #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")) |
158 | 156 | #html.a(href: "https://github.com/rust-embedded/book", title: "Git repository", aria-label: "Git repository", builtin-icon("github")) |
159 | 157 | ] |
160 | 158 | ] |
|
185 | 183 | #html.div(class: "sidebar-resize-indicator") |
186 | 184 | ] |
187 | 185 | ] |
188 | | -#let toc(sources, lang, default_lang) = document("toc.html")[ |
| 186 | +#let toc(sources, out, lang, default_lang) = document(out)[ |
189 | 187 | #html.html(lang: lang, class: "light", dir: ltr)[ |
190 | 188 | #html.head[ |
191 | 189 | #html.meta(charset: "utf-8") |
|
296 | 294 | ] |
297 | 295 | ] |
298 | 296 |
|
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( |
301 | 332 | sources, |
302 | 333 | lang, |
303 | 334 | languages, |
304 | | - book_title: "The Book", |
305 | | - default_lang: "en", |
| 335 | + book_title, |
| 336 | + default_lang, |
306 | 337 | ) = { |
307 | 338 | 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) |
320 | 357 | } |
| 358 | + } |
| 359 | +} |
321 | 360 |
|
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 } |
325 | 366 |
|
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 |
337 | 388 | } |
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( |
345 | 402 | [ |
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 | + } |
354 | 418 | } |
0 commit comments