From b844e4037238cf0062cc610cbfc164ec139839ab Mon Sep 17 00:00:00 2001 From: Jerome Petazzoni Date: Fri, 20 Mar 2020 13:56:50 -0500 Subject: [PATCH] Refactor card generation Many improvements. QR code, fixed page size, better use of page estate, etc. Also pdfkit should kind of work now (not quite using the full page size, but at least it's not utterly broken like before). --- prepare-vms/lib/ips-txt-to-html.py | 12 +-- prepare-vms/settings/admin-dmuc.yaml | 7 -- prepare-vms/settings/admin-kubenet.yaml | 7 -- prepare-vms/settings/admin-kuberouter.yaml | 7 -- prepare-vms/settings/admin-test.yaml | 7 -- prepare-vms/settings/example.yaml | 7 -- prepare-vms/settings/fundamentals.yaml | 7 -- prepare-vms/settings/jerome.yaml | 8 +- prepare-vms/settings/kube101.yaml | 7 -- prepare-vms/settings/swarm.yaml | 7 -- prepare-vms/templates/cards.html | 86 ++++++++++++++-------- 11 files changed, 65 insertions(+), 97 deletions(-) diff --git a/prepare-vms/lib/ips-txt-to-html.py b/prepare-vms/lib/ips-txt-to-html.py index 6f0891cc..19bd90ad 100755 --- a/prepare-vms/lib/ips-txt-to-html.py +++ b/prepare-vms/lib/ips-txt-to-html.py @@ -42,13 +42,15 @@ print("Generated ips.html") try: import pdfkit + paper_size = context["paper_size"] + margin = {"A4": "0.5cm", "Letter": "0.2in"}[paper_size] with open("ips.html") as f: pdfkit.from_file(f, "ips.pdf", options={ - "page-size": context["paper_size"], - "margin-top": context["paper_margin"], - "margin-bottom": context["paper_margin"], - "margin-left": context["paper_margin"], - "margin-right": context["paper_margin"], + "page-size": paper_size, + "margin-top": margin, + "margin-bottom": margin, + "margin-left": margin, + "margin-right": margin, }) print("Generated ips.pdf") except ImportError: diff --git a/prepare-vms/settings/admin-dmuc.yaml b/prepare-vms/settings/admin-dmuc.yaml index 6ac252c0..6eb9c9a4 100644 --- a/prepare-vms/settings/admin-dmuc.yaml +++ b/prepare-vms/settings/admin-dmuc.yaml @@ -10,13 +10,6 @@ cards_template: cards.html # Use "Letter" in the US, and "A4" everywhere else paper_size: A4 -# Feel free to reduce this if your printer can handle it -paper_margin: 0.2in - -# Note: paper_size and paper_margin only apply to PDF generated with pdfkit. -# If you print (or generate a PDF) using ips.html, they will be ignored. -# (The equivalent parameters must be set from the browser's print dialog.) - # This can be "test" or "stable" engine_version: stable diff --git a/prepare-vms/settings/admin-kubenet.yaml b/prepare-vms/settings/admin-kubenet.yaml index e283b10e..0ec45b77 100644 --- a/prepare-vms/settings/admin-kubenet.yaml +++ b/prepare-vms/settings/admin-kubenet.yaml @@ -10,13 +10,6 @@ cards_template: cards.html # Use "Letter" in the US, and "A4" everywhere else paper_size: A4 -# Feel free to reduce this if your printer can handle it -paper_margin: 0.2in - -# Note: paper_size and paper_margin only apply to PDF generated with pdfkit. -# If you print (or generate a PDF) using ips.html, they will be ignored. -# (The equivalent parameters must be set from the browser's print dialog.) - # This can be "test" or "stable" engine_version: stable diff --git a/prepare-vms/settings/admin-kuberouter.yaml b/prepare-vms/settings/admin-kuberouter.yaml index 9e6c4133..e2e19c96 100644 --- a/prepare-vms/settings/admin-kuberouter.yaml +++ b/prepare-vms/settings/admin-kuberouter.yaml @@ -10,13 +10,6 @@ cards_template: cards.html # Use "Letter" in the US, and "A4" everywhere else paper_size: A4 -# Feel free to reduce this if your printer can handle it -paper_margin: 0.2in - -# Note: paper_size and paper_margin only apply to PDF generated with pdfkit. -# If you print (or generate a PDF) using ips.html, they will be ignored. -# (The equivalent parameters must be set from the browser's print dialog.) - # This can be "test" or "stable" engine_version: stable diff --git a/prepare-vms/settings/admin-test.yaml b/prepare-vms/settings/admin-test.yaml index 691b60f8..8ee0463a 100644 --- a/prepare-vms/settings/admin-test.yaml +++ b/prepare-vms/settings/admin-test.yaml @@ -10,13 +10,6 @@ cards_template: cards.html # Use "Letter" in the US, and "A4" everywhere else paper_size: A4 -# Feel free to reduce this if your printer can handle it -paper_margin: 0.2in - -# Note: paper_size and paper_margin only apply to PDF generated with pdfkit. -# If you print (or generate a PDF) using ips.html, they will be ignored. -# (The equivalent parameters must be set from the browser's print dialog.) - # This can be "test" or "stable" engine_version: stable diff --git a/prepare-vms/settings/example.yaml b/prepare-vms/settings/example.yaml index 0275373f..b08725ce 100644 --- a/prepare-vms/settings/example.yaml +++ b/prepare-vms/settings/example.yaml @@ -12,13 +12,6 @@ cards_template: cards.html # Use "Letter" in the US, and "A4" everywhere else paper_size: Letter -# Feel free to reduce this if your printer can handle it -paper_margin: 0.2in - -# Note: paper_size and paper_margin only apply to PDF generated with pdfkit. -# If you print (or generate a PDF) using ips.html, they will be ignored. -# (The equivalent parameters must be set from the browser's print dialog.) - # This can be "test" or "stable" engine_version: test diff --git a/prepare-vms/settings/fundamentals.yaml b/prepare-vms/settings/fundamentals.yaml index 6c04c682..5d938bf2 100644 --- a/prepare-vms/settings/fundamentals.yaml +++ b/prepare-vms/settings/fundamentals.yaml @@ -12,13 +12,6 @@ cards_template: cards.html # Use "Letter" in the US, and "A4" everywhere else paper_size: Letter -# Feel free to reduce this if your printer can handle it -paper_margin: 0.2in - -# Note: paper_size and paper_margin only apply to PDF generated with pdfkit. -# If you print (or generate a PDF) using ips.html, they will be ignored. -# (The equivalent parameters must be set from the browser's print dialog.) - # This can be "test" or "stable" engine_version: stable diff --git a/prepare-vms/settings/jerome.yaml b/prepare-vms/settings/jerome.yaml index 4f68a3e4..ac7799cf 100644 --- a/prepare-vms/settings/jerome.yaml +++ b/prepare-vms/settings/jerome.yaml @@ -10,13 +10,6 @@ cards_template: cards.html # Use "Letter" in the US, and "A4" everywhere else paper_size: Letter -# Feel free to reduce this if your printer can handle it -paper_margin: 0.2in - -# Note: paper_size and paper_margin only apply to PDF generated with pdfkit. -# If you print (or generate a PDF) using ips.html, they will be ignored. -# (The equivalent parameters must be set from the browser's print dialog.) - # This can be "test" or "stable" engine_version: stable @@ -26,3 +19,4 @@ machine_version: 0.14.0 # Password used to connect with the "docker user" docker_user_password: training + diff --git a/prepare-vms/settings/kube101.yaml b/prepare-vms/settings/kube101.yaml index 4c79a254..606bf208 100644 --- a/prepare-vms/settings/kube101.yaml +++ b/prepare-vms/settings/kube101.yaml @@ -12,13 +12,6 @@ cards_template: cards.html # Use "Letter" in the US, and "A4" everywhere else paper_size: Letter -# Feel free to reduce this if your printer can handle it -paper_margin: 0.2in - -# Note: paper_size and paper_margin only apply to PDF generated with pdfkit. -# If you print (or generate a PDF) using ips.html, they will be ignored. -# (The equivalent parameters must be set from the browser's print dialog.) - # This can be "test" or "stable" engine_version: stable diff --git a/prepare-vms/settings/swarm.yaml b/prepare-vms/settings/swarm.yaml index cbc6a010..170aa8ec 100644 --- a/prepare-vms/settings/swarm.yaml +++ b/prepare-vms/settings/swarm.yaml @@ -12,13 +12,6 @@ cards_template: cards.html # Use "Letter" in the US, and "A4" everywhere else paper_size: Letter -# Feel free to reduce this if your printer can handle it -paper_margin: 0.2in - -# Note: paper_size and paper_margin only apply to PDF generated with pdfkit. -# If you print (or generate a PDF) using ips.html, they will be ignored. -# (The equivalent parameters must be set from the browser's print dialog.) - # This can be "test" or "stable" engine_version: stable diff --git a/prepare-vms/templates/cards.html b/prepare-vms/templates/cards.html index eb25965d..0c7b49c6 100644 --- a/prepare-vms/templates/cards.html +++ b/prepare-vms/templates/cards.html @@ -95,6 +95,29 @@ @@ -185,10 +201,22 @@ function qrcodes() { }); } ); -}; +} + +function scale() { + [].forEach.call( + document.getElementsByClassName("scale"), + (e, index) => { + var text_width = e.getBoundingClientRect().width; + var box_width = e.parentElement.getBoundingClientRect().width; + var percent = 100 * box_width / text_width + "%"; + e.style.fontSize = percent; + } + ); +} - + {% for cluster in clusters %}

{{ intro }}

@@ -223,7 +251,9 @@ function qrcodes() {

{% if url %} {{ slides_are_at }} -

{{ url }}
+

+ {{ url }} +

{% endif %} {% if img_bottom_src %} @@ -235,23 +265,21 @@ function qrcodes() { {% if backside %} {% for x in range(pagesize) %}
-
-

You got this at the workshop +

Thanks for attending "Getting Started With Kubernetes and Container Orchestration" - during QCON London (March 2019).

+ during CONFERENCE in Month YYYY!

If you liked that workshop, - I can train your team or organization - on Docker, containers, and Kubernetes, - with curriculums of 1 to 5 days. + I can train your team, in person or + online, with custom courses of + any length and any level.

{% if qrcode %} -

Interested? Scan that QR code to contact me!

+

If you're interested, please scan that QR code to contact me:

{% else %} -

Interested? Contact me at:

+

If you're interested, you can contact me at:

{% endif %}

jerome.petazzoni@gmail.com

-

Thank you!

{% endfor %}