mirror of
https://github.com/tldr-pages/tldr.git
synced 2024-09-11 12:05:35 +03:00
feat/scripts: support generating PDFs for platforms (#11195)
* feat/scripts: support generating PDFs for platform Signed-off-by: K.B.Dharun Krishna <kbdharunkrishna@gmail.com> * render.py: reformat code for black Signed-off-by: K.B.Dharun Krishna <kbdharunkrishna@gmail.com> * PDF/README: update command Signed-off-by: K.B.Dharun Krishna <kbdharunkrishna@gmail.com> * render.py: update code Signed-off-by: K.B.Dharun Krishna <kbdharunkrishna@gmail.com> * render.py: drop platform none parameter from main Signed-off-by: K.B.Dharun Krishna <kbdharunkrishna@gmail.com> --------- Signed-off-by: K.B.Dharun Krishna <kbdharunkrishna@gmail.com>
This commit is contained in:
parent
8bf032d729
commit
4e53530691
@ -19,7 +19,7 @@ Make sure OS specific dependencies for WeasyPrint are installed by following the
|
||||
|
||||
Generating the PDF is as simple as running:
|
||||
|
||||
python3 render.py <path-to-pages-directory> [--color <color-scheme>] [--output <filename>]
|
||||
python3 render.py <path-to-pages-directory> [--color <color-scheme>] [--output <filename>] [--platform <platform-name>]
|
||||
|
||||
Complete information about the arguments can be viewed by running:
|
||||
|
||||
|
@ -17,7 +17,7 @@ from datetime import datetime
|
||||
from weasyprint import HTML
|
||||
|
||||
|
||||
def main(loc, colorscheme, output_filename):
|
||||
def main(loc, colorscheme, output_filename, platform):
|
||||
# Checking correctness of path
|
||||
if not os.path.isdir(loc):
|
||||
print("Invalid directory. Please try again!", file=sys.stderr)
|
||||
@ -43,6 +43,9 @@ def main(loc, colorscheme, output_filename):
|
||||
|
||||
# Writing names of all directories inside 'pages' to a list
|
||||
for operating_sys in sorted(os.listdir(loc)):
|
||||
if platform and operating_sys not in platform:
|
||||
continue
|
||||
|
||||
# Required string to create directory title pages
|
||||
html += (
|
||||
"<h1 class=title-dir>"
|
||||
@ -70,6 +73,9 @@ def main(loc, colorscheme, output_filename):
|
||||
html += "</body></html>"
|
||||
|
||||
# Writing the PDF to disk
|
||||
if platform:
|
||||
output_filename = f"{output_filename[:-4]}-{'+'.join(platform)}.pdf"
|
||||
|
||||
print("\nConverting all pages to PDF...")
|
||||
HTML(string=html).write_pdf(output_filename, stylesheets=csslist)
|
||||
|
||||
@ -97,6 +103,12 @@ if __name__ == "__main__":
|
||||
default="tldr-book.pdf",
|
||||
help="Custom filename for the output PDF (default is 'tldr-book.pdf')",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-p",
|
||||
"--platform",
|
||||
nargs="+",
|
||||
help="Specify one or more platforms to generate PDFs for",
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
main(args.dir_path, args.color, args.output)
|
||||
main(args.dir_path, args.color, args.output, args.platform)
|
||||
|
Loading…
Reference in New Issue
Block a user