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>
pull/23/head
K.B.Dharun Krishna 2023-10-13 09:58:02 +05:30 committed by GitHub
parent 7856124245
commit a2ab577848
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 66 additions and 24 deletions

View File

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

View File

@ -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"

Binary file not shown.

View File

@ -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 <path-to-pages-directory> --color <color-scheme>
python3 render.py <path-to-pages-directory> [--color <color-scheme>] [--output <filename>]
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)

View File

@ -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 {

33
scripts/pdf/build-pdf.sh Normal file
View File

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

Binary file not shown.

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)