Skip to content

Commit

Permalink
PDF generation fixes (quii#503)
Browse files Browse the repository at this point in the history
* Issue: Automate the gofmt in markdown files using gofmtmd during build
Issue Link: quii#353
Modifications:
* Modified the build script to download and run the gofmtmd tool on the markdown files
* Ran the script locally and fixed the issues reported by gofmtmd tool

Note: Intro to generics md file contains some syntax related to generics which is not recognised by the tool. So some valid
code fences are not marked as go

* Issue: Errors regarding epubcheck
Issue Link: quii#420
Solution:
* Corrected the SVG syntax by omitting the  version tag and dtd info
* Minorr markup corrections in md files

Test Case:
* Ran build books script locally and is able to view the generated epub file
* Added newly created epub file to Google Play books and is able to read the book

* Issue: PDF generation build fixes
Issue link: quii#205
Solution:
1. Created a custom docker image with fonts needed for CJK support and some fonts
2. Updated the build script to use the custom pandoc image
Test case:
1. Ran the build script locally and verified that the books generation is successful

* Update go.yml to add support to upload assets 

Made changes to GH actions to add generated epub and PDF to the release once published

* Corrected the yaml format

* Made changes to add cover page before the toc
  • Loading branch information
uppalabharath authored Nov 17, 2021
1 parent 5b32960 commit aad7a5b
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 50 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ on:
branches: [ main ]
pull_request:
branches: [ main ]
release:
types: [ published ]

jobs:

Expand All @@ -23,3 +25,33 @@ jobs:

- name: Build books
run: ./build.books.sh

- name: Get release
id: get_release
if: github.event_name == 'release' && github.event.action == 'published'
uses: bruceadams/get-release@v1.2.3
env:
GITHUB_TOKEN: ${{ github.token }}

- name: Attach generated epub upon release publish
if: github.event_name == 'release' && github.event.action == 'published'
with:
upload_url: ${{ steps.get_release.outputs.upload_url }}
asset_path: ./learn-go-with-tests.epub
asset_name: learn-go-with-tests.epub
asset_content_type: application/epub+zip
uses: actions/upload-release-asset@v1.0.2
env:
GITHUB_TOKEN: ${{ github.token }}

- name: Attach generated PDF upon release publish
if: github.event_name == 'release' && github.event.action == 'published'
with:
upload_url: ${{ steps.get_release.outputs.upload_url }}
asset_path: ./learn-go-with-tests.pdf
asset_name: learn-go-with-tests.pdf
asset_content_type: application/pdf
uses: actions/upload-release-asset@v1.0.2
env:
GITHUB_TOKEN: ${{ github.token }}

12 changes: 6 additions & 6 deletions anti-patterns.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,12 @@ At first pass it's reasonable to say the design isn't so bad. It only has 2 depe

Re-evaluate the design by considering the handler's responsibilities:

- Parse the request body into a `User`
- Use `UserStore` to check if the user exists
- Use `UserStore` to store the user
- Compose an email
- Use `Emailer` to send the email
- Return an appropriate http response, depending on success, errors, etc
- Parse the request body into a `User` :white_check_mark:
- Use `UserStore` to check if the user exists :question:
- Use `UserStore` to store the user :question:
- Compose an email :question:
- Use `Emailer` to send the email :question:
- Return an appropriate http response, depending on success, errors, etc :white_check_mark:

To exercise this code, you're going to have to write many tests with varying degrees of test double setups, spies, etc

Expand Down
64 changes: 36 additions & 28 deletions build.books.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,43 @@

set -e

#docker run -v `pwd`:/source jagregory/pandoc -o learn-go-with-tests.pdf -H meta.tex --latex-engine=xelatex --variable urlcolor=blue --toc --toc-depth=1 pdf-cover.md \
# gb-readme.md \
# why.md \
# hello-world.md \
# integers.md \
# arrays-and-slices.md \
# structs-methods-and-interfaces.md \
# pointers-and-errors.md \
# maps.md \
# dependency-injection.md \
# mocking.md \
# concurrency.md \
# select.md \
# reflection.md \
# sync.md \
# context.md \
# roman-numerals.md \
# math.md \
# app-intro.md \
# http-server.md \
# json.md \
# io.md \
# command-line.md \
# time.md \
# websockets.md \
# os-exec.md \
# error-types.md \
docker run --rm -v `pwd`:/data uppalabharath/pandoc-latex-cjk:latest --from=gfm+rebase_relative_paths -o learn-go-with-tests.pdf \
-H meta.tex --pdf-engine=xelatex --variable urlcolor=blue --toc --toc-depth=1 \
-B pdf-cover.tex \
gb-readme.md \
why.md \
hello-world.md \
integers.md \
iteration.md \
arrays-and-slices.md \
structs-methods-and-interfaces.md \
pointers-and-errors.md \
maps.md \
dependency-injection.md \
mocking.md \
concurrency.md \
select.md \
reflection.md \
sync.md \
context.md \
roman-numerals.md \
math.md \
reading-files.md \
intro-to-generics.md \
app-intro.md \
http-server.md \
json.md \
io.md \
command-line.md \
time.md \
websockets.md \
os-exec.md \
error-types.md \
context-aware-reader.md \
http-handlers-revisited.md \
anti-patterns.md

docker run --rm -v `pwd`:/data pandoc/latex --from=gfm --to=epub --file-scope title.txt -o learn-go-with-tests.epub --pdf-engine=xelatex --toc --toc-depth=1 \
docker run --rm -v `pwd`:/data uppalabharath/pandoc-latex-cjk:latest --from=gfm+rebase_relative_paths --to=epub --file-scope title.txt -o learn-go-with-tests.epub --pdf-engine=xelatex --toc --toc-depth=1 \
gb-readme.md \
why.md \
hello-world.md \
Expand Down
22 changes: 11 additions & 11 deletions command-line.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,17 @@ If you have `tree` installed you should run it and your structure should look li

```
.
├── file_system_store.go
├── file_system_store_test.go
├── cmd
└── webserver
└── main.go
├── league.go
├── server.go
├── server_integration_test.go
├── server_test.go
├── tape.go
└── tape_test.go
|-- file_system_store.go
|-- file_system_store_test.go
|-- cmd
| |-- webserver
| |-- main.go
|-- league.go
|-- server.go
|-- server_integration_test.go
|-- server_test.go
|-- tape.go
|-- tape_test.go
```

We now effectively have a separation between our application and the library code but we now need to change some package names. Remember when you build a Go application its package _must_ be `main`.
Expand Down
10 changes: 5 additions & 5 deletions math.md
Original file line number Diff line number Diff line change
Expand Up @@ -840,11 +840,11 @@ directory, called (confusingly), `clockface`. In there we'll put the `main`
package that will create the binary that will build an SVG:

```
├── clockface
│   └── main.go
├── clockface.go
├── clockface_acceptance_test.go
└── clockface_test.go
|-- clockface
| |-- main.go
|-- clockface.go
|-- clockface_acceptance_test.go
|-- clockface_test.go
```

Inside `main.go`, you'll start with this code but change the import for the
Expand Down
9 changes: 9 additions & 0 deletions meta.tex
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
\usepackage{fancyhdr}

\usepackage{xeCJK}
\usepackage{fontspec}% set Chinese fonts, as follows
\setmainfont{DejaVu Sans}
\setmonofont{DejaVu Sans}
\setsansfont{DejaVu Sans}
\setCJKmainfont[BoldFont=Noto Sans CJK TC,ItalicFont=Noto Sans CJK TC]{Noto Sans CJK TC}
\setCJKsansfont[BoldFont=Noto Sans CJK TC]{Noto Sans CJK TC}
\setCJKmonofont{Noto Sans Mono CJK TC}

\pagestyle{fancy}
\fancyhf{}
\cfoot{v 10.0.0}
2 changes: 2 additions & 0 deletions pdf-cover.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
\includegraphics{epub-cover.png}
\thispagestyle{empty}

0 comments on commit aad7a5b

Please sign in to comment.