From 55d64da01d54d6aa1c4b919d0bc73f416bf3893e Mon Sep 17 00:00:00 2001
From: anarsec <anarsec@riseup.net>
Date: Tue, 15 Aug 2023 20:37:37 +0000
Subject: [PATCH] typst update 0.7 + back cover

---
 layout/anarsec_article.typ              | 22 ++++++++++++++++++++++
 layout/python/anarsec_article_to_pdf.py | 25 ++++++++++++++++++++++---
 2 files changed, 44 insertions(+), 3 deletions(-)

diff --git a/layout/anarsec_article.typ b/layout/anarsec_article.typ
index 2032545..aa78ed3 100644
--- a/layout/anarsec_article.typ
+++ b/layout/anarsec_article.typ
@@ -6,6 +6,7 @@
   description: none,
   subtitle: none,
   category: none,
+  backcoverinsidecontent: none,
   content
 ) = {
   
@@ -125,6 +126,26 @@
   content
   
   set page(numbering: none)
+  
+  // back cover inside
+  page()[
+    // set headings
+    #show heading.where(level: 1): it => {
+      block(width: 100%)[
+        #set align(center)
+        #set text(size: 22pt, font: "Jost")
+        #text(it.body)
+        #v(10pt)
+      ]
+    }
+    
+    // format links
+    #show link: it => {
+      it.body
+    }
+  
+    #backcoverinsidecontent
+  ]
 
   // back cover
   page()[
@@ -148,3 +169,4 @@
   ]
 ]
 
+
diff --git a/layout/python/anarsec_article_to_pdf.py b/layout/python/anarsec_article_to_pdf.py
index b4d2fb2..3be71a7 100644
--- a/layout/python/anarsec_article_to_pdf.py
+++ b/layout/python/anarsec_article_to_pdf.py
@@ -52,6 +52,11 @@ class Converter:
         if not recommendations_file.exists() or not recommendations_file.is_file():
             raise RuntimeError(f"Recommendations file '{recommendations_file}' doesn't exist or isn't a file.")
             
+        # Set series file
+        series_file = self.anarsec_root / "content" / "series" / "_index.md"
+        if not series_file.exists() or not series_file.is_file():
+            raise RuntimeError(f"Series file '{series_file}' doesn't exist or isn't a file.")
+            
         # Set input path
         input_path = self.post_directory / "index.md"
         if not input_path.exists() or not input_path.is_file():
@@ -61,6 +66,9 @@ class Converter:
         glossary = dict()
         for match in re.findall(r'### (.*?)\n+(.*?)\n*(?=###|\Z)', glossary_file.open().read(), re.DOTALL | re.MULTILINE):
             glossary[slugify.slugify(match[0])] = (match[0], match[1])
+            
+        # Load the series markdown
+        series_markdown = re.search(r'\+{3}.*?\+{3}(.*)', series_file.open().read(), re.MULTILINE | re.DOTALL).group(1)
         
         # For each paper size
         for paper_size in ["a4", "letter"]:
@@ -153,6 +161,14 @@ class Converter:
                 typst_path = pathlib.Path(workingDirectory) / f"{self.post_id}.typ"
                 subprocess.check_call([str(self.pandoc_binary), "-f", "markdown", "-t", "typst", "--columns", "999999", "-o", typst_path, input_markdown_path])
                 
+                # Write the series markdown to a file
+                series_markdown_path = pathlib.Path(workingDirectory) / "series-markdown.md"
+                series_markdown_path.open("w").write(series_markdown)
+                
+                # Convert the series markdown to typst
+                series_typst_path = pathlib.Path(workingDirectory) / f"series.typ"
+                subprocess.check_call([str(self.pandoc_binary), "-f", "markdown", "-t", "typst", "--columns", "999999", "-o", series_typst_path, series_markdown_path])
+                
                 # Build the full typst file
                 full_typst_path = pathlib.Path(workingDirectory) / f"{self.post_id}-full.typ"
                 full_typst = f"""
@@ -168,6 +184,7 @@ class Converter:
   description: "{description}",
   subtitle: "{toml_front_matter.get("description")}",
   category: "{toml_front_matter["taxonomies"]["categories"][0]}",
+  backcoverinsidecontent: [{series_typst_path.open().read()}],
   content
 )
 {typst_path.open().read()}
@@ -180,18 +197,19 @@ class Converter:
                 os.environ["TYPST_FONT_PATHS"] = str(workingDirectory)
 
                 subprocess.check_call(
-                    [str(self.typst_binary), "--root", workingDirectory, "compile", full_typst_path, pdf_path],
+                    [str(self.typst_binary), "compile", full_typst_path, pdf_path, "--root", workingDirectory],
                     stderr = subprocess.STDOUT
                 )
                 
-                # Insert blank pages before the back cover if needed
+                # Insert blank pages before the back cover and back cover inside if needed
                 pdf_reader = PyPDF2.PdfFileReader(pdf_path.open("rb"))
                 if len(pdf_reader.pages) % 4 != 0:
                     pdf_writer = PyPDF2.PdfFileWriter()
-                    for page in pdf_reader.pages[:-1]:
+                    for page in pdf_reader.pages[:-2]:
                         pdf_writer.addPage(page)
                     for i in range(4 - len(pdf_reader.pages) % 4):
                         pdf_writer.addBlankPage()
+                    pdf_writer.addPage(pdf_reader.pages[-2])
                     pdf_writer.addPage(pdf_reader.pages[-1])
                     pdf_with_blank_pages_path = pathlib.Path(workingDirectory) / f"{self.post_id}-with-blank-pages.pdf"
                     pdf_writer.write(pdf_with_blank_pages_path.open("wb"))
@@ -234,3 +252,4 @@ if __name__ == "__main__":
     
     # Convert
     converter.convert()
+
-- 
GitLab