Skip to content

Commit aad7a5b

Browse files
PDF generation fixes (#503)
* Issue: Automate the gofmt in markdown files using gofmtmd during build Issue Link: #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: #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: #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
1 parent 5b32960 commit aad7a5b

File tree

7 files changed

+101
-50
lines changed

7 files changed

+101
-50
lines changed

.github/workflows/go.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ on:
55
branches: [ main ]
66
pull_request:
77
branches: [ main ]
8+
release:
9+
types: [ published ]
810

911
jobs:
1012

@@ -23,3 +25,33 @@ jobs:
2325

2426
- name: Build books
2527
run: ./build.books.sh
28+
29+
- name: Get release
30+
id: get_release
31+
if: github.event_name == 'release' && github.event.action == 'published'
32+
uses: bruceadams/[email protected]
33+
env:
34+
GITHUB_TOKEN: ${{ github.token }}
35+
36+
- name: Attach generated epub upon release publish
37+
if: github.event_name == 'release' && github.event.action == 'published'
38+
with:
39+
upload_url: ${{ steps.get_release.outputs.upload_url }}
40+
asset_path: ./learn-go-with-tests.epub
41+
asset_name: learn-go-with-tests.epub
42+
asset_content_type: application/epub+zip
43+
uses: actions/[email protected]
44+
env:
45+
GITHUB_TOKEN: ${{ github.token }}
46+
47+
- name: Attach generated PDF upon release publish
48+
if: github.event_name == 'release' && github.event.action == 'published'
49+
with:
50+
upload_url: ${{ steps.get_release.outputs.upload_url }}
51+
asset_path: ./learn-go-with-tests.pdf
52+
asset_name: learn-go-with-tests.pdf
53+
asset_content_type: application/pdf
54+
uses: actions/[email protected]
55+
env:
56+
GITHUB_TOKEN: ${{ github.token }}
57+

anti-patterns.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,12 @@ At first pass it's reasonable to say the design isn't so bad. It only has 2 depe
144144

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

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

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

build.books.sh

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,43 @@
22

33
set -e
44

5-
#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 \
6-
# gb-readme.md \
7-
# why.md \
8-
# hello-world.md \
9-
# integers.md \
10-
# arrays-and-slices.md \
11-
# structs-methods-and-interfaces.md \
12-
# pointers-and-errors.md \
13-
# maps.md \
14-
# dependency-injection.md \
15-
# mocking.md \
16-
# concurrency.md \
17-
# select.md \
18-
# reflection.md \
19-
# sync.md \
20-
# context.md \
21-
# roman-numerals.md \
22-
# math.md \
23-
# app-intro.md \
24-
# http-server.md \
25-
# json.md \
26-
# io.md \
27-
# command-line.md \
28-
# time.md \
29-
# websockets.md \
30-
# os-exec.md \
31-
# error-types.md \
5+
docker run --rm -v `pwd`:/data uppalabharath/pandoc-latex-cjk:latest --from=gfm+rebase_relative_paths -o learn-go-with-tests.pdf \
6+
-H meta.tex --pdf-engine=xelatex --variable urlcolor=blue --toc --toc-depth=1 \
7+
-B pdf-cover.tex \
8+
gb-readme.md \
9+
why.md \
10+
hello-world.md \
11+
integers.md \
12+
iteration.md \
13+
arrays-and-slices.md \
14+
structs-methods-and-interfaces.md \
15+
pointers-and-errors.md \
16+
maps.md \
17+
dependency-injection.md \
18+
mocking.md \
19+
concurrency.md \
20+
select.md \
21+
reflection.md \
22+
sync.md \
23+
context.md \
24+
roman-numerals.md \
25+
math.md \
26+
reading-files.md \
27+
intro-to-generics.md \
28+
app-intro.md \
29+
http-server.md \
30+
json.md \
31+
io.md \
32+
command-line.md \
33+
time.md \
34+
websockets.md \
35+
os-exec.md \
36+
error-types.md \
37+
context-aware-reader.md \
38+
http-handlers-revisited.md \
39+
anti-patterns.md
3240

33-
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 \
41+
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 \
3442
gb-readme.md \
3543
why.md \
3644
hello-world.md \

command-line.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,17 @@ If you have `tree` installed you should run it and your structure should look li
4646

4747
```
4848
.
49-
├── file_system_store.go
50-
├── file_system_store_test.go
51-
├── cmd
52-
└── webserver
53-
└── main.go
54-
├── league.go
55-
├── server.go
56-
├── server_integration_test.go
57-
├── server_test.go
58-
├── tape.go
59-
└── tape_test.go
49+
|-- file_system_store.go
50+
|-- file_system_store_test.go
51+
|-- cmd
52+
| |-- webserver
53+
| |-- main.go
54+
|-- league.go
55+
|-- server.go
56+
|-- server_integration_test.go
57+
|-- server_test.go
58+
|-- tape.go
59+
|-- tape_test.go
6060
```
6161

6262
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`.

math.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -840,11 +840,11 @@ directory, called (confusingly), `clockface`. In there we'll put the `main`
840840
package that will create the binary that will build an SVG:
841841

842842
```
843-
├── clockface
844-
│   └── main.go
845-
├── clockface.go
846-
├── clockface_acceptance_test.go
847-
└── clockface_test.go
843+
|-- clockface
844+
| |-- main.go
845+
|-- clockface.go
846+
|-- clockface_acceptance_test.go
847+
|-- clockface_test.go
848848
```
849849

850850
Inside `main.go`, you'll start with this code but change the import for the

meta.tex

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
\usepackage{fancyhdr}
22

3+
\usepackage{xeCJK}
4+
\usepackage{fontspec}% set Chinese fonts, as follows
5+
\setmainfont{DejaVu Sans}
6+
\setmonofont{DejaVu Sans}
7+
\setsansfont{DejaVu Sans}
8+
\setCJKmainfont[BoldFont=Noto Sans CJK TC,ItalicFont=Noto Sans CJK TC]{Noto Sans CJK TC}
9+
\setCJKsansfont[BoldFont=Noto Sans CJK TC]{Noto Sans CJK TC}
10+
\setCJKmonofont{Noto Sans Mono CJK TC}
11+
312
\pagestyle{fancy}
413
\fancyhf{}
514
\cfoot{v 10.0.0}

pdf-cover.tex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
\includegraphics{epub-cover.png}
2+
\thispagestyle{empty}

0 commit comments

Comments
 (0)