Fun Facts
Shows a new fun fact every day, laid out like the front page of a small newspaper. It builds on date in two ways: the facts live in a separate Jinja file that the screen template imports, and the screen uses custom fonts, rules and a box to make more of a designed page than a plain list of data.
Files
funfacts.yml— the config. Re-renders thefunfactsscreen every midnight.funfacts.xml.jinja— the screen template.facts.jinja— the facts, as one Jinja list. It draws nothing on its own.fonts/— DM Serif Display, regular and italic, under the SIL Open Font License (fonts/OFL.txt). Text without afontuses the bundled FiraSans.
Importing one Jinja file from another
facts.jinja only sets a variable:
{% set facts = [
{"content": "Snails take the longest naps! They can sleep for up to 3 years."},
...
] -%}
The screen template imports it, and every top-level variable becomes an attribute of the name given
after as:
{% import "facts.jinja" as DB -%}
{% set number = timestamp.toordinal() % (DB.facts | length) -%}
{% set fact = DB.facts[number].content -%}
The file name is resolved like any other file the config references, relative to CONFIG_DIR. Keeping
the data in its own file means you can add, remove or translate facts without touching the layout,
and several screens can import the same file. Macros defined in an imported file can be called the same
way, e.g. DB.someMacro().
An imported file doesn’t see the importing template’s variables, such as timestamp, unless you import
it with context. That’s why this example picks the fact in the screen template instead of in
facts.jinja.
Picking the fact
timestamp.toordinal() counts days, so it grows by one every midnight. Taking it modulo the number of
facts steps through the list one fact per day and starts over when all have been shown. Unlike
facts | random, this never repeats a fact two days in a row, and rendering twice on the same day
gives the same fact.
The design
Masthead. The title sits above a thick and a thin rule, with the date, a “Did you know?” kicker and the fact number between the rules. Each text is placed with
xandalign(left,center,right), so the three line up with the edges and the middle of the page.Quote mark. A 300 pt
“in light gray, drawn as text. It shares a<box>with the fact, so it stays next to the first line however many lines the fact wraps to. The box itself is positioned withvalign="middle", which centers the whole group between the header and the footer.Adaptive size. The template picks a font size from the length of the fact, so one-liners are big and the longest facts still fit.
Grays. The panel shows 16 levels of gray. The quote mark and the small print use gray to step back and leave the fact in full black.
Escaping. The fact is written as
{{ fact | e }}, so an&,<or>in a fact is escaped and doesn’t break the XML.
Try it
From the web/ directory:
CONFIG_DIR=examples/funfacts uv run todays_paper funfacts -o funfacts.png
Add -t 2027-02-22 to see how the longest fact in the list fits.
Source
facts.jinja
{% set facts = [
{"content": "Snails take the longest naps! They can sleep for up to 3 years."},
{"content": "Before there were trees on the earth, our planet was covered by giant mushrooms."},
{"content": "Elephants use the skin folds on their backs to crusch mosquitos."},
{"content": "The moon has moonquakes. They happen due to tidal stresses connected to the distance between the moon and the Earth."},
{"content": "You actually lose a large percentage of your taste buds while on an airplane. This might explain a lot about those less-than-stellar in-flight meals, or why you find yourself craving the saltiest foods while in the sky."},
{"content": "You may be jealous of a bird's ability to fly, but it may soothe your envy to learn they can't live in space because they need gravity to swallow."},
{"content": "Bees can sting other bees — usually if they feel threatened or are protecting their territory. In other words, you're not the only one who's scared of getting stung."},
...
]
-%}
249 lines left out. See the full file in the repository.
funfacts.xml.jinja
{# The facts live in their own file. Its top-level variables become attributes of DB. -#}
{% import "facts.jinja" as DB -%}
{# Step one fact forward every day, starting over when all have been shown. -#}
{% set number = timestamp.toordinal() % (DB.facts | length) -%}
{% set fact = DB.facts[number].content -%}
{# Longer facts get a smaller font so every fact fits the page. -#}
{% if fact | length < 90 -%}
{% set size = 66 -%}
{% elif fact | length < 170 -%}
{% set size = 54 -%}
{% else -%}
{% set size = 46 -%}
{% endif -%}
{% set margin = 56 -%}
{% set indent = 110 -%}
{% set serif = "fonts/DMSerifDisplay-Regular.ttf" -%}
{% set italic = "fonts/DMSerifDisplay-Italic.ttf" -%}
<screen>
{# Masthead: title between newspaper-style double rules. #}
<text align="center" x="{{ width // 2 }}" y="30" size="84" font="{{ serif }}">The Daily Fun Fact</text>
<rectangle x="{{ margin }}" y="136" width="{{ width - 2 * margin }}" height="5" fill="true" />
<line x="{{ margin }}" y="147" x2="{{ width - margin }}" y2="147" width="2" />
<text x="{{ margin }}" y="158" size="24">{{ timestamp.strftime('%A %-d %B') | upper }}</text>
<text align="center" x="{{ width // 2 }}" y="152" size="30" font="{{ italic }}" color="#555555">Did you know?</text>
<text align="right" x="{{ width - margin }}" y="158" size="24">FACT NO. {{ number + 1 }}</text>
<line x="{{ margin }}" y="198" x2="{{ width - margin }}" y2="198" width="2" />
{# A box keeps the quote mark next to the fact's first line, however many lines it has.
The box is centered between header and footer, nudged up since the glyph's empty top
margin makes the box taller than what's visible. #}
<box x="{{ margin - 8 }}" y="{{ (198 + height - 70) // 2 - 40 }}" valign="middle">
<text x="0" y="0" size="300" font="{{ serif }}" color="#cccccc">“</text>
<text
x="{{ indent + 8 }}"
y="80"
width="{{ width - 2 * margin - indent }}"
size="{{ size }}"
font="{{ serif }}"
>{{ fact | e }}</text>
</box>
{# Footer #}
<line x="{{ margin }}" y="{{ height - 70 }}" x2="{{ width - margin }}" y2="{{ height - 70 }}" width="2" />
<text align="center" x="{{ width // 2 }}" y="{{ height - 54 }}" size="22" color="#555555">A NEW FACT EVERY DAY · {{ DB.facts | length }} IN THE COLLECTION</text>
</screen>
funfacts.yml
# Shows a new fun fact every day. Builds on date by importing the facts from a second Jinja file.
settings:
# Decides when the day changes, and with it the fact.
timezone: Europe/Stockholm
screens:
# Panel resolution. Use 1024x758 for an ED060XC3 panel, 1448x1072 for an ED060KC1 panel.
width: 1024
height: 758
rotate: 0
funfacts:
template: funfacts.xml.jinja
scheduler:
# Re-render every midnight to show the next fact.
- days: [1, 2, 3, 4, 5, 6, 7]
hour: 0
screen: funfacts