diff --git a/_config.yml b/_config.yml index 3d1425f..c3ca0d8 100644 --- a/_config.yml +++ b/_config.yml @@ -2,6 +2,9 @@ title: InsightStack description: Tools, templates and thinking for knowledge work in development. url: https://varnasr.github.io baseurl: /InsightStack +# Default link-preview card, drawn by scripts/make_share_card.py. A page can set image and image_alt. +share_image: /assets/share-card.jpg +share_image_alt: "InsightStack. Calculators, econometrics, research documentation and loaders for real survey microdata. Part of the OpenStacks family." markdown: kramdown # GitHub Pages runs this plugin, which turns each folder's README.md into that diff --git a/_layouts/default.html b/_layouts/default.html index 2322320..b53f03e 100644 --- a/_layouts/default.html +++ b/_layouts/default.html @@ -11,7 +11,13 @@ - +{% assign share_image = page.image | default: site.share_image | absolute_url %} + + + + + + diff --git a/assets/share-card.jpg b/assets/share-card.jpg new file mode 100644 index 0000000..4c73dad Binary files /dev/null and b/assets/share-card.jpg differ diff --git a/calculators/block_level_development/block_level_development_calculator.html b/calculators/block_level_development/block_level_development_calculator.html index 2f5b4c2..c2d3e10 100644 --- a/calculators/block_level_development/block_level_development_calculator.html +++ b/calculators/block_level_development/block_level_development_calculator.html @@ -10,7 +10,12 @@ - + + + + + + diff --git a/calculators/district_health_indicators/health_indicators_calculator.html b/calculators/district_health_indicators/health_indicators_calculator.html index 4dbf59e..5b6397b 100644 --- a/calculators/district_health_indicators/health_indicators_calculator.html +++ b/calculators/district_health_indicators/health_indicators_calculator.html @@ -10,7 +10,12 @@ - + + + + + + diff --git a/calculators/education_needs/education_calculator.html b/calculators/education_needs/education_calculator.html index 99a8662..9c9b012 100644 --- a/calculators/education_needs/education_calculator.html +++ b/calculators/education_needs/education_calculator.html @@ -10,7 +10,12 @@ - + + + + + + diff --git a/calculators/environmental_change/environmental_change_calculator.html b/calculators/environmental_change/environmental_change_calculator.html index dda3d93..8226a6e 100644 --- a/calculators/environmental_change/environmental_change_calculator.html +++ b/calculators/environmental_change/environmental_change_calculator.html @@ -10,7 +10,12 @@ - + + + + + + diff --git a/calculators/financial_inclusion/financial_inclusion_calculator.html b/calculators/financial_inclusion/financial_inclusion_calculator.html index 3023307..7e9628a 100644 --- a/calculators/financial_inclusion/financial_inclusion_calculator.html +++ b/calculators/financial_inclusion/financial_inclusion_calculator.html @@ -10,7 +10,12 @@ - + + + + + + diff --git a/calculators/population_projection/population_projection_calculator.html b/calculators/population_projection/population_projection_calculator.html index e47701b..266724c 100644 --- a/calculators/population_projection/population_projection_calculator.html +++ b/calculators/population_projection/population_projection_calculator.html @@ -10,7 +10,12 @@ - + + + + + + diff --git a/index.html b/index.html index 712d10f..5961537 100644 --- a/index.html +++ b/index.html @@ -10,7 +10,12 @@ - + + + + + + diff --git a/scripts/fonts/Inter-Regular.otf b/scripts/fonts/Inter-Regular.otf new file mode 100644 index 0000000..2b93c4f Binary files /dev/null and b/scripts/fonts/Inter-Regular.otf differ diff --git a/scripts/fonts/Inter-SemiBold.otf b/scripts/fonts/Inter-SemiBold.otf new file mode 100644 index 0000000..7137d9b Binary files /dev/null and b/scripts/fonts/Inter-SemiBold.otf differ diff --git a/scripts/fonts/InterDisplay-ExtraBold.otf b/scripts/fonts/InterDisplay-ExtraBold.otf new file mode 100644 index 0000000..0f64ebc Binary files /dev/null and b/scripts/fonts/InterDisplay-ExtraBold.otf differ diff --git a/scripts/fonts/OFL-Inter.txt b/scripts/fonts/OFL-Inter.txt new file mode 100644 index 0000000..b32f86f --- /dev/null +++ b/scripts/fonts/OFL-Inter.txt @@ -0,0 +1,88 @@ +Copyright 2016-2023 The Inter Project Authors (https://github.com/rsms/inter) +Subset to Basic Latin and a few punctuation marks for the share card script. +Licensed under the SIL Open Font License, Version 1.1. + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font +creation efforts of academic and linguistic communities, and to +provide a free and open framework in which fonts may be shared and +improved in partnership with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any +reserved names are not used by derivative works. The fonts and +derivatives, however, cannot be released under any other type of +license. The requirement for fonts to remain under this license +does not apply to any document created using the fonts or their +derivatives. + +DEFINITIONS +Font Software refers to the set of files released by the +Copyright Holder(s) under this license and clearly marked as such. +This may include source files, build scripts and documentation. + +Reserved Font Name refers to any names specified as such after +the copyright statement(s). + +Original Version refers to the collection of Font Software +components as distributed by the Copyright Holder(s). + +Modified Version refers to any derivative made by adding to, +deleting, or substituting in part or in whole any of the components +of the Original Version, by changing formats or by porting the Font +Software to a new environment. + +Author refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person +obtaining a copy of the Font Software, to use, study, copy, merge, +embed, modify, redistribute, and sell modified and unmodified copies +of the Font Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, + in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, + redistributed and/or sold with any software, provided that each + copy contains the above copyright notice and this license. These + can be included either as stand-alone text files, human-readable + headers or in the appropriate machine-readable metadata fields + within text or binary files as long as those fields can be easily + viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font + Name(s) unless explicit written permission is granted by the + corresponding Copyright Holder. This restriction only applies to + the primary font name as presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the + Font Software shall not be used to promote, endorse or advertise + any Modified Version, except to acknowledge the contribution(s) + of the Copyright Holder(s) and the Author(s) or with their + explicit written permission. + +5) The Font Software, modified or unmodified, in part or in whole, + must be distributed entirely under this license, and must not be + distributed under any other license. The requirement for fonts to + remain under this license does not apply to any document created + using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions +are not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL +THE COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR +CONSEQUENTIAL DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR +OTHERWISE, ARISING FROM, OUT OF THE USE OR INABILITY TO USE THE FONT +SOFTWARE OR FROM OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/scripts/make_share_card.py b/scripts/make_share_card.py new file mode 100644 index 0000000..184fbf8 --- /dev/null +++ b/scripts/make_share_card.py @@ -0,0 +1,143 @@ +#!/usr/bin/env python3 +"""Draws the 1200x630 link-preview card, assets/share-card.jpg. + +Run it after changing the title, line or colours below: + + python3 scripts/make_share_card.py + +The words are copied from the page's own meta description, so change them there +first. Needs Pillow. Fonts are Inter (SIL Open Font License, see +fonts/OFL-Inter.txt), subset and kept beside this script. Style follows the +OpenStacks house style: 2px rules, no shadows, no rounded corners, saffron as +the single accent. Text colours are measured against what they sit on and the +script stops below 4.5:1. +""" +import io +from pathlib import Path +from PIL import Image, ImageDraw, ImageFont + +HERE = Path(__file__).resolve().parent +OUT = HERE.parent / "assets" / "share-card.jpg" + +TITLE = 'InsightStack' +SUBTITLE = None # optional second line under the title, or None +LINE = 'Calculators, econometrics, research documentation and loaders for real survey microdata.' +LABEL = 'Part of the OpenStacks family' # small label, top left +ADDRESS = 'varnasr.github.io/InsightStack/' +BAND = '#14305c' # colour of the bottom band + +BLACK, WHITE, SAFFRON, ASH = "#0d0d0f", "#f6f2ea", "#f2a541", "#d8d3c8" +S = 2 # draw at 2x, then reduce, for smooth edges +W, H = 1200, 630 + + +def lum(c): + c = c.lstrip("#") + ch = [int(c[i:i + 2], 16) / 255 for i in (0, 2, 4)] + ch = [x / 12.92 if x <= 0.03928 else ((x + 0.055) / 1.055) ** 2.4 for x in ch] + return 0.2126 * ch[0] + 0.7152 * ch[1] + 0.0722 * ch[2] + + +def ratio(a, b): + hi, lo = sorted((lum(a), lum(b)), reverse=True) + return (hi + 0.05) / (lo + 0.05) + + +for ink, ground, what in [(WHITE, BLACK, "title"), (SAFFRON, BLACK, "subtitle and label"), + (ASH, BLACK, "line"), (WHITE, BAND, "address")]: + assert ratio(ink, ground) >= 4.5, f"{what}: {ratio(ink, ground):.2f}:1 is below 4.5:1" + + +def font(name, px): + return ImageFont.truetype(str(HERE / "fonts" / name), px * S) + + +def width(d, text, f, track=0): + return d.textlength(text, font=f) + track * S * max(len(text) - 1, 0) + + +def spaced(d, xy, text, f, fill, track): + x, y = xy + for ch in text: + d.text((x, y), ch, font=f, fill=fill) + x += d.textlength(ch, font=f) + track * S + + +def wrap(d, text, f, maxw): + lines, cur = [], "" + for w in text.split(): + t = (cur + " " + w).strip() + if width(d, t, f) <= maxw or not cur: + cur = t + else: + lines.append(cur) + cur = w + lines.append(cur) + return lines + + +def render(): + im = Image.new("RGB", (W * S, H * S), BLACK) + d = ImageDraw.Draw(im) + pad, maxw = 72 * S, (W - 144) * S + + # top strip + d.rectangle([0, 0, W * S, 76 * S], fill=BLACK) + d.rectangle([0, 74 * S, W * S, 76 * S], fill=WHITE) + d.rectangle([pad, 30 * S, pad + 16 * S, 46 * S], fill=SAFFRON) + spaced(d, (pad + 32 * S, 26 * S), LABEL.upper(), font("Inter-SemiBold.otf", 22), SAFFRON, 3) + + # bottom band + d.rectangle([0, (H - 84) * S, W * S, H * S], fill=BAND) + d.rectangle([0, (H - 86) * S, W * S, (H - 84) * S], fill=WHITE) + f = font("Inter-SemiBold.otf", 26) + d.text((pad, (H - 84) * S + 26 * S), ADDRESS, font=f, fill=WHITE) + + # title: one line if it fits at 112px or more, otherwise two lines + title = TITLE.upper() + for px in range(150, 111, -2): + f = font("InterDisplay-ExtraBold.otf", px) + if width(d, title, f) <= maxw: + tl = [title] + break + else: + for px in range(120, 70, -2): + f = font("InterDisplay-ExtraBold.otf", px) + tl = wrap(d, title, f, maxw) + if len(tl) <= 2 and all(width(d, x, f) <= maxw for x in tl): + break + lh = int(px * 0.98) + y = 100 * S + for ln in tl: + d.text((pad, y), ln, font=f, fill=WHITE) + y += lh * S + y += 18 * S + if SUBTITLE: + fs = font("InterDisplay-ExtraBold.otf", 40) + d.text((pad, y), SUBTITLE, font=fs, fill=SAFFRON) + y += 68 * S + else: + d.rectangle([pad, y + 6 * S, pad + 120 * S, y + 14 * S], fill=SAFFRON) + y += 46 * S + + # one line from the page's own description + fl = font("Inter-Regular.otf", 38) + for ln in wrap(d, LINE, fl, maxw - 40 * S): + d.text((pad, y), ln, font=fl, fill=ASH) + y += 52 * S + assert y <= (H - 92) * S, f"text runs into the bottom band ({y // S}px)" + return im.resize((W, H), Image.LANCZOS) + + +def jpeg(): + b = io.BytesIO() + render().save(b, "JPEG", quality=90, optimize=True, subsampling=0) + return b.getvalue() + + +if __name__ == "__main__": + data = jpeg() + assert len(data) <= 250_000, f"{len(data)} bytes is over the 250 KB limit" + OUT.parent.mkdir(parents=True, exist_ok=True) + OUT.write_bytes(data) + print(f"wrote {OUT} ({len(data)} bytes, {W}x{H})") diff --git a/taguette_coding/tag_summary_export.html b/taguette_coding/tag_summary_export.html index 5942864..d610278 100644 --- a/taguette_coding/tag_summary_export.html +++ b/taguette_coding/tag_summary_export.html @@ -8,7 +8,12 @@ - + + + + + +