fix: bundle consistent fonts for share card rendering
This commit is contained in:
4
build.ts
4
build.ts
@@ -27,4 +27,6 @@ for (const output of result.outputs) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
await mkdir(path.join(outdir, "fonts"), { recursive: true });
|
await mkdir(path.join(outdir, "fonts"), { recursive: true });
|
||||||
await copyFile("src/assets/fonts/InstrumentSerif-Regular.ttf", path.join(outdir, "fonts/InstrumentSerif-Regular.ttf"));
|
for (const file of ["InstrumentSerif-Regular.ttf", "NotoSans-Regular.ttf", "NotoSans-Medium.ttf", "NotoSans-SemiBold.ttf"]) {
|
||||||
|
await copyFile(`src/assets/fonts/${file}`, path.join(outdir, "fonts", file));
|
||||||
|
}
|
||||||
|
|||||||
@@ -36,8 +36,10 @@ The registered Discord callback is
|
|||||||
four habits, history, reminders, and live Discord state. The transfer hash and
|
four habits, history, reminders, and live Discord state. The transfer hash and
|
||||||
counts are recorded in `/opt/minabot/migration-manifest.json`. Local development
|
counts are recorded in `/opt/minabot/migration-manifest.json`. Local development
|
||||||
was stopped before the snapshot so only production manages the existing live cards.
|
was stopped before the snapshot so only production manages the existing live cards.
|
||||||
Do not restart development with the same bot/message state; use stubbed previews
|
Development now blocks channel writes at both snapshot-send and live-card entry
|
||||||
or an isolated database and bot configuration.
|
points. It also skips copied live-card recovery and change scheduling. Preview and
|
||||||
|
download remain available. Stubbed tests inject their own transport/configuration;
|
||||||
|
real writes through the environment loader are enabled only in production.
|
||||||
|
|
||||||
Daily verified snapshots and pre-migration snapshots are stored under
|
Daily verified snapshots and pre-migration snapshots are stored under
|
||||||
`/srv/minabot/data/backups`, retaining seven snapshots. The restore rehearsal
|
`/srv/minabot/data/backups`, retaining seven snapshots. The restore rehearsal
|
||||||
|
|||||||
93
src/assets/fonts/InstrumentSerif-OFL.txt
Normal file
93
src/assets/fonts/InstrumentSerif-OFL.txt
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
Copyright 2022 The Instrument Serif Project Authors (https://github.com/Instrument/instrument-serif)
|
||||||
|
|
||||||
|
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
||||||
|
This license is copied below, and is also available with a FAQ at:
|
||||||
|
https://scripts.sil.org/OFL
|
||||||
|
|
||||||
|
|
||||||
|
-----------------------------------------------------------
|
||||||
|
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
||||||
|
-----------------------------------------------------------
|
||||||
|
|
||||||
|
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.
|
||||||
94
src/assets/fonts/NotoSans-LICENSE.txt
Normal file
94
src/assets/fonts/NotoSans-LICENSE.txt
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
Copyright 2018 The Noto Project Authors (github.com/googlei18n/noto-fonts)
|
||||||
|
|
||||||
|
This Font Software is licensed under the SIL Open Font License,
|
||||||
|
Version 1.1.
|
||||||
|
|
||||||
|
This license is copied below, and is also available with a FAQ at:
|
||||||
|
http://scripts.sil.org/OFL
|
||||||
|
|
||||||
|
-----------------------------------------------------------
|
||||||
|
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
||||||
|
-----------------------------------------------------------
|
||||||
|
|
||||||
|
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.
|
||||||
BIN
src/assets/fonts/NotoSans-Medium.ttf
Normal file
BIN
src/assets/fonts/NotoSans-Medium.ttf
Normal file
Binary file not shown.
BIN
src/assets/fonts/NotoSans-Regular.ttf
Normal file
BIN
src/assets/fonts/NotoSans-Regular.ttf
Normal file
Binary file not shown.
BIN
src/assets/fonts/NotoSans-SemiBold.ttf
Normal file
BIN
src/assets/fonts/NotoSans-SemiBold.ttf
Normal file
Binary file not shown.
14
src/assets/fonts/README.md
Normal file
14
src/assets/fonts/README.md
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
# Bundled share-card fonts
|
||||||
|
|
||||||
|
Instrument Serif Regular/Italic: downloaded from the
|
||||||
|
[Google Fonts source](https://github.com/google/fonts/tree/main/ofl/instrumentserif).
|
||||||
|
License: `InstrumentSerif-OFL.txt` (also retained in the original `OFL.txt`).
|
||||||
|
|
||||||
|
Noto Sans Regular (400), Medium (500), and SemiBold (600): downloaded from the
|
||||||
|
[Noto source](https://github.com/notofonts/noto-fonts/tree/main/hinted/ttf/NotoSans).
|
||||||
|
License: `NotoSans-LICENSE.txt`.
|
||||||
|
|
||||||
|
Downloaded September 7, 2026. The files are versioned in this repository and copied
|
||||||
|
into the production image. Browser and native canvas renderers use the alias
|
||||||
|
`Mina Sans`; no system sans-serif font is selected for card text. The native font
|
||||||
|
loader fails startup if a required font cannot be registered.
|
||||||
@@ -35,7 +35,7 @@ async function loadAvatar(url: string): Promise<HTMLImageElement | null> {
|
|||||||
|
|
||||||
/** Compact summary: fixed typography stays readable when Discord scales the attachment. */
|
/** Compact summary: fixed typography stays readable when Discord scales the attachment. */
|
||||||
export async function renderProgressCard(data: ShareData, user: PublicUser, privacy: CardPrivacy, theme: Theme = "light"): Promise<{ blob: Blob; alt: string; avatarMissing: boolean }> {
|
export async function renderProgressCard(data: ShareData, user: PublicUser, privacy: CardPrivacy, theme: Theme = "light"): Promise<{ blob: Blob; alt: string; avatarMissing: boolean }> {
|
||||||
await document.fonts.load('64px "Instrument Serif"');
|
await Promise.all(['400 64px "Instrument Serif"', '400 32px "Mina Sans"', '500 32px "Mina Sans"', '600 32px "Mina Sans"'].map(font => document.fonts.load(font)));
|
||||||
const avatar = privacy.avatar && user.avatarUrl ? await loadAvatar(user.avatarUrl) : null;
|
const avatar = privacy.avatar && user.avatarUrl ? await loadAvatar(user.avatarUrl) : null;
|
||||||
const canvas = document.createElement("canvas");
|
const canvas = document.createElement("canvas");
|
||||||
const shortRange = dayNumber(data.to) - dayNumber(data.from) < 84;
|
const shortRange = dayNumber(data.to) - dayNumber(data.from) < 84;
|
||||||
@@ -52,7 +52,7 @@ export async function renderProgressCard(data: ShareData, user: PublicUser, priv
|
|||||||
ctx.scale(1.25, 1.25);
|
ctx.scale(1.25, 1.25);
|
||||||
const { ink, muted, paper, empty, rule, avatar: avatarBackground, dot } = themePalette[theme];
|
const { ink, muted, paper, empty, rule, avatar: avatarBackground, dot } = themePalette[theme];
|
||||||
const green = "#285d49";
|
const green = "#285d49";
|
||||||
const sans = '-apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif';
|
const sans = '"Mina Sans"';
|
||||||
const text = (value: string, x: number, y: number, size = 32, color: string = ink, weight = "400", maxWidth = 864, align: CanvasTextAlign = "left", serif = false) => {
|
const text = (value: string, x: number, y: number, size = 32, color: string = ink, weight = "400", maxWidth = 864, align: CanvasTextAlign = "left", serif = false) => {
|
||||||
ctx.font = `${weight} ${size}px ${serif ? '"Instrument Serif", Georgia, serif' : sans}`;
|
ctx.font = `${weight} ${size}px ${serif ? '"Instrument Serif", Georgia, serif' : sans}`;
|
||||||
ctx.fillStyle = color; ctx.textAlign = align;
|
ctx.fillStyle = color; ctx.textAlign = align;
|
||||||
|
|||||||
@@ -10,9 +10,18 @@ import { cardDate } from "../lib/progress-card";
|
|||||||
import { calendarTimeline } from "../components/design-system/calendar-model";
|
import { calendarTimeline } from "../components/design-system/calendar-model";
|
||||||
import { themedHabitShade } from "../lib/habit-palette";
|
import { themedHabitShade } from "../lib/habit-palette";
|
||||||
|
|
||||||
const sourceFont = new URL('../assets/fonts/InstrumentSerif-Regular.ttf', import.meta.url);
|
for (const [file, family] of [
|
||||||
const builtFont = new URL('./fonts/InstrumentSerif-Regular.ttf', import.meta.url);
|
['InstrumentSerif-Regular.ttf', 'Instrument Serif'],
|
||||||
GlobalFonts.registerFromPath((existsSync(sourceFont) ? sourceFont : builtFont).pathname, 'Instrument Serif');
|
['NotoSans-Regular.ttf', 'Mina Sans'],
|
||||||
|
['NotoSans-Medium.ttf', 'Mina Sans'],
|
||||||
|
['NotoSans-SemiBold.ttf', 'Mina Sans'],
|
||||||
|
]) {
|
||||||
|
const sourceFont = new URL(`../assets/fonts/${file}`, import.meta.url);
|
||||||
|
const builtFont = new URL(`./fonts/${file}`, import.meta.url);
|
||||||
|
if (!GlobalFonts.registerFromPath((existsSync(sourceFont) ? sourceFont : builtFont).pathname, family)) {
|
||||||
|
throw new Error(`Could not load bundled font: ${file}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function liveCardData(db: AppDatabase, userId: string, now: number) {
|
export function liveCardData(db: AppDatabase, userId: string, now: number) {
|
||||||
const user = db.select().from(users).where(eq(users.id, userId)).get();
|
const user = db.select().from(users).where(eq(users.id, userId)).get();
|
||||||
@@ -54,7 +63,7 @@ export async function renderLiveCard(data: LiveImageData, theme: Theme) {
|
|||||||
ctx.fillStyle = color; ctx.beginPath(); ctx.roundRect(x, y, Math.max(0, w), Math.max(0, h), radius); ctx.fill();
|
ctx.fillStyle = color; ctx.beginPath(); ctx.roundRect(x, y, Math.max(0, w), Math.max(0, h), radius); ctx.fill();
|
||||||
};
|
};
|
||||||
const text = (value: string, x: number, y: number, size: number, width: number, color: string = colors.ink, serif = false, weight = '400') => {
|
const text = (value: string, x: number, y: number, size: number, width: number, color: string = colors.ink, serif = false, weight = '400') => {
|
||||||
ctx.font = `${weight} ${size}px ${serif ? '"Instrument Serif"' : 'sans-serif'}`; ctx.fillStyle = color;
|
ctx.font = `${weight} ${size}px ${serif ? '"Instrument Serif"' : '"Mina Sans"'}`; ctx.fillStyle = color;
|
||||||
const chars = Array.from(value); let fitted = value;
|
const chars = Array.from(value); let fitted = value;
|
||||||
while (chars.length && ctx.measureText(fitted).width > width) { chars.pop(); fitted = chars.join('') + '…'; }
|
while (chars.length && ctx.measureText(fitted).width > width) { chars.pop(); fitted = chars.join('') + '…'; }
|
||||||
ctx.fillText(fitted, x, y);
|
ctx.fillText(fitted, x, y);
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ export function createLiveDiscord(db: AppDatabase, auth: ReturnType<typeof creat
|
|||||||
update(id, { dirty: false, retryAt: null });
|
update(id, { dirty: false, retryAt: null });
|
||||||
const data = liveCardData(db, id, now());
|
const data = liveCardData(db, id, now());
|
||||||
// Hash the rendered content, excluding timestamps and private task details.
|
// Hash the rendered content, excluding timestamps and private task details.
|
||||||
const hash = createHash('sha256').update(JSON.stringify({ data, theme: current.theme, renderer: 2, content: liveMessageText })).digest('hex');
|
const hash = createHash('sha256').update(JSON.stringify({ data, theme: current.theme, renderer: 3, content: liveMessageText })).digest('hex');
|
||||||
if (current.messageId && current.imageHash === hash) {
|
if (current.messageId && current.imageHash === hash) {
|
||||||
update(id, { error: null }); rollover(id); return;
|
update(id, { error: null }); rollover(id); return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,24 @@
|
|||||||
|
@font-face {
|
||||||
|
font-family: "Mina Sans";
|
||||||
|
src: url("../src/assets/fonts/NotoSans-Regular.ttf") format("truetype");
|
||||||
|
font-style: normal;
|
||||||
|
font-weight: 400;
|
||||||
|
font-display: swap;
|
||||||
|
}
|
||||||
|
@font-face {
|
||||||
|
font-family: "Mina Sans";
|
||||||
|
src: url("../src/assets/fonts/NotoSans-Medium.ttf") format("truetype");
|
||||||
|
font-style: normal;
|
||||||
|
font-weight: 500;
|
||||||
|
font-display: swap;
|
||||||
|
}
|
||||||
|
@font-face {
|
||||||
|
font-family: "Mina Sans";
|
||||||
|
src: url("../src/assets/fonts/NotoSans-SemiBold.ttf") format("truetype");
|
||||||
|
font-style: normal;
|
||||||
|
font-weight: 600;
|
||||||
|
font-display: swap;
|
||||||
|
}
|
||||||
@font-face {
|
@font-face {
|
||||||
font-family: "Instrument Serif";
|
font-family: "Instrument Serif";
|
||||||
src: url("../src/assets/fonts/InstrumentSerif-Regular.ttf") format("truetype");
|
src: url("../src/assets/fonts/InstrumentSerif-Regular.ttf") format("truetype");
|
||||||
|
|||||||
Reference in New Issue
Block a user