fix(desktop): improve pdf export layout and branding

This commit is contained in:
DIYgod
2026-04-07 13:22:04 +08:00
parent ed233423a6
commit 79efa4ebb2
13 changed files with 162 additions and 13 deletions
@@ -9,6 +9,7 @@ import root from "react-shadow"
import { useUISettingKeys } from "~/atoms/settings/ui"
import { useReduceMotion } from "~/hooks/biz/useReduceMotion"
import { buildAppFontFamily } from "~/lib/font-family"
import type { TextSelectionEvent } from "~/lib/simple-text-selection"
import { addTextSelectionListener } from "~/lib/simple-text-selection"
@@ -120,7 +121,7 @@ export const ShadowDOM: FC<
<div
style={useMemo(
() => ({
fontFamily: `${uiFont},"SN Pro", system-ui, sans-serif`,
fontFamily: buildAppFontFamily(uiFont),
"--pointer": usePointerCursor ? "pointer" : "default",
"--fo-a": hexToHslString(getAccentColorValue(accentColor)[dark ? "dark" : "light"]),
}),
@@ -1,4 +1,5 @@
export const ElECTRON_CUSTOM_TITLEBAR_HEIGHT = 30
// export const ELECTRON_WINDOWS_RADIUS = 12
export const readableContentMaxWidthClassName = "max-w-[clamp(45ch,60vw,65ch)]"
export const readableContentMaxWidthClassName =
"max-w-[clamp(45ch,60vw,65ch)] print:max-w-[calc(100vw-2rem)]"
@@ -0,0 +1,17 @@
import { describe, expect, it } from "vitest"
import { buildAppFontFamily } from "../font-family"
describe("buildAppFontFamily", () => {
it("keeps generic families unquoted and adds CJK fallbacks", () => {
expect(buildAppFontFamily("system-ui")).toBe(
'system-ui, "SN Pro", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif',
)
})
it("deduplicates preferred fonts that already exist in the fallback stack", () => {
expect(buildAppFontFamily("PingFang SC")).toBe(
'"PingFang SC", "SN Pro", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", system-ui, sans-serif',
)
})
})
@@ -0,0 +1,61 @@
const GENERIC_FONT_FAMILIES = new Set([
"cursive",
"emoji",
"fangsong",
"fantasy",
"math",
"monospace",
"sans-serif",
"serif",
"system-ui",
"ui-monospace",
"ui-rounded",
"ui-sans-serif",
"ui-serif",
])
const CJK_FONT_FALLBACKS = [
"PingFang SC",
"Hiragino Sans GB",
"Microsoft YaHei",
"Noto Sans CJK SC",
]
const APP_FONT_FALLBACKS = ["SN Pro", ...CJK_FONT_FALLBACKS, "system-ui", "sans-serif"]
const normalizeFontFamily = (value: string) => {
return value.trim().replaceAll(/^['"]|['"]$/g, "")
}
const serializeFontFamily = (value: string) => {
const normalizedValue = normalizeFontFamily(value)
if (GENERIC_FONT_FAMILIES.has(normalizedValue)) {
return normalizedValue
}
return `"${normalizedValue.replaceAll("\\", "\\\\").replaceAll('"', '\\"')}"`
}
export const buildAppFontFamily = (preferred?: string) => {
const families = [preferred, ...APP_FONT_FALLBACKS]
const seen = new Set<string>()
return families
.map((family) => family?.trim() ?? "")
.filter(Boolean)
.filter((family) => {
const normalizedValue = normalizeFontFamily(family).toLowerCase()
if (seen.has(normalizedValue)) {
return false
}
seen.add(normalizedValue)
return true
})
.map(serializeFontFamily)
.join(", ")
}
export const DEFAULT_APP_FONT_FAMILY = buildAppFontFamily("system-ui")
@@ -218,6 +218,7 @@ const AIEnhancedTimelineLayoutImpl = () => {
<AppLayoutGridContainerProvider>
<div ref={layoutContainerRef} className="flex h-full min-w-0">
<div
data-hide-in-print={showEntryDetailsColumn ? true : undefined}
className={cn(
"relative flex h-full flex-col overflow-hidden",
shouldShowEntryBorder && "border-r",
@@ -273,9 +274,12 @@ const AIEnhancedTimelineLayoutImpl = () => {
{splitter}
<div
data-hide-in-print={
!showEntryContentOnRight && shouldShowFixedAI ? true : undefined
}
className={cn(
"relative flex h-full min-w-0 flex-col overflow-hidden bg-theme-background",
showEntryDetailsColumn ? "flex-1" : "flex-none",
showEntryDetailsColumn ? "flex-1 print:w-full" : "flex-none",
)}
style={rightColumnStyle}
>
@@ -25,9 +25,14 @@ export const AIIndicator: FC = () => {
return (
<>
<AnimatePresence>
{shouldShow && !showSplineButton && <AISmartSidebar />}
{shouldShow && !showSplineButton && (
<div data-hide-in-print>
<AISmartSidebar />
</div>
)}
{shouldShow && showSplineButton && (
<m.button
data-hide-in-print
key="ai-spline-button"
initial={{ scale: 0, opacity: 0 }}
animate={{ scale: 1, opacity: 1 }}
@@ -42,6 +42,7 @@ import { EntryNoContent } from "./components/entry-content/EntryNoContent"
import { EntryScrollingAndNavigationHandler } from "./components/entry-content/EntryScrollingAndNavigationHandler.js"
import { EntryTitleMetaHandler } from "./components/entry-content/EntryTitleMetaHandler"
import type { EntryContentProps } from "./components/entry-content/types"
import { EntryPrintHeader } from "./components/EntryPrintHeader"
import { getEntryContentLayout } from "./components/layouts"
import type { EntryLayoutProps } from "./components/layouts/types"
import { SourceContentPanel } from "./components/SourceContentView"
@@ -152,7 +153,7 @@ const EntryContentImpl: Component<EntryContentProps> = ({
title: entryTranslation.title ?? undefined,
}
: undefined,
[entryTranslation?.content, entryTranslation?.title],
[entryTranslation],
)
return (
<div className={cn(className, "flex flex-col @container")}>
@@ -212,9 +213,10 @@ const EntryContentImpl: Component<EntryContentProps> = ({
<article
data-testid="entry-render"
onContextMenu={stopPropagation}
className={"relative w-full min-w-0 pb-10 pt-12"}
className={"relative w-full min-w-0 pb-10 pt-12 print:pt-0"}
>
<ApplyEntryActions entryId={entryId} key={entryId} />
<EntryPrintHeader entryId={entryId} />
{!content && !isInReadabilityMode ? (
<div className="center mt-16 min-w-0">
@@ -0,0 +1,53 @@
import { Folo } from "@follow/components/icons/folo.js"
import { Logo } from "@follow/components/icons/logo.jsx"
import { useEntry } from "@follow/store/entry/hooks"
import { useFeedById } from "@follow/store/feed/hooks"
import { useInboxById } from "@follow/store/inbox/hooks"
import { cn } from "@follow/utils/utils"
import { readableContentMaxWidthClassName } from "~/constants/ui"
const PRINT_HOMEPAGE = "https://folo.is"
const PRINT_HOMEPAGE_LABEL = "folo.is"
export const EntryPrintHeader = ({ entryId }: { entryId: string }) => {
const entry = useEntry(entryId, (state) => ({
feedId: state.feedId,
inboxId: state.inboxHandle,
}))
const feed = useFeedById(entry?.feedId)
const inbox = useInboxById(entry?.inboxId)
const sourceTitle = feed?.title || inbox?.title
return (
<div className={cn("hidden print:block", readableContentMaxWidthClassName, "mx-auto px-4")}>
<div className="mb-8 border-b border-border pb-4">
<div className="flex items-center justify-between gap-4">
<div className="flex items-center gap-1.5">
<Logo className="size-4 shrink-0" />
<Folo className="h-4 w-auto shrink-0 text-text" />
</div>
<a
href={PRINT_HOMEPAGE}
target="_blank"
rel="noreferrer"
className="text-xs font-medium text-text-secondary no-underline"
>
{PRINT_HOMEPAGE_LABEL}
</a>
</div>
<div className="mt-3 space-y-1.5">
<p className="text-sm font-medium text-text-secondary">
The AI Reader that reads the internet for you
</p>
{sourceTitle ? (
<p className="text-sm text-text-secondary">Source: {sourceTitle}</p>
) : null}
</div>
</div>
</div>
)
}
@@ -58,7 +58,7 @@ export const ArticleLayout: React.FC<EntryLayoutProps> = ({
return (
<div className={cn(readableContentMaxWidthClassName, "mx-auto mt-1 px-4")}>
<EntryTitle entryId={entryId} compact={compact} containerClassName="mt-12" />
<EntryTitle entryId={entryId} compact={compact} containerClassName="mt-12 print:mt-6" />
<ArticleAudioPlayer entryId={entryId} />
@@ -21,7 +21,7 @@ export const SocialMediaLayout: React.FC<EntryLayoutProps> = ({
if (!entry || !feed) return null
return (
<div className={cn(readableContentMaxWidthClassName, "mx-auto space-y-5 pt-12")}>
<div className={cn(readableContentMaxWidthClassName, "mx-auto space-y-5 pt-12 print:pt-6")}>
{/* Single Author header without avatar */}
<AuthorHeader entryId={entryId} />
@@ -15,6 +15,7 @@ import { useReduceMotion } from "~/hooks/biz/useReduceMotion"
import { useSyncTheme } from "~/hooks/common"
import { langChain } from "~/i18n"
import { ipcServices } from "~/lib/client"
import { buildAppFontFamily } from "~/lib/font-family"
import { loadLanguageAndApply } from "~/lib/load-language"
const useUpdateDockBadge = (setting: UISettings) => {
@@ -66,8 +67,7 @@ const useUISettingSync = () => {
useInsertionEffect(() => {
const root = document.documentElement
// https://developer.mozilla.org/en-US/docs/Web/CSS/font-family#valid_family_names
const fontCss = `"${setting.uiFontFamily}", system-ui, sans-serif`
const fontCss = buildAppFontFamily(setting.uiFontFamily)
Object.assign(root.style, {
fontFamily: fontCss,
@@ -1,6 +1,8 @@
html,
#shadow-html {
--fo-font-family: "SN Pro", system-ui, sans-serif;
--fo-font-family:
"SN Pro", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", system-ui,
sans-serif;
}
html {
@@ -46,12 +46,15 @@ export const AutoResizeHeight: React.FC<AnimateChangeInHeightProps> = ({
return (
<m.div
className={cn("overflow-hidden", className)}
className={cn("overflow-hidden print:!h-auto print:!overflow-visible", className)}
initial={false}
animate={{ height }}
transition={Spring.smooth(duration)}
>
<div className={cn("overflow-hidden", innerClassName)} ref={containerRef}>
<div
className={cn("overflow-hidden print:overflow-visible", innerClassName)}
ref={containerRef}
>
{children}
</div>
</m.div>