|
14 | 14 |
|
15 | 15 | (require 'asdf) |
16 | 16 |
|
| 17 | +;; You need the str library already installed: |
| 18 | +;; (ql:quickload "str") |
| 19 | +;; We use str:replace-all which relies on ppcre, so we need a library anyways. |
| 20 | +;; That's why I'm doing and using CIEL: small scripts are much easier to run and share. |
| 21 | + |
| 22 | +(handler-case |
| 23 | + (require 'str) |
| 24 | + (error () |
| 25 | + (format t "~&Please install the 'str' library to generate the PDF: (ql:quickload \"str\")~&") |
| 26 | + (uiop:quit 1))) |
| 27 | + |
17 | 28 | (defparameter chapters |
18 | 29 | (list |
19 | 30 | "index.md" |
|
71 | 82 | (defparameter *epub-command-placeholder* "pandoc -o ~a --toc metadata.txt ~a" |
72 | 83 | "format with book name and sources file.") |
73 | 84 |
|
| 85 | +(defparameter pdf-toc "== Table Of Contents (High-level) |
| 86 | +<high-level-table-of-contents> |
| 87 | +#outline(title: none, depth:1) |
| 88 | +
|
| 89 | +#pagebreak() |
| 90 | +
|
| 91 | +== Table Of Contents (Detailed) |
| 92 | +<detailed-table-of-contents> |
| 93 | +#outline(title: none, depth:3) |
| 94 | +") |
| 95 | + |
74 | 96 | (defun reset-target () |
75 | 97 | (uiop:run-program (format nil "echo > ~a" *full-markdown*))) |
76 | 98 |
|
|
95 | 117 | (format t "~&Generating a very short PDF sample.~&") |
96 | 118 | (uiop:run-program (format nil "typst compile ~a" *typst-preamble*))) |
97 | 119 |
|
| 120 | +(defun insert-pdf-tocs () |
| 121 | + "Replace {{PDF-TOCS}} in the .typ file with a proper TOC declaration. |
| 122 | +
|
| 123 | + Using sed was tooooo cumbersome." |
| 124 | + (format t "~&Inserting our table of contents into full-with-preamble.typ…~&") |
| 125 | + (let* ((file.typ "full-with-preamble.typ") |
| 126 | + (file-string (uiop:read-file-string file.typ)) |
| 127 | + (new-content (str:replace-all "{{PDF-TOCS}}" pdf-toc file-string))) |
| 128 | + (str:to-file file.typ new-content))) |
| 129 | + |
98 | 130 | (defun to-pdf () |
99 | 131 | "Needs pandoc >= 3.8 with Markdown to Typst conversion, |
100 | 132 | and the typst binary on the path." |
|
114 | 146 | :output t |
115 | 147 | :error-output t) |
116 | 148 |
|
| 149 | + ;; Insert our two outlines: |
| 150 | + (insert-pdf-tocs) |
| 151 | + |
117 | 152 | ;; Compile the Typst document: |
118 | 153 | (uiop:run-program "typst compile full-with-preamble.typ" :output t :error-output t) |
119 | 154 | ; todo utiliser min-book? |
120 | | - (uiop:run-program "mv full-with-preamble.pdf common-lisp-cookbook.pdf")) |
| 155 | + (uiop:run-program "mv full-with-preamble.pdf common-lisp-cookbook.pdf") |
| 156 | + (format t "Done: common-lisp-cookbook.pdf")) |
121 | 157 |
|
122 | 158 | (defun build-full-source () |
123 | 159 | (format t "Creating the full source into ~a...~&" *full-markdown*) |
|
0 commit comments