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

Switch eBook PDF generation from WeasyPrint to Prince #833

Merged
merged 29 commits into from
May 20, 2020
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
2a84d8e
Move to EJS templates for consistency and to fix missing author pictures
tunetheweb May 16, 2020
89814de
Add Prince Support (inc fixing figure aria labels)
tunetheweb May 16, 2020
351b8cc
Merge branch 'master' into ebook_fixes
tunetheweb May 16, 2020
0b40c94
Add YouTube fallback
tunetheweb May 16, 2020
c0feed7
Fix table in Japanese chapter
tunetheweb May 16, 2020
73ff7bc
move from WeasyPrint to Prince
tunetheweb May 16, 2020
f32d99d
Update README.md
tunetheweb May 16, 2020
7d6bafb
Remove unnecessary change
tunetheweb May 16, 2020
4a02e9c
Update statement for PDF accessibility
tunetheweb May 16, 2020
c262297
Regen PDFs
tunetheweb May 16, 2020
d1b0dcd
Fix typos
tunetheweb May 16, 2020
2094c78
Fix spacing
tunetheweb May 16, 2020
9a20b99
Review feedback
tunetheweb May 16, 2020
fd8494d
Review feedback
tunetheweb May 16, 2020
f1ecaf9
Review feedback
tunetheweb May 16, 2020
9afd4f6
Misc fixes
tunetheweb May 16, 2020
70db42f
Make contributors line up
tunetheweb May 16, 2020
3b7ceb3
Fix text wrapping issue in Methodology section
tunetheweb May 17, 2020
94310b7
Prince supports SVG social media icons
tunetheweb May 17, 2020
608da1a
Add print support in case we ever want to print a physical copy
tunetheweb May 18, 2020
35aab23
Remove link underlines in print mode
tunetheweb May 18, 2020
66519e8
Add footnotes and left/right pages
tunetheweb May 18, 2020
ee28b22
Fix typos
tunetheweb May 18, 2020
19889a3
templates/base/2019/base_ebook.html
tunetheweb May 19, 2020
59abf31
Merge branch 'master' into ebook_fixes
tunetheweb May 19, 2020
1fd7711
Avoid hanging headers
tunetheweb May 19, 2020
63f16ff
Merge branch 'master' into ebook_fixes
tunetheweb May 19, 2020
5c5c75f
Review feedback
tunetheweb May 20, 2020
ef9018f
Merge branch 'master' into ebook_fixes
tunetheweb May 20, 2020
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
8 changes: 1 addition & 7 deletions src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,7 @@ npm install
npm run generate
```

3. For generating PDFs of the ebook, WeasyPrint will need some additional libraries:

```
brew install cairo
brew install pango
brew install gdk-pixbuf
```
3. For generating PDFs of the ebook, you need to install Prince. Follow the instructions on [the Prince Website](https://www.princexml.com/).

4. To actually generate the ebooks, start your local server, then run the following:

Expand Down
8 changes: 6 additions & 2 deletions src/content/en/2019/mobile-web.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,12 @@ The state of JavaScript on the mobile web is terrifying. According to HTTP Archi
Why is this a problem? Because sites loading this much JS take upwards of [10 seconds](https://httparchive.org/reports/loading-speed?start=earliest&end=2019_07_01&view=list#ttci) to become consistently interactive. Or in other words, your page may appear fully loaded, but when a user clicks any of your buttons or menus, the user may experience some slowdown because the JavaScript hasn't finished executing. In the worst case scenario, users may be forced to keep clicking the button for upwards of 10 seconds, just waiting for that magical moment where something actually happens. Think about how confusing and frustrating that can be.

<figure>
<iframe class="fig-mobile fig-desktop" width="560" height="315" src="https://www.youtube.com/embed/Lx1cYJAVnzA" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
<figcaption>Figure 2. Example of how painful of an experience waiting for JS to load can be.</figcaption>
<iframe class="fig-mobile fig-desktop video-embed" width="560" height="315" src="https://www.youtube.com/embed/Lx1cYJAVnzA" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
<a class="video-fallback-image" href="/static/images/2019/mobile-web/fig2.png">
<img src="/static/images/2019/mobile-web/fig2.png" alt="Figure 2. Example of how painful of an experience waiting for JS to load can be." aria-labelledby="fig2-caption" aria-described="fig2-description" width="600" height="343">
</a>
<div id="fig2-description" class="visually-hidden">Video showing two web pages loading and each page has a figure tapping repeatedly on a button throughout the video, to no effect. There is a clock ticking up from 0 seconds at the top, and an initial happy emoji face for each website, that starts to turn less happy as clock passes 6 seconds, wide-eyed at 8 seconds, angry at 10 seconds, really angry at 13 seconds and crying at 19 seconds shortly after which the video ends.</div>
<figcaption id="fig2-caption">Figure 2. Example of how painful of an experience waiting for JS to load can be.</figcaption>
</figure>

Let's delve deeper and look at another metric that focuses more on *how well* each page utilizes JavaScript. For example, does it really need as much JavaScript as it's loading? We call this metric the *JavaScript Bloat Score*, based on the [web bloat score](https://www.webbloatscore.com/). The idea behind it is this:
Expand Down
6 changes: 3 additions & 3 deletions src/content/ja/2019/caching.md
Original file line number Diff line number Diff line change
Expand Up @@ -595,9 +595,9 @@ Varyヘッダーは、1つ以上の要求ヘッダー値の値をキャッシュ
<thead>
<tr>
<td scope="col"></td>
<th>Service Workerを使用しない</th>
<th>Service Workerを使用する</th>
<th>合計</th>
<th scope="col">Service Workerを使用しない</th>
<th scope="col">Service Workerを使用する</th>
<th scope="col">合計</th>
</tr>
</thead>
<tbody>
Expand Down
6 changes: 5 additions & 1 deletion src/content/ja/2019/mobile-web.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ last_updated: 2020-05-14T00:00:00.000Z

<figure>
<iframe class="fig-mobile fig-desktop" width="560" height="315" src="https://www.youtube.com/embed/Lx1cYJAVnzA" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
<figcaption>図2. JS がロードされるのを待つのがいかに苦痛であるかの例。</figcaption>
<a class="video-fallback-image" href="/static/images/2019/mobile-web/fig2.png">
<img src="/static/images/2019/mobile-web/fig2.png" alt="図2. JS がロードされるのを待つのがいかに苦痛であるかの例。" aria-labelledby="fig2-caption" aria-described="fig2-description" width="600" height="343">
</a>
<div id="fig2-description" class="visually-hidden">Video showing two web pages loading and each page has a figure tapping repeatedly on a button throughout the video, to no effect. There is a clock ticking up from 0 seconds at the top, and an initial happy emoji face for each website, that starts to turn less happy as clock passes 6 seconds, wide-eyed at 8 seconds, angry at 10 seconds, really angry at 13 seconds and crying at 19 seconds shortly after which the video ends.</div>
<figcaption fig2-caption>図2. JS がロードされるのを待つのがいかに苦痛であるかの例。</figcaption>
</figure>

さらに深く掘り下げて、各ページがJavaScriptをどの程度利用しているかに焦点を当てた別の指標を見てみましょう。例えば、読み込み中のページは本当に多くのJavaScriptを必要としているのでしょうか? 私たちはこの指標を[Web bloat score](https://www.webbloatscore.com/)に基づいた*JavaScript Bloat Score*と呼んでいます。その背後にある考え方は次のようなものです。
Expand Down
4 changes: 2 additions & 2 deletions src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"homepage": "https://github.com/HTTPArchive/almanac.httparchive.org#readme",
"scripts": {
"generate": "node ./tools/generate",
"ebook_2019_en": "weasyprint http://127.0.0.1:8080/en/2019/ebook static/pdfs/web_almanac_2019_en.pdf",
"ebook_2019_ja": "weasyprint http://127.0.0.1:8080/ja/2019/ebook static/pdfs/web_almanac_2019_ja.pdf",
"ebook_2019_en": "prince http://127.0.0.1:8080/en/2019/ebook -o static/pdfs/web_almanac_2019_en.pdf --pdf-profile='PDF/UA-1'",
"ebook_2019_ja": "prince http://127.0.0.1:8080/ja/2019/ebook -o static/pdfs/web_almanac_2019_ja.pdf --pdf-profile='PDF/UA-1'",
"deploy": "echo \"Y\" | gcloud app deploy --project webalmanac --stop-previous-version"
},
"devDependencies": {
Expand Down
85 changes: 71 additions & 14 deletions src/static/css/ebook.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,31 @@
#title .title {
color: white;
background-color: #5C687D;
}

.intro-year {
margin: 0;
width: auto;
color: #F7F779;
font-size: 10rem;
line-height: 100%;
font-weight: bold;
}

#title h1.title::before {
border-bottom: none;
}

#title h1.title {
font-size: 5rem;
font-weight: 700;
}

#title h2.title {
font-size: 2rem;
font-weight: 300;
}

#title img {
margin: 0 auto;
}
Expand All @@ -15,12 +43,6 @@
margin: 0;
}

.table-wrap {
display: block;
max-width: 100%;
text-align: center;
}

th, td {
padding: 5px;
}
Expand All @@ -43,10 +65,10 @@ tbody tr:nth-child(even) {
}

.intro-image {
background-color: grey;
border-radius: 10px;
display: block;
margin: 20px 0;
background-color: #5C687D;
}

.team {
Expand Down Expand Up @@ -121,37 +143,45 @@ ul li.contributor::before {
color: #333;
}

/* Join the team card */
.contributor-join {
display: none;
}

.social-icon {
height: 20px;
width: 20px;
}

@prince-pdf {
prince-pdf-display-doc-title: true;
}


@page:first {
background-color: #5C687D;
}

@page {
tunetheweb marked this conversation as resolved.
Show resolved Hide resolved
margin: 2.5cm;
padding: 0;
font-family: 'Lato', sans-serif;
font-size: 10pt;
size: A4;

@bottom-left {
width: 100%;
margin: 10pt 0 30pt 0;
border-top: .25pt solid #666;
color: #333;
font-family: 'Poppins', sans-serif;
}

@bottom-right {
width: 100px;
margin: 10pt 0 30pt 0;
border-top: .25pt solid #666;
font-family: 'Poppins', sans-serif;
content: counter(page);
}

@top-right {
font-family: 'Poppins', sans-serif;
content: string(chapter_subtitle) string(chapter_title);
margin: 30pt 0 10pt 0;
color: #333;
Expand Down Expand Up @@ -196,30 +226,44 @@ ul li.contributor::before {
}

#toc a {
display: table;
display: inline-block;
min-width: 500px;
}

#toc a::after {
display: inline-block;
float: right;
content: target-counter(attr(href), page);
}

section.chapter h1.title {
section h1 {
string-set: chapter_title content();
}

section div.subtitle {
string-set: chapter_subtitle "";
}

section.chapter div.subtitle {
string-set: chapter_subtitle content() " - ";
}

.content ul li::before {
content: none;
}

.content ul li {
list-style: disc;
}

figure,
figure a,
figure div,
figure img,
figcaption {
max-width: 100%;
text-align: center;
page-break-inside: avoid;
}

figure .anchor-link {
Expand All @@ -234,11 +278,24 @@ ul li.contributor::before {
width: 1000px;
}

figure iframe.video-embed {
display: none;
}

figure .video-fallback-image {
display: block;
}

table {
display: table;
border-spacing: 2px;
border-color: grey;
}

.authors li {
page-break-inside: avoid;
}

}
tunetheweb marked this conversation as resolved.
Show resolved Hide resolved


Expand Down
8 changes: 8 additions & 0 deletions src/static/css/page.css
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,14 @@ figure .fig-desktop {
display: block;
}

.video-embed {
display: block;
}

.video-fallback-image {
display: none;
}

.bio {
margin-top: 10px;
}
Expand Down
Binary file added src/static/images/2019/mobile-web/fig2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/static/pdfs/web_almanac_2019_en.pdf
Binary file not shown.
Binary file modified src/static/pdfs/web_almanac_2019_ja.pdf
Binary file not shown.
3 changes: 2 additions & 1 deletion src/templates/ar/2019/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ <h1>{{ self.foreword_title() }}</h1>

{% block appendix %}Appendices{% endblock %}

{% block ebook_download %}Download the entire {{ year }} Web Almanac in PDF format{% endblock %}
{% block ebook_download %}Download the entire {{ year }} Web Almanac in PDF format (generated with <a href="https://www.princexml.com/">www.princexml.com</a>){% endblock %}
{% block ebook_download_note %}(generated with <a href="https://www.princexml.com/">www.princexml.com</a>){% endblock %}

{%
set localizedPartTitles = {
Expand Down
16 changes: 8 additions & 8 deletions src/templates/base/2019/base_chapter.html
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@

{% macro render_authors() %}
{% for author in metadata.get('authors') %}
{% if loop.index == 1 %}
{% if loop.index == 1 %}
<h2 id="authors">
<a href="#authors" class="anchor-link">
{% if loop.length == 1 %}{{ self.author() }}{% endif -%}
Expand All @@ -120,7 +120,7 @@ <h2 id="authors">
<ul>
{% endif %}
{% set authordata = config.contributors[author] if author in config.contributors else None %}
{% if authordata %}
{% if authordata %}
<li>
<div aria-hidden="true">
<a href="{{ url_for('contributors', year=year, lang=lang, _anchor=author) }}" tabindex="-1">
Expand All @@ -132,25 +132,25 @@ <h2 id="authors">
{% if authordata.twitter or authordata.github %}
<span class="social">
{% if authordata.twitter %}
<a class="twitter" href="https://twitter.com/{{ authordata.twitter }}" aria-labelledby="author_{{ author }}_twitter">
<a class="twitter" href="https://twitter.com/{{ authordata.twitter }}" aria-labelledby="author-{{ author }}-twitter">
<svg width="18" height="18" role="img">
<title id="author_{{ author }}_twitter">{{ onTwitter(authordata.twitter) }}</title>
<title id="author-{{ author }}-twitter">{{ onTwitter(authordata.twitter) }}</title>
<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#twitter"></use>
</svg>
</a>
{% endif %}
{% if authordata.github %}
<a class="github" href="https://github.com/{{ authordata.github }}" aria-labelledby="author_{{ author }}_github">
<a class="github" href="https://github.com/{{ authordata.github }}" aria-labelledby="author-{{ author }}-github">
<svg width="18" height="18" role="img">
<title id="author_{{ author }}_github">{{ onGitHub(authordata.github) }}</title>
<title id="author-{{ author }}-github">{{ onGitHub(authordata.github) }}</title>
<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#github"></use>
</svg>
</a>
{% endif %}
{% if authordata.website %}
<a class="website" href="{{ authordata.website }}" aria-labelledby="author_{{ author }}_website">
<a class="website" href="{{ authordata.website }}" aria-labelledby="author-{{ author }}-website">
<svg width="18" height="18" role="img">
<title id="author_{{ author }}_website">{{ website(authordata.name) }}</title>
<title id="author-{{ author }}-website">{{ website(authordata.name) }}</title>
<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#globe"></use>
</svg>
</a>
Expand Down
Loading