65 lines
1.5 KiB
Python
Executable file
65 lines
1.5 KiB
Python
Executable file
#!/usr/bin/env python
|
|
|
|
# Usage: ./build.py INPUT_DIR OUTPUT_FILE
|
|
|
|
import os
|
|
# import re
|
|
import sys
|
|
import pypandoc
|
|
|
|
|
|
def gx_usage():
|
|
"""Show usage"""
|
|
print(f"Usage: {sys.argv[0]} METADATA_FILE INPUT_FILE OUTPUT_FILE")
|
|
print()
|
|
|
|
|
|
if len(sys.argv) != 4:
|
|
gx_usage()
|
|
|
|
metadata_file = sys.argv[1]
|
|
if not os.path.exists(metadata_file):
|
|
print(f"Metadata file not found: {metadata_file}")
|
|
sys.exit(1)
|
|
|
|
input_file = sys.argv[2]
|
|
if not os.path.exists(input_file):
|
|
print(f"Input file not found: {input_file}")
|
|
sys.exit(1)
|
|
|
|
# Get second
|
|
output_file = sys.argv[3]
|
|
if os.path.exists(output_file):
|
|
print(f"Output file already exists: {output_file}")
|
|
sys.exit(1)
|
|
|
|
# Build the pandoc options as a string
|
|
pandoc_cmd = [
|
|
"--toc",
|
|
"--number-sections",
|
|
"--include-in-header", "utils/docs/main.tex",
|
|
"--metadata-file", metadata_file,
|
|
# "-V", "linkcolor:blue",
|
|
# "-V", "geometry:a4paper",
|
|
# "-V", "geometry:margin=1.8cm",
|
|
"-V", "mainfont=DejaVu Serif",
|
|
"-V", "monofont=SauceCodePro Nerd Font",
|
|
"--pdf-engine=pdflatex",
|
|
"--filter=utils/docs/filter-nobg.hs",
|
|
]
|
|
|
|
# from glob import glob
|
|
# input_files = [os.path.join(dp, f) for dp, dn, filenames in os.walk(input_dir) for f in filenames if re.search(r'^[0-9].*\.md$', f)]
|
|
# input_files.sort()
|
|
|
|
# Convert all markdown files in the chapters/ subdirectory.
|
|
pypandoc.convert_file(
|
|
[input_file],
|
|
"pdf",
|
|
outputfile=output_file,
|
|
extra_args=pandoc_cmd,
|
|
)
|
|
|
|
print(f"Conversion completed. Output saved to: {output_file}")
|
|
|
|
#
|