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

* scrips: build and deploy PDF pages for all languages

* cleanup/render.py: reformat code

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

* Apply suggestions from code review

Co-authored-by: Matthew Peveler <matt.peveler@gmail.com>

* scrpts/pdf: update README, refactor code

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

* test/ci: building PDF was wildcard

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

* test/ci: building translations as wildcard 2

* test/ci: fix flag in PDF building

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

* test/ci: update build pdf action

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

* test/ci: extend PDF exclusion list

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

* cleanup/ci: update PDF translation build

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

* scripts/pdf: add website and repo link

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

* test/ci: move PDF build to seperate script file

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

* test/ci: minor fixes to build pdf script

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

* cleanup/ci: update build PDF

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

* scripts: update font family, minor fix

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

* fix/deploy: sha256sum command

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

---------

Signed-off-by: K.B.Dharun Krishna <kbdharunkrishna@gmail.com>
Co-authored-by: Matthew Peveler <matt.peveler@gmail.com>
This commit is contained in:
K.B.Dharun Krishna
2023-10-13 09:58:02 +05:30
committed by GitHub
parent 7856124245
commit a2ab577848
8 changed files with 66 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-pages.pdf')",
)
args = parser.parse_args()
main(args.dir_path, args.color)
main(args.dir_path, args.color, args.output)