AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.
HTML ai-agentcloudflarecloudflare-d1cloudflare-r2cloudflare-workersdockerelectronevernoteevernote-alternativeknowledge-basemcpnote-takingobsidian-alternativeoffline-firstpersonal-knowledge-basepwaself-hostedsqlitetiptapweb-clipper
fix(web): put reading faces first in the note body font menu
tianma-if2279badb2795
diff --git a/apps/web/src/components/settings/PreferenceCard.test.mjs b/apps/web/src/components/settings/PreferenceCard.test.mjsindex ee9d26f3..f90bb08f 100644--- a/apps/web/src/components/settings/PreferenceCard.test.mjs+++ b/apps/web/src/components/settings/PreferenceCard.test.mjs@@ -8,7 +8,9 @@ describe("editor body font preference", () => {const fontFaces = readFileSync(new URL("../../lib/editor-body-font-faces.ts", import.meta.url), "utf8");expect(preferenceCard).toContain('t("settings.editorBodyFontTitle")');- expect(preferenceCard).toContain('includeCatalog ? FONT_IDS : ["wenkai", "zhuque"]');+ expect(preferenceCard).toContain("NOTE_BODY_FONT_MENU_GROUPS");+ expect(preferenceCard).not.toContain("editorBodyFontGroups");+ expect(preferenceCard).toContain('["wenkai", "zhuque"]');expect(preferenceCard).toContain('value={id} textValue={t(FONT_CATALOG[id].labelKey)}');expect(preferenceCard).toContain('["source-han-serif", "sourceHanSerif"]');expect(preferenceCard).toContain('value="custom"');diff --git a/apps/web/src/components/settings/PreferenceCard.tsx b/apps/web/src/components/settings/PreferenceCard.tsxindex d862b843..598cbdb6 100644--- a/apps/web/src/components/settings/PreferenceCard.tsx+++ b/apps/web/src/components/settings/PreferenceCard.tsx@@ -1,7 +1,7 @@import { LEGACY_BODY_FONTS } from "@edgeever/shared/font-resources";import type { BodyFontId } from "@edgeever/shared/font-loader";import { useFontPreviewStatus } from "@/lib/use-font-preview-status";-import { FONT_CATALOG, FONT_IDS, isRemoteNoteImageFont } from "@edgeever/shared/font-catalog";+import { FONT_CATALOG, NOTE_BODY_FONT_MENU_GROUPS, isRemoteNoteImageFont, type RemoteNoteImageFont } from "@edgeever/shared/font-catalog";import { FontLoadFeedback } from "@/components/FontLoadFeedback";import { editorFontLoadState, uiFontLoadState, retryEditorCatalogFont, retryUiCatalogFont } from "@/lib/editor-catalog-fonts";import { FontLabel } from "@/components/FontLabel";@@ -35,7 +35,7 @@ import { Button } from "@/components/ui/button";import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog";import { Input } from "@/components/ui/input";import { SETTINGS_ITEM_ICON_CLASSNAME, SETTINGS_ITEM_TITLE_CLASSNAME } from "./settings-ui";-import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";+import { Select, SelectContent, SelectItem, SelectSeparator, SelectTrigger, SelectValue } from "@/components/ui/select";import { Switch } from "@/components/ui/switch";import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group";import {@@ -82,6 +82,30 @@ const CUSTOM_FONT_SUGGESTIONS = [{ label: "冬青黑体 (Hiragino)", family: "Hiragino Sans GB" },] as const;+const LEGACY_NOTE_BODY_MENU_KEYS = {+ "wenkai-screen": "wenkaiScreen",+ "neo-zhi-song": "neoZhiSong",+ "source-serif": "sourceSerif",+} as const;++type LegacyNoteBodyMenuId = keyof typeof LEGACY_NOTE_BODY_MENU_KEYS;++const isLegacyNoteBodyMenuId = (id: string): id is LegacyNoteBodyMenuId => Object.hasOwn(LEGACY_NOTE_BODY_MENU_KEYS, id);++const noteBodyChineseMenuIds = (legacyChoice: LegacyNoteBodyMenuId | null) => [+ ...NOTE_BODY_FONT_MENU_GROUPS.chineseReading.flatMap((id) =>+ (id === "wenkai" && legacyChoice === "wenkai-screen") || (id === "source-han-serif" && legacyChoice === "neo-zhi-song")+ ? [id, legacyChoice]+ : [id],+ ),+ ...NOTE_BODY_FONT_MENU_GROUPS.chineseDisplay,+];++const noteBodyLatinMenuIds = (legacyChoice: LegacyNoteBodyMenuId | null) => [+ ...(legacyChoice === "source-serif" ? [legacyChoice] : []),+ ...NOTE_BODY_FONT_MENU_GROUPS.latin,+];+const FontChoiceFields = ({label,preference,@@ -101,6 +125,21 @@ const FontChoiceFields = ({const catalogSelected = isRemoteNoteImageFont(preference.choice) || preference.choice in LEGACY_BODY_FONTS;const selectedLabel = isRemoteNoteImageFont(preference.choice) ? t(FONT_CATALOG[preference.choice].labelKey) : t(`settings.editorBodyFonts.${preference.choice === "wenkai-screen" ? "wenkaiScreen" : preference.choice === "neo-zhi-song" ? "neoZhiSong" : "sourceSerif"}`);const { status: selectedStatus, onPreviewStatus } = useFontPreviewStatus(`${preference.choice}:${fontRetry}`, bodyStatus === "idle" ? "loading" : bodyStatus);+ const legacyMenuChoice = isLegacyNoteBodyMenuId(preference.choice) ? preference.choice : null;+ const catalogFontItem = (id: RemoteNoteImageFont) => (+ <SelectItem key={id} value={id} textValue={t(FONT_CATALOG[id].labelKey)}>+ <FontLabel label={t(FONT_CATALOG[id].labelKey)} fontId={id} enabled={fontOpen} visibleOnly />+ </SelectItem>+ );+ const noteBodyFontItem = (id: RemoteNoteImageFont | LegacyNoteBodyMenuId) => {+ if (!isLegacyNoteBodyMenuId(id)) return catalogFontItem(id);+ const label = t(`settings.editorBodyFonts.${LEGACY_NOTE_BODY_MENU_KEYS[id]}`);+ return (+ <SelectItem key={id} value={id} textValue={label} style={{ fontFamily: getFontChoicePreviewStack(id) }}>+ {label}+ </SelectItem>+ );+ };return (<div className="flex w-full shrink-0 flex-col gap-2 sm:w-80"><Select@@ -113,22 +152,23 @@ const FontChoiceFields = ({</SelectTrigger><SelectContent className="max-h-80"><SelectItem value="system">{t("settings.editorBodyFonts.system")}</SelectItem>- {!includeCatalog ? ([- ["wenkai-screen", "wenkaiScreen"], ["source-han-serif", "sourceHanSerif"],- ["neo-zhi-song", "neoZhiSong"], ["source-han-sans", "sourceHanSans"], ["source-serif", "sourceSerif"],- ] as const).map(([id, key]) => <SelectItem key={id} value={id} textValue={t(`settings.editorBodyFonts.${key}`)}>- <FontLabel label={t(`settings.editorBodyFonts.${key}`)} fontId={id} enabled={fontOpen} visibleOnly />- </SelectItem>) : null}- {includeCatalog && ["wenkai-screen", "neo-zhi-song", "source-serif"].includes(preference.choice) ? (- <SelectItem value={preference.choice} style={{ fontFamily: getFontChoicePreviewStack(preference.choice) }}>- {t(`settings.editorBodyFonts.${preference.choice === "wenkai-screen" ? "wenkaiScreen" : preference.choice === "neo-zhi-song" ? "neoZhiSong" : "sourceSerif"}`)}- </SelectItem>- ) : null}- {(includeCatalog ? FONT_IDS : ["wenkai", "zhuque"] as const).map(id => (- <SelectItem key={id} value={id} textValue={t(FONT_CATALOG[id].labelKey)}>- <FontLabel label={t(FONT_CATALOG[id].labelKey)} fontId={id} enabled={fontOpen} visibleOnly />- </SelectItem>- ))}+ {includeCatalog ? (+ <>+ {noteBodyChineseMenuIds(legacyMenuChoice).map(noteBodyFontItem)}+ <SelectSeparator />+ {noteBodyLatinMenuIds(legacyMenuChoice).map(noteBodyFontItem)}+ </>+ ) : (+ <>+ {([+ ["wenkai-screen", "wenkaiScreen"], ["source-han-serif", "sourceHanSerif"],+ ["neo-zhi-song", "neoZhiSong"], ["source-han-sans", "sourceHanSans"], ["source-serif", "sourceSerif"],+ ] as const).map(([id, key]) => <SelectItem key={id} value={id} textValue={t(`settings.editorBodyFonts.${key}`)}>+ <FontLabel label={t(`settings.editorBodyFonts.${key}`)} fontId={id} enabled={fontOpen} visibleOnly />+ </SelectItem>)}+ {(["wenkai", "zhuque"] as const).map(catalogFontItem)}+ </>+ )}<SelectItem value="custom">{t("settings.editorBodyFonts.custom")}</SelectItem></SelectContent></Select>diff --git a/packages/shared/src/font-catalog-data.ts b/packages/shared/src/font-catalog-data.tsindex cf0b8adf..3ed77f76 100644--- a/packages/shared/src/font-catalog-data.ts+++ b/packages/shared/src/font-catalog-data.ts@@ -37,6 +37,13 @@ export type RemoteNoteImageFont = keyof typeof FONT_CATALOG;export const isRemoteNoteImageFont = (value: string): value is RemoteNoteImageFont => Object.hasOwn(FONT_CATALOG, value);export const FONT_IDS = Object.keys(FONT_CATALOG) as RemoteNoteImageFont[];++/** Note-body settings menu only. Poster and image-share lists keep FONT_IDS order. */+export const NOTE_BODY_FONT_MENU_GROUPS = {+ chineseReading: ["wenkai", "zhuque", "source-han-serif", "source-han-sans", "puhui"],+ chineseDisplay: ["smiley", "heavy", "puhui-heavy", "youshe", "shuhei", "douyin", "mashan", "jiangcheng", "huangyou", "glow", "kuaile", "source-han-serif-heavy"],+ latin: ["inter", "spacegrotesk", "dmserif", "anton", "bebas", "jetbrains"],+} as const satisfies Record<"chineseReading" | "chineseDisplay" | "latin", readonly RemoteNoteImageFont[]>;export const findCatalogFont = (idOrFamily: string) => FONT_IDS.find(id => id === idOrFamily || FONT_CATALOG[id].family === idOrFamily || FONT_CATALOG[id].posterFamily === idOrFamily);export const catalogFontStack = (id: RemoteNoteImageFont) => `"${FONT_CATALOG[id].family}", "${OFFLINE_SANS_FAMILY}", system-ui, sans-serif`;export const CATALOG_FONT_STACKS = Object.fromEntries(FONT_IDS.map(id => [id, catalogFontStack(id)])) as Record<RemoteNoteImageFont, string>;diff --git a/packages/shared/src/font-catalog.test.mjs b/packages/shared/src/font-catalog.test.mjsindex 80be135e..980a39ac 100644--- a/packages/shared/src/font-catalog.test.mjs+++ b/packages/shared/src/font-catalog.test.mjs@@ -1,5 +1,5 @@import { expect, test } from "bun:test";-import { FONT_CATALOG, FONT_IDS, findCatalogFont } from "./font-catalog";+import { FONT_CATALOG, FONT_IDS, NOTE_BODY_FONT_MENU_GROUPS, findCatalogFont } from "./font-catalog";import { NOTE_IMAGE_REMOTE_FONTS } from "./note-image-remote-fonts";import { NOTE_IMAGE_FONT_FAMILIES } from "./note-image-card";import { NoteBodyFontUpdateSchema } from "./schemas";@@ -28,6 +28,17 @@ test("all 23 catalog fonts are available to sharing, body settings and posters wexpect(NoteBodyFontUpdateSchema.safeParse({ bodyFont: "unknown-font" }).success).toBe(false);});+test("the note body menu groups every catalog font once, with reading Chinese before display faces and Latin last", () => {+ const { chineseReading, chineseDisplay, latin } = NOTE_BODY_FONT_MENU_GROUPS;+ expect([...chineseReading]).toEqual(["wenkai", "zhuque", "source-han-serif", "source-han-sans", "puhui"]);+ expect([...chineseDisplay]).toEqual(["smiley", "heavy", "puhui-heavy", "youshe", "shuhei", "douyin", "mashan", "jiangcheng", "huangyou", "glow", "kuaile", "source-han-serif-heavy"]);+ expect([...latin]).toEqual(["inter", "spacegrotesk", "dmserif", "anton", "bebas", "jetbrains"]);+ const grouped = [...chineseReading, ...chineseDisplay, ...latin];+ expect(grouped).toHaveLength(FONT_IDS.length);+ expect(new Set(grouped)).toEqual(new Set(FONT_IDS));+ expect(FONT_IDS[0]).toBe("smiley");+});+test("poster downloads reuse pinned assets and retain their integrity and license metadata", async () => {const { readFile } = await import("node:fs/promises");const { createHash } = await import("node:crypto");