Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create PDF books from Markdown files #113

Merged
merged 10 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified downloads/typescript-book-zh_CN.epub
Binary file not shown.
Binary file added downloads/typescript-book-zh_CN.pdf
Binary file not shown.
Binary file modified downloads/typescript-book.epub
Binary file not shown.
Binary file added downloads/typescript-book.pdf
Binary file not shown.
12 changes: 11 additions & 1 deletion tools/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Use `make` to run the main commands:
* `make format`: Format Markdown files for books.
* `make check`: Run several checks to ensure the Markdown files are valid.
* `make website`: Create different Markdown pages for the website.
* `make website-preview`: Build and preview website.
* `make website-preview`: Build and preview website locally.
* `make website-deploy`: Build and deploy website to GitHub Pages.
* `make books`: Create .epub books.

Expand Down Expand Up @@ -94,3 +94,13 @@ For instance, run the EPUB check using:
```shell
epubcheck ../downloads/typescript-book.epub
```

## How to Contribute to This E-Book

To contribute to this e-book, follow these steps:

* Update the main Markdown file with your changes.
* Run `make check` to ensure the linter and other checks pass.
* Preview the website locally with `make website-preview` to make sure it works as expected.
* Generate the e-books by running `make books`.
* Submit your PR and share your awesome contributions!
29 changes: 23 additions & 6 deletions tools/make-books.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
#!/bin/bash
echo "Making ebooks ..."
DIR_DOWNLOADS=downloads
DIR_DOWNLOADS="downloads"

INPUT_EN="README"
INPUT_CN="README-zh_CN"

OUTPUT_EN="typescript-book"
OUTPUT_CN="typescript-book-zh_CN"

AUTHOR="Simone Poggiali"
TITLE_EN="The Concise TypeScript Book"
TITLE_CN="# 简洁的TypeScript之书"

cd ../

echo "Making ebooks ..."

# Check dependencies
if command -v pandoc &>/dev/null; then
echo "pandoc is installed"
Expand All @@ -19,11 +30,17 @@ else
fi

# Generate eBooks
pandoc -o $DIR_DOWNLOADS/typescript-book.epub --metadata title="The Concise TypeScript Book" --metadata author="Simone Poggiali" -s README.md
pandoc -o $DIR_DOWNLOADS/typescript-book-zh_CN.epub --metadata title="# 简洁的TypeScript之书" --metadata author="Simone Poggiali" -s README-zh_CN.md
pandoc -o $DIR_DOWNLOADS/$OUTPUT_EN.epub --metadata title="$TITLE_EN" --metadata author="$AUTHOR" -s $INPUT_EN.md
pandoc -o $DIR_DOWNLOADS/$OUTPUT_CN.epub --metadata title="$TITLE_CN" --metadata author="$AUTHOR" -s $INPUT_CN.md

# Validate eBooks
epubcheck $DIR_DOWNLOADS/typescript-book.epub
epubcheck $DIR_DOWNLOADS/typescript-book-zh_CN.epub
epubcheck $DIR_DOWNLOADS/$OUTPUT_CN.epub
epubcheck $DIR_DOWNLOADS/$OUTPUT_CN.epub

cd ./tools || exit

# Generate PDFs
npm run make-pdf --source=$INPUT_EN --destination=$OUTPUT_EN
npm run make-pdf --source=$INPUT_CN --destination=$OUTPUT_CN

echo "Books were created. Please commit!"
Loading
Loading