scripts: build and deploy PDF pages for translations (#10969)

* scripts: build and deploy PDF pages for translations

Signed-off-by: K.B.Dharun Krishna <kbdharunkrishna@gmail.com>

* render.py: fix typo in filename description

---------

Signed-off-by: K.B.Dharun Krishna <kbdharunkrishna@gmail.com>
This commit is contained in:
K.B.Dharun Krishna
2023-10-22 02:34:22 +05:30
committed by GitHub
parent d9ad48e058
commit e35b482300
8 changed files with 67 additions and 24 deletions

View File

@@ -17,7 +17,7 @@ from datetime import datetime
from weasyprint import HTML
def main(loc, colorscheme):
def main(loc, colorscheme, output_filename):
# Checking correctness of path
if not os.path.isdir(loc):
print("Invalid directory. Please try again!", file=sys.stderr)
@@ -31,11 +31,13 @@ def main(loc, colorscheme):
# A string that stores all pages in HTML format
html = (
'<!doctype html><html><head><meta charset="utf-8"></head>'
+ "<body><h1 class=title-main>tldr pages</h1>"
+ "<body><h1 class=title-main>tldr pages book</h1>"
+ "<div class=title-sub>Simplified and community-driven man pages</div>"
+ "<div class=title-sub><em><small>Generated on "
+ datetime.now().strftime("%c")
+ "</small></em></div>"
+ "</small></em></div><br><br>"
+ "<div class=title-sub>Website: <a href=https://tldr.sh>https://tldr.sh</a></div><br>"
+ "<div class=title-sub>GitHub: <a href=https://github.com/tldr-pages/tldr>https://github.com/tldr-pages/tldr</a></div><br>"
+ '<p style="page-break-before: always" ></p>'
)
@@ -69,10 +71,10 @@ def main(loc, colorscheme):
# Writing the PDF to disk
print("\nConverting all pages to PDF...")
HTML(string=html).write_pdf("tldr-pages.pdf", stylesheets=csslist)
HTML(string=html).write_pdf(output_filename, stylesheets=csslist)
if os.path.exists("tldr-pages.pdf"):
print("\nCreated tldr-pages.pdf in the current directory!\n")
if os.path.exists(output_filename):
print(f"\nCreated {output_filename} in the current directory!\n")
if __name__ == "__main__":
@@ -89,6 +91,12 @@ if __name__ == "__main__":
default="basic",
help="Color scheme of the PDF",
)
parser.add_argument(
"-o",
"--output",
default="tldr-book.pdf",
help="Custom filename for the output PDF (default is 'tldr-book.pdf')",
)
args = parser.parse_args()
main(args.dir_path, args.color)
main(args.dir_path, args.color, args.output)