mirror of
https://github.com/tldr-pages/tldr.git
synced 2025-06-07 17:26:02 +02: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
2 changed files with 15 additions and 3 deletions
|
@ -19,7 +19,7 @@ Make sure OS specific dependencies for WeasyPrint are installed by following the
|
||||||
|
|
||||||
Generating the PDF is as simple as running:
|
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:
|
Complete information about the arguments can be viewed by running:
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ from datetime import datetime
|
||||||
from weasyprint import HTML
|
from weasyprint import HTML
|
||||||
|
|
||||||
|
|
||||||
def main(loc, colorscheme, output_filename):
|
def main(loc, colorscheme, output_filename, platform):
|
||||||
# Checking correctness of path
|
# Checking correctness of path
|
||||||
if not os.path.isdir(loc):
|
if not os.path.isdir(loc):
|
||||||
print("Invalid directory. Please try again!", file=sys.stderr)
|
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
|
# Writing names of all directories inside 'pages' to a list
|
||||||
for operating_sys in sorted(os.listdir(loc)):
|
for operating_sys in sorted(os.listdir(loc)):
|
||||||
|
if platform and operating_sys not in platform:
|
||||||
|
continue
|
||||||
|
|
||||||
# Required string to create directory title pages
|
# Required string to create directory title pages
|
||||||
html += (
|
html += (
|
||||||
"<h1 class=title-dir>"
|
"<h1 class=title-dir>"
|
||||||
|
@ -70,6 +73,9 @@ def main(loc, colorscheme, output_filename):
|
||||||
html += "</body></html>"
|
html += "</body></html>"
|
||||||
|
|
||||||
# Writing the PDF to disk
|
# Writing the PDF to disk
|
||||||
|
if platform:
|
||||||
|
output_filename = f"{output_filename[:-4]}-{'+'.join(platform)}.pdf"
|
||||||
|
|
||||||
print("\nConverting all pages to PDF...")
|
print("\nConverting all pages to PDF...")
|
||||||
HTML(string=html).write_pdf(output_filename, stylesheets=csslist)
|
HTML(string=html).write_pdf(output_filename, stylesheets=csslist)
|
||||||
|
|
||||||
|
@ -97,6 +103,12 @@ if __name__ == "__main__":
|
||||||
default="tldr-book.pdf",
|
default="tldr-book.pdf",
|
||||||
help="Custom filename for the output PDF (default is '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()
|
args = parser.parse_args()
|
||||||
|
|
||||||
main(args.dir_path, args.color, args.output)
|
main(args.dir_path, args.color, args.output, args.platform)
|
||||||
|
|
Loading…
Add table
Reference in a new issue