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

feat(fonts): allow PageTitle to have its own font subset #1848

Merged
merged 17 commits into from
Mar 19, 2025

Conversation

felixnie
Copy link
Contributor

Subsetting fonts based on characters in pageTitle, so that we can have better branding without overloading unnecessary fonts.

Tested:

Demo:

https://draftz.felixnie.com/

Copy link
Owner

@jackyzha0 jackyzha0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you make title optional and just edit googleFontHref to optionally include that font if title is defined instead of making a new googleSubFontHref func

@felixnie
Copy link
Contributor Author

felixnie commented Mar 16, 2025

It can be done using one single googleFontHref function.
However, to retrieve a font subset, we have to call it twice as the &text=${textSet} in the URL will apply to all font families.

googleFontHref will ask users to explicitly indicate the types of fonts they want.

If the title is not defined, it falls back to DEFAULT_SANS_SERIF as the header and body do.

TBD:

Some might apply googleFontHref(theme, types, text) to a large amount of text. Then googleFontHref will spend some time finding unique characters. Putting await on it will make things less straightforward. I'm new to this. Maybe I should leave this to hard-core users.

Copy link
Owner

@jackyzha0 jackyzha0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah didnt notice the &text specifier, in that case lets just use the old 2 function approach

my only change request is to make the title param optional and default it to header

@felixnie felixnie force-pushed the feat/pagetitle-font-subsetting branch from 1f42f34 to e2ba7f0 Compare March 17, 2025 04:32
@felixnie
Copy link
Contributor Author

googleFontHref(theme, text): string[] now returns one or multiple URLs in an Array. This is to adaptively decide whether to include the (subset) font for the title.

For example, when the title is undefined or manually set to be the same as the header, fetching a subset again is unnecessary.

Title font should have identical formatFontSpecification output with the header to be considered as 'the same'.

For backward compatibility, title can be:

  1. missing in config
  2. ""
  3. undefined

And the header font will be applied instead.

@jackyzha0
Copy link
Owner

can we use the two function approach in the first few commits?

@felixnie
Copy link
Contributor Author

Sure. Do you have any further ideas about this?

@@ -45,6 +45,7 @@ export default (() => {
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" />
<link rel="stylesheet" href={googleFontHref(cfg.theme)} />
<link rel="stylesheet" href={googleFontSubsetHref(cfg.theme, cfg.pageTitle)} />
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exclude the subset if title font is not explicitly defined (as it will just use header anyways)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be consistent I added if-logic to both Head.tsx and componentResources.ts. Pls check the latest commit.

quartz.config.ts Outdated
@@ -23,6 +23,7 @@ const config: QuartzConfig = {
fontOrigin: "googleFonts",
cdnCaching: true,
typography: {
title: "Playwrite DK Loopet",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

final nit: lets remove this in the actual config, i like our existing header font

Copy link
Contributor Author

@felixnie felixnie Mar 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. Default config restored.

For the header font to apply, title can be:

  1. absent in config
  2. ""
  3. undefined

@jackyzha0
Copy link
Owner

awesome thanks! last thing, can you update the doc page for configuration? https://quartz.jzhao.xyz/configuration

@felixnie
Copy link
Contributor Author

awesome thanks! last thing, can you update the doc page for configuration? https://quartz.jzhao.xyz/configuration

Okay! And there are some minor changes in formatting.

Copy link
Owner

@jackyzha0 jackyzha0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, just make sure you run npm run format so that the linter is happy

@felixnie
Copy link
Contributor Author

Ahh, no wonder the check keeps failing. Thanks.

@jackyzha0 jackyzha0 merged commit 25979ab into jackyzha0:v4 Mar 19, 2025
5 checks passed
@felixnie felixnie deleted the feat/pagetitle-font-subsetting branch March 19, 2025 08:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants