diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c94bd4454d..c6309a4f60 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -43,7 +43,7 @@ jobs: - name: Build PDF if: github.repository == 'tldr-pages/tldr' && github.ref == 'refs/heads/main' working-directory: ./scripts/pdf - run: python render.py ../../pages -c solarized-light + run: bash build-pdf.sh - name: Deploy if: github.repository == 'tldr-pages/tldr' && github.ref == 'refs/heads/main' diff --git a/scripts/deploy.sh b/scripts/deploy.sh index d6db2654a9..712ad4d8be 100755 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -33,12 +33,13 @@ function upload_assets { mv -f "${TLDR_LANG_ARCHIVES_DIRECTORY}"/*.zip "$SITE_HOME/assets/" rm -rf "$TLDR_LANG_ARCHIVES_DIRECTORY" cp -f "$TLDRHOME/index.json" "$SITE_HOME/assets/" - cp -f "${TLDRHOME}/scripts/pdf/tldr-pages.pdf" "${SITE_HOME}/assets/tldr-book.pdf" + cp -f "${TLDRHOME}/scripts/pdf/tldr-book*.pdf" "${SITE_HOME}/assets/" + sha256sum \ "${SITE_HOME}/assets/index.json" \ "${SITE_HOME}/assets/"*.zip \ - "${SITE_HOME}/assets/tldr-book.pdf" \ + "${SITE_HOME}/assets/tldr-book*.pdf" \ > "${SITE_HOME}/assets/tldr.sha256sums" cd "$SITE_HOME" diff --git a/scripts/pdf/NotoSans-Regular.ttf b/scripts/pdf/NotoSans-Regular.ttf new file mode 100644 index 0000000000..7552fbe806 Binary files /dev/null and b/scripts/pdf/NotoSans-Regular.ttf differ diff --git a/scripts/pdf/README.md b/scripts/pdf/README.md index b93e1b1a10..088a3d0df8 100644 --- a/scripts/pdf/README.md +++ b/scripts/pdf/README.md @@ -2,12 +2,6 @@ This directory contains the script and related resources to generate a PDF document with all the `tldr` pages. -## Preview - -![cryptsetup in the Basic color-scheme.](https://user-images.githubusercontent.com/29029116/35637791-4e42af80-06db-11e8-8b8e-42ce6c905ff4.jpg) -![cryptsetup in the Solarized Light color-scheme.](https://user-images.githubusercontent.com/29029116/35637798-51e3784a-06db-11e8-9576-6e57ef5c5c20.jpg) -![cryptsetup in the Solarized Dark color-scheme.](https://user-images.githubusercontent.com/29029116/35637801-54449fce-06db-11e8-93f7-d90cdc34044b.jpg) - ## Highlights - No LaTeX dependencies for generating the PDF. @@ -25,14 +19,20 @@ Make sure OS specific dependencies for WeasyPrint are installed by following the Generating the PDF is as simple as running: - python3 render.py --color + python3 render.py [--color ] [--output ] Complete information about the arguments can be viewed by running: python3 render.py --help -The color-schemes that can be specified are: +Available color schemes: -* `basic` -* `solarized-light` -* `solarized-dark` +- `basic` +- `solarized-light` +- `solarized-dark` + +## Preview + +![cryptsetup in the Basic color-scheme.](https://user-images.githubusercontent.com/29029116/35637791-4e42af80-06db-11e8-8b8e-42ce6c905ff4.jpg) +![cryptsetup in the Solarized Light color-scheme.](https://user-images.githubusercontent.com/29029116/35637798-51e3784a-06db-11e8-9576-6e57ef5c5c20.jpg) +![cryptsetup in the Solarized Dark color-scheme.](https://user-images.githubusercontent.com/29029116/35637801-54449fce-06db-11e8-93f7-d90cdc34044b.jpg) diff --git a/scripts/pdf/basic.css b/scripts/pdf/basic.css index 52d794209e..cfc0f10d31 100644 --- a/scripts/pdf/basic.css +++ b/scripts/pdf/basic.css @@ -1,8 +1,8 @@ /* SPDX-License-Identifier: MIT */ @font-face { - font-family: "PT Serif"; - src: url("pt-serif-web-regular.ttf") format("truetype"); + font-family: "sans-serif"; + src: url("NotoSans-Regular.ttf") format("truetype"); } p { @@ -14,7 +14,7 @@ code { } h1, h2, h4, ul { - font-family: "PT Serif"; + font-family: "sans-serif"; } .title-main { diff --git a/scripts/pdf/build-pdf.sh b/scripts/pdf/build-pdf.sh new file mode 100644 index 0000000000..09df4d21a7 --- /dev/null +++ b/scripts/pdf/build-pdf.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: MIT + +# This script is executed by GitHub Actions when a PR is merged (i.e. in the `Build PDF` step). +set -ex + +function process_page { + pageDir="$1" + folder=$(basename "${pageDir}") + language="${folder##*.}" + case $folder in + pages.bn | pages.ja | pages.ko | pages.ml | pages.ta | pages.th | pages.zh | pages.zh_TW) + ;; + pages) + python3 render.py "${pageDir}" -c solarized-light + ;; + *) + python3 render.py "${pageDir}" -c basic -o "tldr-book-${language}.pdf" + ;; + esac +} + +function main { + for pageDir in ../../pages*; do + process_page "${pageDir}" + done +} + +################################### +# MAIN +################################### + +main diff --git a/scripts/pdf/pt-serif-web-regular.ttf b/scripts/pdf/pt-serif-web-regular.ttf deleted file mode 100644 index 5310691a99..0000000000 Binary files a/scripts/pdf/pt-serif-web-regular.ttf and /dev/null differ diff --git a/scripts/pdf/render.py b/scripts/pdf/render.py index a639acfe83..bf1a361e8d 100644 --- a/scripts/pdf/render.py +++ b/scripts/pdf/render.py @@ -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 = ( '' - + "

tldr pages

" + + "

tldr pages book

" + "
Simplified and community-driven man pages
" + "
Generated on " + datetime.now().strftime("%c") - + "
" + + "

" + + "
" + + "
" + '

' ) @@ -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)