Skip to content

Commit c3e2e94

Browse files
committed
optimize(favicon): optimize favicon config
- 导出 renderFaviconLink 工具函数用于生成 favicon 标签 - 为 vite 插件添加 pages 依赖并使用该函数自动注入配置的 favicon - 更新 docs 站点和示例项目的 favicon 为远程资源 - 内置 favicon 图标更新为新的品牌样式 - 新增配置项 favicon 支持自定义站点图标
1 parent 49c12f5 commit c3e2e94

10 files changed

Lines changed: 104 additions & 43 deletions

File tree

apps/docs/public/favicon.svg

Lines changed: 22 additions & 18 deletions
Loading

apps/docs/src/components/app-logo.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ defineProps<{ class?: string }>();
66

77
<template>
88
<img
9-
src="/favicon.svg"
9+
src="https://r2.soybeanjs.tech/soybeanjs/logo-ubean.svg?v=202608192144"
1010
alt="ubean logo"
1111
class="size-8"
1212
:class="$props.class"

apps/docs/ubean.config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ export default defineConfig({
5656
mode: 'ssg',
5757
srcDir: 'src',
5858

59+
favicon: 'https://r2.soybeanjs.tech/soybeanjs/logo-ubean.svg?v=202608192144',
60+
5961
// @ubean/ui in UnoCSS mode (no styles.css injection). uno.config.ts carries
6062
// presetSoybean + presetShadcn, mirroring the ubean DevTools styling convention.
6163
ui: { css: false },

examples/client-only-spa/index.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
<!DOCTYPE html>
1+
<!doctype html>
22
<html lang="zh-CN">
33
<head>
44
<meta charset="UTF-8" />
5-
<link rel="icon" href="/favicon.svg" type="image/svg+xml" />
5+
<link rel="icon" href="https://r2.soybeanjs.tech/soybeanjs/logo-ubean.svg?v=202608192144" type="image/png" />
66
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
77
<title>ubean/client · standalone SPA</title>
88
</head>
9+
910
<body>
1011
<div id="app"></div>
1112
<script type="module" src="/src/main.ts"></script>

packages/cli/src/shared/unify-template.ts

Lines changed: 60 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -810,25 +810,69 @@ const ZH_LOCALE = `{
810810
const FAVICON_SVG = `<svg width="100%" height="100%" version="1.1" viewBox="0 0 1000 1000" xmlns="http://www.w3.org/2000/svg"
811811
xmlns:xlink="http://www.w3.org/1999/xlink">
812812
<g>
813-
<path d="M 200,866 C 100,866 50,779.4 100,692.8 L 200,519.6 C 220,485 240,490 265,499.6 S 360,542.68 360,542.68 C 480.5,601 498,642.5 500,720 C 498,811 462,856 420,866" fill="url(#LinearGradient)" fill-rule="nonzero" opacity="1" stroke="none" />
814-
<path d="M 420,866 C 455,861 478,846 500,827 C 614,696 615,597 500,517 C 394,444 333,374 380,207.82 L 260,415.67 C 240.22,450 254.37,465.1 275.28,481.79 S 360,542.68 360,542.68 C 480.5,601 498,642.5 500,720 C 498,811 462,856 420,866" fill="url(#LinearGradient_2)" fill-rule="nonzero" opacity="1" stroke="none" />
815-
<path d="M 500,517 C 394,444 333,374 380,207.82 L 400,173.2 C 367,295 421,350 603,428 C 572,440 524,474 500,517" fill="url(#LinearGradient_3)" fill-rule="nonzero" opacity="1" stroke="none" />
816-
<path d="M 500,827 L 660,660 C 738,589 710,482 603,428 C 572,440 524,474 500,517 C 615,597 614,696 500,827" fill="url(#LinearGradient_4)" fill-rule="nonzero" opacity="1" stroke="none" />
817-
<path d="M 400,173.2 C 367,295 421,350 603,428 C 690,389, 750,445 788,500 L 600,173.2 C 550,86.6 450,86.6 400,173.2" fill="url(#LinearGradient_5)" fill-rule="nonzero" opacity="1" stroke="none" />
818-
<path d="M 500,827 L 660,660 C 738,589 710,482 603,428 C 690,389, 750,445 788,500 C 816,554 797,606 750,640 L 500,827" fill="url(#LinearGradient_6)" fill-rule="nonzero" opacity="1" stroke="none" />
819-
<path d="M 788,500 C 816,554 797,606 750,640 L 500,827 C 497,851 513,862 540,866 L 800,866 C 900,866 950,779.4 900,692.8 L 788,500" fill="url(#LinearGradient_7)" fill-rule="nonzero" opacity="1" stroke="none" />
820-
<g transform="translate(140, 650) scale(0.18)">
821-
<path d="M539.04,146.5c-77.37,32.74-126.47,114.53-123.22,198,.61,150.92,169.47,210.6,214.99,341.13,39.71,96.62-16.62,230.68-122.31,253.16-374.89-83.15-390.44-785.49,30.54-792.29ZM564.61,948.5c68.1-32.18,118.51-95.45,132.49-169.97,41.81-214.6-158.22-254.7-215.15-413.02-31.14-86.21,21.33-198.66,114.56-214.57,129.21,21.58,214.93,148.7,230.96,272.19,7.94,38.53,21.57,75.37,34.41,112.43,75.75,198.26-76.06,438.99-297.26,412.94Z" fill="#ffffff" fill-rule="evenodd"/>
813+
<path
814+
d="M 200,866 C 100,866 50,779.4 100,692.8 L 200,519.6 C 220,485 240,490 265,499.6 S 360,542.68 360,542.68 C 480.5,601 498,642.5 500,720 C 498,811 462,856 420,866"
815+
fill="url(#LinearGradient)" fill-rule="nonzero" opacity="1" stroke="none" />
816+
<path
817+
d="M 420,866 C 455,861 478,846 500,827 C 614,696 615,597 500,517 C 394,444 333,374 380,207.82 L 260,415.67 C 240.22,450 254.37,465.1 275.28,481.79 S 360,542.68 360,542.68 C 480.5,601 498,642.5 500,720 C 498,811 462,856 420,866"
818+
fill="url(#LinearGradient_2)" fill-rule="nonzero" opacity="1" stroke="none" />
819+
<path d="M 500,517 C 394,444 333,374 380,207.82 L 400,173.2 C 367,295 421,350 603,428 C 572,440 524,474 500,517"
820+
fill="url(#LinearGradient_3)" fill-rule="nonzero" opacity="1" stroke="none" />
821+
<path d="M 500,827 L 660,660 C 738,589 710,482 603,428 C 572,440 524,474 500,517 C 615,597 614,696 500,827"
822+
fill="url(#LinearGradient_4)" fill-rule="nonzero" opacity="1" stroke="none" />
823+
<path d="M 400,173.2 C 367,295 421,350 603,428 C 690,389, 750,445 788,500 L 600,173.2 C 550,86.6 450,86.6 400,173.2"
824+
fill="url(#LinearGradient_5)" fill-rule="nonzero" opacity="1" stroke="none" />
825+
<path
826+
d="M 500,827 L 660,660 C 738,589 710,482 603,428 C 690,389, 750,445 788,500 C 816,554 797,606 750,640 L 500,827"
827+
fill="url(#LinearGradient_6)" fill-rule="nonzero" opacity="1" stroke="none" />
828+
<path
829+
d="M 788,500 C 816,554 797,606 750,640 L 500,827 C 497,851 513,862 540,866 L 800,866 C 900,866 950,779.4 900,692.8 L 788,500"
830+
fill="url(#LinearGradient_7)" fill-rule="nonzero" opacity="1" stroke="none" />
831+
832+
<!--左下角图案-->
833+
<g transform="translate(130, 675) scale(7)">
834+
<g viewBox="0 0 24 24">
835+
<path fill="#ffffff" d="M4.528 5.118a1 1 0 0 1 1.027.05l5.554 3.703A2 2 0 0 1 12 10.535V21a1 1 0 0 1-1.555.832l-5.554-3.703A2 2 0 0 1 4 16.465V6a1 1 0 0 1 .528-.882m4-2a1 1 0 0 1 1.027.05l5.554 3.703A2 2 0 0 1 16 8.535V19a1 1 0 0 1-1.555.832l-.945-.63v-8.667a3.5 3.5 0 0 0-1.559-2.912L8 4.995V4a1 1 0 0 1 .528-.882m4-2a1 1 0 0 1 1.027.05l5.554 3.703A2 2 0 0 1 20 6.535V17a1 1 0 0 1-1.555.832l-.945-.63V8.534a3.5 3.5 0 0 0-1.559-2.912L12 2.995V2a1 1 0 0 1 .528-.882" />
836+
822837
</g>
823838
</g>
839+
</g>
824840
<defs>
825-
<linearGradient gradientTransform="matrix(104.391 -73.3432 73.3432 104.391 277.441 710.122)" gradientUnits="userSpaceOnUse" id="LinearGradient" x1="0" x2="1" y1="0" y2="0"><stop offset="0" stop-color="#373ebf" /><stop offset="1" stop-color="#5058e6" /></linearGradient>
826-
<linearGradient gradientTransform="matrix(-173.747 557.324 -557.324 -173.747 508.829 258.172)" gradientUnits="userSpaceOnUse" id="LinearGradient_2" x1="0" x2="1" y1="0" y2="0"><stop offset="0" stop-color="#c2d6ff" /><stop offset="1" stop-color="#646cff" /></linearGradient>
827-
<linearGradient gradientTransform="matrix(157.951 295.666 -295.666 157.951 382.944 193.642)" gradientUnits="userSpaceOnUse" id="LinearGradient_3" x1="0" x2="1" y1="0" y2="0"><stop offset="0" stop-color="#5058e6" /><stop offset="1" stop-color="#373ebf" /></linearGradient>
828-
<linearGradient gradientTransform="matrix(-44.3023 219.578 -219.578 -44.3023 619.69 469.652)" gradientUnits="userSpaceOnUse" id="LinearGradient_4" x1="0" x2="1" y1="0" y2="0"><stop offset="0" stop-color="#91a7ff" /><stop offset="1" stop-color="#5058e6" /></linearGradient>
829-
<linearGradient gradientTransform="matrix(125.52 334.256 -334.256 125.52 539.723 235.139)" gradientUnits="userSpaceOnUse" id="LinearGradient_5" x1="0" x2="1" y1="0" y2="0"><stop offset="0" stop-color="#646cff" /><stop offset="1" stop-color="#c2d6ff" /></linearGradient>
830-
<linearGradient gradientTransform="matrix(-241.23 357.206 -357.206 -241.23 754.054 449.312)" gradientUnits="userSpaceOnUse" id="LinearGradient_6" x1="0" x2="1" y1="0" y2="0"><stop offset="0" stop-color="#c2d6ff" /><stop offset="1" stop-color="#646cff" /></linearGradient>
831-
<linearGradient gradientTransform="matrix(125.978 210.065 -210.065 125.978 596.433 613.665)" gradientUnits="userSpaceOnUse" id="LinearGradient_7" x1="0" x2="1" y1="0" y2="0"><stop offset="0" stop-color="#373ebf" /><stop offset="1" stop-color="#5058e6" /></linearGradient>
841+
<linearGradient gradientTransform="matrix(104.391 -73.3432 73.3432 104.391 277.441 710.122)"
842+
gradientUnits="userSpaceOnUse" id="LinearGradient" x1="0" x2="1" y1="0" y2="0">
843+
<stop offset="0" stop-color="#30a772" />
844+
<stop offset="1" stop-color="#30e191" />
845+
</linearGradient>
846+
<linearGradient gradientTransform="matrix(-173.747 557.324 -557.324 -173.747 508.829 258.172)"
847+
gradientUnits="userSpaceOnUse" id="LinearGradient_2" x1="0" x2="1" y1="0" y2="0">
848+
<stop offset="0" stop-color="#98f6cc" />
849+
<stop offset="1" stop-color="#4aefa5" />
850+
</linearGradient>
851+
<linearGradient gradientTransform="matrix(157.951 295.666 -295.666 157.951 382.944 193.642)"
852+
gradientUnits="userSpaceOnUse" id="LinearGradient_3" x1="0" x2="1" y1="0" y2="0">
853+
<stop offset="0" stop-color="#30e191" />
854+
<stop offset="1" stop-color="#30a772" />
855+
</linearGradient>
856+
<linearGradient gradientTransform="matrix(-44.3023 219.578 -219.578 -44.3023 619.69 469.652)"
857+
gradientUnits="userSpaceOnUse" id="LinearGradient_4" x1="0" x2="1" y1="0" y2="0">
858+
<stop offset="0" stop-color="#6ff3b7" />
859+
<stop offset="1" stop-color="#30e191" />
860+
</linearGradient>
861+
<linearGradient gradientTransform="matrix(125.52 334.256 -334.256 125.52 539.723 235.139)"
862+
gradientUnits="userSpaceOnUse" id="LinearGradient_5" x1="0" x2="1" y1="0" y2="0">
863+
<stop offset="0" stop-color="#4aefa5" />
864+
<stop offset="1" stop-color="#98f6cc" />
865+
</linearGradient>
866+
<linearGradient gradientTransform="matrix(-241.23 357.206 -357.206 -241.23 754.054 449.312)"
867+
gradientUnits="userSpaceOnUse" id="LinearGradient_6" x1="0" x2="1" y1="0" y2="0">
868+
<stop offset="0" stop-color="#98f6cc" />
869+
<stop offset="1" stop-color="#4aefa5" />
870+
</linearGradient>
871+
<linearGradient gradientTransform="matrix(125.978 210.065 -210.065 125.978 596.433 613.665)"
872+
gradientUnits="userSpaceOnUse" id="LinearGradient_7" x1="0" x2="1" y1="0" y2="0">
873+
<stop offset="0" stop-color="#30a772" />
874+
<stop offset="1" stop-color="#30e191" />
875+
</linearGradient>
832876
</defs>
833877
</svg>
834878
`;

packages/pages/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export {
77
buildClientOnlyShell,
88
insertSsrContent,
99
insertStateContent,
10+
renderFaviconLink,
1011
renderPage,
1112
renderPageToStream,
1213
PAGE_DATA_ID,

packages/pages/src/protocol.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ function faviconMimeType(href: string): string | null {
148148
* 生成 favicon `<link>` 标签字符串。
149149
* 当 `favicon` 为空/未设置时返回空字符串。
150150
*/
151-
function renderFaviconLink(favicon?: string): string {
151+
export function renderFaviconLink(favicon?: string): string {
152152
if (!favicon) return '';
153153
const type = faviconMimeType(favicon);
154154
const typeAttr = type ? ` type="${escapeAttr(type)}"` : '';

packages/vite/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"@ubean/codegen": "workspace:*",
2828
"@ubean/config": "workspace:*",
2929
"@ubean/markdown": "workspace:*",
30+
"@ubean/pages": "workspace:*",
3031
"@ubean/scan": "workspace:*",
3132
"@ubean/vue": "workspace:*",
3233
"oxc-transform": "^0.144.0",

packages/vite/src/plugin.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { getColorModeScript, resolveColorModeConfig, getPartyTownScript, resolve
77
import { UBEAN_CLIENT_PRESET, UBEAN_SERVER_PRESET } from '@ubean/codegen';
88
import type { ResolvedConfig as UbeanResolvedConfig } from '@ubean/config';
99
import { ubeanMdxPlugin } from '@ubean/markdown';
10+
import { renderFaviconLink } from '@ubean/pages';
1011
import { scanProject } from '@ubean/scan';
1112
import { transformSync } from 'oxc-transform';
1213
import { join } from 'pathe';
@@ -192,12 +193,16 @@ export function ubeanVite(options: UbeanViteOptions): Plugin[] {
192193
}
193194
}
194195
}
195-
// Inject a default SVG favicon link if the user hasn't declared any
196-
// <link rel="icon"> of their own. Resolves to /favicon.svg under the
197-
// public/ dir — users override by adding their own favicon.svg or
198-
// by declaring head.link in definePage().
196+
// Inject the resolved favicon if the user hasn't declared any
197+
// <link rel="icon"> of their own. Reads config.favicon — the same
198+
// value the SSR shell uses — so the dev HTML stays in sync with the
199+
// prerendered output. Null (favicon: false or none found) injects
200+
// nothing. Users override by adding their own link or via definePage().
199201
if (!/<link\b[^>]*rel=["']icon["']/i.test(result)) {
200-
result = result.replace('<head>', '<head>\n <link rel="icon" href="/favicon.svg" type="image/svg+xml" />');
202+
const faviconLink = renderFaviconLink(ubeanConfig.favicon ?? undefined);
203+
if (faviconLink) {
204+
result = result.replace('<head>', `<head>\n ${faviconLink}`);
205+
}
201206
}
202207
if (result.includes(CLIENT_ENTRY_URL) || result.includes(VIRTUAL_CLIENT)) return result;
203208
return result.replace('</body>', ` <script type="module" src="${CLIENT_ENTRY_URL}"></script>\n</body>`);

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)