mirror of
https://github.com/tldr-pages/tldr.git
synced 2025-04-22 01:02:09 +02:00
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:
parent
7856124245
commit
a2ab577848
8 changed files with 66 additions and 24 deletions
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
|
@ -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'
|
||||
|
|
|
@ -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"
|
||||
|
|
BIN
scripts/pdf/NotoSans-Regular.ttf
Normal file
BIN
scripts/pdf/NotoSans-Regular.ttf
Normal file
Binary file not shown.
|
@ -2,12 +2,6 @@
|
|||
|
||||
This directory contains the script and related resources to generate a PDF document with all the `tldr` pages.
|
||||
|
||||
## Preview
|
||||
|
||||

|
||||

|
||||

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

|
||||

|
||||

|
||||
|
|
|
@ -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
33
scripts/pdf/build-pdf.sh
Normal 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.
|
@ -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)
|
||||
|
|
Loading…
Add table
Reference in a new issue