mirror of
https://0xacab.org/anarsec/anarsec.guide.git
synced 2025-06-07 22:32:55 -04:00
layout fr
This commit is contained in:
parent
65777895db
commit
05a1171289
14 changed files with 88 additions and 42 deletions
|
@ -22,7 +22,8 @@ class Converter:
|
|||
self.pandoc_binary = pandoc_binary
|
||||
self.typst_binary = typst_binary
|
||||
self.anarsec_root = anarsec_root
|
||||
self.post_id = post_id
|
||||
self.post_id = post_id.split('.',1)[0]
|
||||
self.post_lang = post_id.split('.',1)[1]
|
||||
self.force = force
|
||||
self.verbose = verbose
|
||||
|
||||
|
@ -43,22 +44,34 @@ class Converter:
|
|||
"""Convert the input file to the output file. This method should only be run once."""
|
||||
|
||||
# Set glossary file
|
||||
glossary_file = self.anarsec_root / "content" / "glossary" / "_index.md"
|
||||
if self.post_lang == 'en':
|
||||
glossary_file = self.anarsec_root / "content" / "glossary" / "_index.md"
|
||||
else:
|
||||
glossary_file = self.anarsec_root / "content" / "glossary" / f"_index.{self.post_lang}.md"
|
||||
if not glossary_file.exists() or not glossary_file.is_file():
|
||||
raise RuntimeError(f"Glossary file '{glossary_file}' doesn't exist or isn't a file.")
|
||||
|
||||
# Set recommendations file
|
||||
recommendations_file = self.anarsec_root / "content" / "recommendations" / "_index.md"
|
||||
if self.post_lang == 'en':
|
||||
recommendations_file = self.anarsec_root / "content" / "recommendations" / "_index.md"
|
||||
else:
|
||||
recommendations_file = self.anarsec_root / "content" / "recommendations" / f"_index.{self.post_lang}.md"
|
||||
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 self.post_lang == 'en':
|
||||
series_file = self.anarsec_root / "content" / "series" / "_index.md"
|
||||
else:
|
||||
series_file = self.anarsec_root / "content" / "series" / f"_index.{self.post_lang}.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 self.post_lang == 'en':
|
||||
input_path = self.post_directory / "index.md"
|
||||
else:
|
||||
input_path = self.post_directory / f"index.{self.post_lang}.md"
|
||||
if not input_path.exists() or not input_path.is_file():
|
||||
raise RuntimeError(f"Post Markdown file '{input_path}' doesn't exist or isn't a file.")
|
||||
|
||||
|
@ -73,7 +86,10 @@ class Converter:
|
|||
# For each paper size
|
||||
for paper_size in ["a4", "letter"]:
|
||||
# Set the output path
|
||||
output_path = self.post_directory / f"{self.post_id}-{paper_size}.pdf"
|
||||
if self.post_lang == 'en':
|
||||
output_path = self.anarsec_root / "static" / "posts" / self.post_id / f"{self.post_id}-{paper_size}-{self.post_lang}.pdf"
|
||||
else:
|
||||
output_path = self.anarsec_root / "static" / self.post_lang / "posts" / self.post_id / f"{self.post_id}-{paper_size}-{self.post_lang}.pdf"
|
||||
if not self.force and output_path.exists():
|
||||
raise RuntimeError(f"Output file '{output_path}' already exists.")
|
||||
|
||||
|
@ -122,7 +138,10 @@ class Converter:
|
|||
|
||||
# Add recommendations to the Markdown content
|
||||
recommendations = re.search(r'\+{3}.*?\+{3}(.*)', recommendations_file.open().read(), re.MULTILINE | re.DOTALL).group(1)
|
||||
markdown_content += f"\n\n# Appendix: Recommendations\n\n{recommendations}\n\n"
|
||||
if self.post_lang == 'en':
|
||||
markdown_content += f"\n\n# Appendix: Recommendations\n\n{recommendations}\n\n"
|
||||
if self.post_lang == 'fr':
|
||||
markdown_content += f"\n\n# Annexe: Recommendations\n\n{recommendations}\n\n"
|
||||
|
||||
# Make all images paths relative in the Markdown content
|
||||
for extension in ["jpg", "png", "webp", "jpeg", "gif"]:
|
||||
|
@ -138,7 +157,10 @@ class Converter:
|
|||
|
||||
# Add glossary entries to the Markdown content
|
||||
if glossary_entries:
|
||||
markdown_content += "\n\n# Appendix: Glossary\n\n"
|
||||
if self.post_lang == 'en':
|
||||
markdown_content += "\n\n# Appendix: Glossary\n\n"
|
||||
if self.post_lang == 'fr':
|
||||
markdown_content += "\n\n# Annexe: Glossaire\n\n"
|
||||
for entry, entry_content in glossary.items():
|
||||
if entry in glossary_entries:
|
||||
markdown_content += f"## {entry_content[0]}\n\n{entry_content[1]}\n\n"
|
||||
|
@ -159,6 +181,14 @@ class Converter:
|
|||
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])
|
||||
|
||||
# mutlilingual categories
|
||||
category = toml_front_matter["taxonomies"]["categories"][0]
|
||||
if self.post_lang == 'fr':
|
||||
if category == 'Defensive':
|
||||
category = 'Défensif'
|
||||
if category == 'Offensive':
|
||||
category = 'Offensif'
|
||||
|
||||
# Build the full typst file
|
||||
full_typst_path = pathlib.Path(workingDirectory) / f"{self.post_id}-full.typ"
|
||||
full_typst = f"""
|
||||
|
@ -173,8 +203,9 @@ class Converter:
|
|||
lastediteddate: "{toml_front_matter["extra"]["dateedit"]}",
|
||||
description: "{description}",
|
||||
subtitle: "{toml_front_matter.get("description")}",
|
||||
category: "{toml_front_matter["taxonomies"]["categories"][0]}",
|
||||
category: "{category}",
|
||||
backcoverinsidecontent: [{series_typst_path.open().read()}],
|
||||
lang: "{self.post_lang}",
|
||||
content
|
||||
)
|
||||
{typst_path.open().read()}
|
||||
|
@ -225,7 +256,7 @@ if __name__ == "__main__":
|
|||
parser.add_argument("--pandoc-binary", type = pathlib.Path, required = True, help = "Path to the Pandoc binary. Minimum required version is 3.1.5.")
|
||||
parser.add_argument("--typst-binary", type = pathlib.Path, required = True, help = "Path to the typst binary. Minimum required version is 0.6.0.")
|
||||
parser.add_argument("--anarsec-root", type = pathlib.Path, required = True, help = "Root of the Anarsec repository.")
|
||||
parser.add_argument("--post-id", type = str, required = True, help = "ID of the Anarsec post to convert, i.e. the name of the post folder in '/content/posts'.")
|
||||
parser.add_argument("--post-id", type = str, required = True, help = "ID of the Anarsec post to convert with language added after a period, i.e. 'nophones.en' and 'nophones.fr', where 'nophones' is the name of the post folder in '/content/posts'.")
|
||||
parser.add_argument("-f", "--force", dest = "force", default = False, action = "store_true", help = "Replace the output files if they already exist.")
|
||||
parser.add_argument("-v", "--verbose", dest = "verbose", default = False, action = "store_true", help = "Print messages when the output files are created.")
|
||||
arguments = parser.parse_args()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue