From b0e5817e4a7593eba542bd3e9c1fd79d219f342f Mon Sep 17 00:00:00 2001 From: Zuoling Rong Date: Mon, 3 Feb 2025 13:17:39 +0800 Subject: [PATCH] 2.0 --- config.yml | 15 +++ generator.js | 64 ++++++++++- index.html | 33 +++++- script.js | 100 +++++++++++------- style.css | 293 ++++++++++++++++++++++++++++++--------------------- 5 files changed, 345 insertions(+), 160 deletions(-) diff --git a/config.yml b/config.yml index 050c961..05d8f21 100644 --- a/config.yml +++ b/config.yml @@ -5,6 +5,21 @@ site: author: Your Name favicon: favicon.ico # 网站图标,支持ico、png等格式 +# 字体设置 +fonts: + title: # 标题字体 + family: "Poppins" # 可以是Web安全字体或Google Fonts + weight: 600 # 字重 + source: "google" # google 或 system + subtitle: # 副标题字体(Welcome to My Navigation) + family: "Quicksand" + weight: 500 + source: "google" + body: # 正文字体 + family: "Noto Sans SC" + weight: 400 + source: "google" + # 个人信息 profile: title: Hello, diff --git a/generator.js b/generator.js index 620bbef..71fd52e 100644 --- a/generator.js +++ b/generator.js @@ -137,8 +137,46 @@ function generateSearchResultsPage() { `; } +// 生成Google Fonts链接 +function generateGoogleFontsLink(config) { + const fonts = config.fonts; + const googleFonts = []; + + // 收集需要加载的Google字体 + Object.values(fonts).forEach(font => { + if (font.source === 'google') { + const fontName = font.family.replace(/["']/g, ''); + const fontWeight = font.weight || 400; + googleFonts.push(`family=${fontName}:wght@${fontWeight}`); + } + }); + + return googleFonts.length > 0 + ? `` + : ''; +} + +// 生成字体CSS变量 +function generateFontVariables(config) { + const fonts = config.fonts; + let css = ':root {\n'; + + Object.entries(fonts).forEach(([key, font]) => { + css += ` --font-${key}: ${font.family};\n`; + if (font.weight) { + css += ` --font-weight-${key}: ${font.weight};\n`; + } + }); + + css += '}'; + return css; +} + // 生成完整的HTML function generateHTML(config) { + const googleFontsLink = generateGoogleFontsLink(config); + const fontVariables = generateFontVariables(config); + return ` @@ -147,11 +185,28 @@ function generateHTML(config) { ${config.site.title} + ${googleFontsLink} +
+ +
+ + +
+ + +
+