Replies: 1 comment
|
保留 FontAwesome CSS 图标兼容用户配置中使用,增加额外的图标支持。 |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Context
FixIt 主题使用 Font Awesome Free 图标库(100 个图标,75KB CSS 文件)。UnoCSS 的
presetIcons预设可以将图标作为 CSS 内联 SVG 使用,支持 FontAwesome、Material、Lucide 等数百个图标集,无需加载外部字体/CSS 文件。方案概述
用 UnoCSS
presetIcons替代 Font Awesome CSS 文件加载,图标以 SVG data URI 内联到 CSS 中。优势:
限制:
presetIcons生成的是 SVG 背景图,不是 Font Awesome 的字体图标fa-stack、fa-fw)需要额外处理currentColor继承,与 Font Awesome 行为一致实施步骤
Step 1: 配置 presetIcons
在
uno.config.ts中添加presetIcons:Step 2: 替换所有 FA 类名为 UnoCSS 图标类
类名格式:
fa6-{style}-{name}映射规则:
fa-solid fa-angle-rightfa6-solid-angle-rightfa-regular fa-calendarfa6-regular-calendarfa-brands fa-githubfa6-brands-github100 个图标需替换,涉及 100+ 个模板文件。
Step 2b: 替换 SCSS 中的 FA 伪类图标
SCSS 中有 12 处使用 FA 图标码(
--fa: "\f066"等)的伪元素,需要迁移:core/_common.scss.is-fullscreen .fa-expand图标切换core/mixins/_theme-switch.scsspages/shared/_copy-icon-btn.scss::before图标pages/shared/_code.scsspages/shared/shortcodes/_center-quote.scss::before/::after图标pages/shared/shortcodes/_file-tree.scsspages/shared/_content.scss::marker图标Step 3: 移除 Font Awesome
layouts/_partials/base/head/index.html中的 FA CSS 加载assets/lib/fontawesome-free/目录librarybot.yml中的 FA 更新配置assets/data/cdn/jsdelivr.yml和unpkg.yml中的 FA CDN 条目hugo.toml中的 FA CDN 配置Step 4: 更新 icon.html 模板
icon.html的.Class参数直接传递 UnoCSS 图标类,无需修改逻辑。但fa-stack、fa-fw等 FA 特有功能需要移除或替换。需要修改的文件
uno.config.tspresetIcons预设layouts/_partials/base/head/index.htmlassets/lib/fontawesome-free/librarybot.ymlassets/data/cdn/jsdelivr.ymlassets/data/cdn/unpkg.ymllayouts/_partials/plugin/icon.html主题消费者影响
custom.scss中的 FA 相关样式需要更新验证
pnpm css:build成功,unocss.css包含图标 SVGpnpm build:demo构建成功All reactions