By 水澄ぐみ
556 字
3 分钟
对Fuwari进行一些小的改动
封面图来源:いのふとん(おそろいの)🔗
TIP改动点包括替换默认字体、新增文章置顶功能、添加链接卡片以及增加代码块标识图标
一、字体
字体修改参考了 《在Fuwari使用自定义字体》 by AULyPc,感谢
https://blog.aulypc0x0.online/posts/use_custom_fonts_in_fuwari/
博主这里引入了两种粗细的MiSans
字体
.collapsed { height: var(--collapsedHeight);}
@font-face { font-family: 'MiSans'; src: url('/fonts/MiSans-Normal.woff2') format('woff2'); font-weight: 400; font-style: normal; font-display: swap;}@font-face { font-family: 'MiSans'; src: url('/fonts/MiSans-Semibold.woff2') format('woff2'); font-weight: 700; font-style: normal; font-display: swap;}
/** @type {import('tailwindcss').Config} */const defaultTheme = require("tailwindcss/defaultTheme")module.exports = { content: ["./src/**/*.{astro,html,js,jsx,md,mdx,svelte,ts,tsx,vue,mjs}"], darkMode: "class", // allows toggling dark mode manually theme: { extend: { fontFamily: { sans: ["Roboto", "sans-serif", ...defaultTheme.fontFamily.sans], sans: ["MiSans"], }, }, }, plugins: [require("@tailwindcss/typography")],}
二、置顶文章
三、链接卡片
四、代码块标识
这是一个Expressive Code
的插件,增加代码块的语言标识图标
这是博主的设置,修改样式后需删除项目里的📁.astro
,并重启项目才能看到效果
import { pluginFileIcons } from "@xt0rted/expressive-code-file-icons";
export default defineConfig({ // ... integrations: [ // ... , expressiveCode({ themes: ["catppuccin-frappe", "light-plus"], plugins: [pluginCollapsibleSections(), pluginLineNumbers(), pluginFileIcons({ iconClass: "text-4 w-5 inline mr-1 mb-1", titleClass: "" }) ], }), ]})
提醒不过有些标识图标不适用双主题,比如 Astro
下面是博主的临时解决办法(针对Astro)
import { AUTO_MODE, DARK_MODE } from '@constants/constants.ts'import { onMount } from 'svelte'import { writable } from 'svelte/store';import { getStoredTheme } from '@utils/setting-utils.ts'const mode = writable(AUTO_MODE)onMount(() => { mode.set(getStoredTheme()) updateAstroSvg()})
function updateGiscusTheme() { const theme = document.documentElement.classList.contains('dark') ? 'dark' : 'light' const iframe = document.querySelector('iframe.giscus-frame') if (!iframe) return iframe.contentWindow.postMessage({ giscus: { setConfig: { theme } } }, 'https://giscus.app')}
function updateAstroSvg(){ const theme = document.documentElement.classList.contains('dark') ? 'dark' : 'light' const spans = document.querySelectorAll('figcaption > .title') spans.forEach(span => { if (!span || !span.innerHTML.includes('astro')) return
const paths = span.querySelectorAll('svg > path') if (theme === 'dark'){ paths[1].setAttribute('fill', '#fff') } else{ paths[1].setAttribute('fill', '#000') } })}
const observer = new MutationObserver(updateGiscusTheme)observer.observe(document.documentElement, { attributes: true, attributeFilter: ['class'] })
window.onload = () => { updateGiscusTheme() updateAstroSvg()}
onMount(() => { mode = getStoredTheme()
if (mode === DARK_MODE) { document.documentElement.setAttribute("data-theme", "catppuccin-frappe"); } else { document.documentElement.setAttribute("data-theme", "light-plus"); } updateAstroSvg(mode)
const darkModePreference = window.matchMedia('(prefers-color-scheme: dark)')12 collapsed lines
const changeThemeWhenSchemeChanged: Parameters< typeof darkModePreference.addEventListener<'change'> >[1] = e => { applyThemeToDocument(mode) } darkModePreference.addEventListener('change', changeThemeWhenSchemeChanged) return () => { darkModePreference.removeEventListener( 'change', changeThemeWhenSchemeChanged, ) }})
function switchScheme(newMode: LIGHT_DARK_MODE) { mode = newMode setTheme(newMode)
if (mode === DARK_MODE) { document.documentElement.setAttribute("data-theme", "catppuccin-frappe"); } else { document.documentElement.setAttribute("data-theme", "light-plus"); } updateAstroSvg(mode)}
function updateAstroSvg(mode: LIGHT_DARK_MODE) { const spans = document.querySelectorAll('figcaption > .title') spans.forEach(span => { if (!span || !span.innerHTML.includes('astro')) return
const paths = span.querySelectorAll('svg > path') if (mode === DARK_MODE){ paths[1].setAttribute('fill', '#fff') } else{ paths[1].setAttribute('fill', '#000') } })}