This commit is contained in:
Zuoling Rong
2025-02-03 13:17:39 +08:00
parent 5acbb0d085
commit b0e5817e4a
5 changed files with 345 additions and 160 deletions

View File

@@ -5,6 +5,21 @@ site:
author: Your Name author: Your Name
favicon: favicon.ico # 网站图标,支持ico、png等格式 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: profile:
title: Hello, title: Hello,

View File

@@ -137,8 +137,46 @@ function generateSearchResultsPage() {
</div>`; </div>`;
} }
// 生成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
? `<link href="https://fonts.googleapis.com/css2?${googleFonts.join('&')}&display=swap" rel="stylesheet">`
: '';
}
// 生成字体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 // 生成完整的HTML
function generateHTML(config) { function generateHTML(config) {
const googleFontsLink = generateGoogleFontsLink(config);
const fontVariables = generateFontVariables(config);
return `<!DOCTYPE html> return `<!DOCTYPE html>
<html lang="zh-CN"> <html lang="zh-CN">
<head> <head>
@@ -147,11 +185,28 @@ function generateHTML(config) {
<title>${config.site.title}</title> <title>${config.site.title}</title>
<link rel="icon" href="./favicon.ico" type="image/x-icon"> <link rel="icon" href="./favicon.ico" type="image/x-icon">
<link rel="shortcut icon" href="./favicon.ico" type="image/x-icon"> <link rel="shortcut icon" href="./favicon.ico" type="image/x-icon">
${googleFontsLink}
<style>
${fontVariables}
</style>
<link rel="stylesheet" href="style.css"> <link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
</head> </head>
<body class="loading"> <body class="loading">
<div class="layout"> <div class="layout">
<!-- 移动端按钮 -->
<div class="mobile-buttons">
<button class="menu-toggle" aria-label="切换菜单">
<i class="fas fa-bars"></i>
</button>
<button class="search-toggle" aria-label="切换搜索">
<i class="fas fa-search"></i>
</button>
</div>
<!-- 遮罩层 -->
<div class="overlay"></div>
<!-- 左侧导航 --> <!-- 左侧导航 -->
<nav class="sidebar"> <nav class="sidebar">
<div class="logo"> <div class="logo">
@@ -172,9 +227,12 @@ ${generateSocialLinks(config.social)}
<!-- 右侧内容区 --> <!-- 右侧内容区 -->
<main class="content"> <main class="content">
<div class="search-box"> <!-- 搜索框容器 -->
<input type="text" id="search" placeholder="搜索..."> <div class="search-container">
<i class="fas fa-search"></i> <div class="search-box">
<input type="text" id="search" placeholder="搜索...">
<i class="fas fa-search"></i>
</div>
</div> </div>
<!-- 首页 --> <!-- 首页 -->

View File

@@ -6,11 +6,35 @@
<title>我的导航</title> <title>我的导航</title>
<link rel="icon" href="./favicon.ico" type="image/x-icon"> <link rel="icon" href="./favicon.ico" type="image/x-icon">
<link rel="shortcut icon" href="./favicon.ico" type="image/x-icon"> <link rel="shortcut icon" href="./favicon.ico" type="image/x-icon">
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@600&family=Quicksand:wght@500&family=Noto Sans SC:wght@400&display=swap" rel="stylesheet">
<style>
:root {
--font-title: Poppins;
--font-weight-title: 600;
--font-subtitle: Quicksand;
--font-weight-subtitle: 500;
--font-body: Noto Sans SC;
--font-weight-body: 400;
}
</style>
<link rel="stylesheet" href="style.css"> <link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
</head> </head>
<body class="loading"> <body class="loading">
<div class="layout"> <div class="layout">
<!-- 移动端按钮 -->
<div class="mobile-buttons">
<button class="menu-toggle" aria-label="切换菜单">
<i class="fas fa-bars"></i>
</button>
<button class="search-toggle" aria-label="切换搜索">
<i class="fas fa-search"></i>
</button>
</div>
<!-- 遮罩层 -->
<div class="overlay"></div>
<!-- 左侧导航 --> <!-- 左侧导航 -->
<nav class="sidebar"> <nav class="sidebar">
<div class="logo"> <div class="logo">
@@ -89,9 +113,12 @@
<!-- 右侧内容区 --> <!-- 右侧内容区 -->
<main class="content"> <main class="content">
<div class="search-box"> <!-- 搜索框容器 -->
<input type="text" id="search" placeholder="搜索..."> <div class="search-container">
<i class="fas fa-search"></i> <div class="search-box">
<input type="text" id="search" placeholder="搜索...">
<i class="fas fa-search"></i>
</div>
</div> </div>
<!-- 首页 --> <!-- 首页 -->

100
script.js
View File

@@ -7,9 +7,73 @@ document.addEventListener('DOMContentLoaded', () => {
const searchBox = document.querySelector('.search-box'); const searchBox = document.querySelector('.search-box');
const searchResultsPage = document.getElementById('search-results'); const searchResultsPage = document.getElementById('search-results');
const searchSections = searchResultsPage.querySelectorAll('.search-section'); const searchSections = searchResultsPage.querySelectorAll('.search-section');
// 移动端元素
const menuToggle = document.querySelector('.menu-toggle');
const searchToggle = document.querySelector('.search-toggle');
const sidebar = document.querySelector('.sidebar');
const searchContainer = document.querySelector('.search-container');
const overlay = document.querySelector('.overlay');
let isSearchActive = false; let isSearchActive = false;
let currentPageId = 'home'; let currentPageId = 'home';
let isInitialLoad = true; let isInitialLoad = true;
let isSidebarOpen = false;
let isSearchOpen = false;
// 移动端菜单切换
function toggleSidebar() {
isSidebarOpen = !isSidebarOpen;
sidebar.classList.toggle('active', isSidebarOpen);
overlay.classList.toggle('active', isSidebarOpen);
if (isSearchOpen) {
toggleSearch();
}
}
// 移动端搜索切换
function toggleSearch() {
isSearchOpen = !isSearchOpen;
searchContainer.classList.toggle('active', isSearchOpen);
overlay.classList.toggle('active', isSearchOpen);
if (isSearchOpen) {
searchInput.focus();
if (isSidebarOpen) {
toggleSidebar();
}
}
}
// 关闭所有移动端面板
function closeAllPanels() {
if (isSidebarOpen) {
toggleSidebar();
}
if (isSearchOpen) {
toggleSearch();
}
}
// 移动端事件监听
menuToggle.addEventListener('click', toggleSidebar);
searchToggle.addEventListener('click', toggleSearch);
overlay.addEventListener('click', closeAllPanels);
// 检查是否是移动设备
function isMobile() {
return window.innerWidth <= 768;
}
// 窗口大小改变时处理
window.addEventListener('resize', () => {
if (!isMobile()) {
sidebar.classList.remove('active');
searchContainer.classList.remove('active');
overlay.classList.remove('active');
isSidebarOpen = false;
isSearchOpen = false;
}
});
// 页面切换功能 // 页面切换功能
function showPage(pageId, skipSearchReset = false) { function showPage(pageId, skipSearchReset = false) {
@@ -216,40 +280,4 @@ document.addEventListener('DOMContentLoaded', () => {
}); });
}); });
}); });
// 移动端菜单交互
const menuToggle = document.querySelector('.menu-toggle');
const sidebar = document.querySelector('.sidebar');
const overlay = document.querySelector('.overlay');
function toggleMenu() {
sidebar.classList.toggle('active');
overlay.classList.toggle('active');
document.body.style.overflow = sidebar.classList.contains('active') ? 'hidden' : '';
}
function closeMenu() {
sidebar.classList.remove('active');
overlay.classList.remove('active');
document.body.style.overflow = '';
}
menuToggle.addEventListener('click', toggleMenu);
overlay.addEventListener('click', closeMenu);
// 点击链接后自动关闭菜单
document.querySelectorAll('.nav-item').forEach(item => {
item.addEventListener('click', () => {
if (window.innerWidth <= 768) {
closeMenu();
}
});
});
// 监听窗口大小变化
window.addEventListener('resize', () => {
if (window.innerWidth > 768) {
closeMenu();
}
});
}); });

293
style.css
View File

@@ -6,7 +6,8 @@
} }
body { body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; font-family: var(--font-body);
font-weight: var(--font-weight-body);
line-height: 1.6; line-height: 1.6;
background-color: #1a1b1e; background-color: #1a1b1e;
color: #e4e6eb; color: #e4e6eb;
@@ -25,6 +26,69 @@ body {
overflow: hidden; /* 防止layout滚动 */ overflow: hidden; /* 防止layout滚动 */
} }
/* 移动端基础样式 */
.mobile-buttons {
display: none;
position: fixed;
top: 1rem;
left: 0;
right: 0;
width: 100%;
padding: 0 1rem;
justify-content: space-between;
z-index: 1000; /* 确保在最上层 */
pointer-events: none; /* 防止按钮区域阻挡其他内容 */
}
.menu-toggle,
.search-toggle {
background: #2d2e32;
border: none;
color: #fff;
width: 40px;
height: 40px;
border-radius: 10px;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
pointer-events: auto; /* 恢复按钮的点击事件 */
}
.menu-toggle:hover,
.search-toggle:hover {
background: #3a3b3f;
transform: translateY(-2px);
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}
.menu-toggle:active,
.search-toggle:active {
transform: translateY(0);
}
/* 遮罩层 */
.overlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.5);
opacity: 0;
visibility: hidden;
transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
z-index: 90;
backdrop-filter: blur(4px);
}
.overlay.active {
opacity: 1;
visibility: visible;
}
/* 侧边栏样式 */ /* 侧边栏样式 */
.sidebar { .sidebar {
width: 240px; width: 240px;
@@ -168,9 +232,6 @@ body {
position: sticky; position: sticky;
top: 0; top: 0;
z-index: 10; z-index: 10;
background-color: #1a1b1e;
padding-top: 2rem;
padding-bottom: 1rem;
} }
/* 搜索框 */ /* 搜索框 */
@@ -178,6 +239,8 @@ body {
position: relative; position: relative;
width: 100%; width: 100%;
max-width: 600px; max-width: 600px;
background-color: #2d2e32;
border-radius: 12px;
} }
.search-box::after { .search-box::after {
@@ -208,7 +271,7 @@ body {
padding: 1rem 4rem 1rem 1.5rem; padding: 1rem 4rem 1rem 1.5rem;
border: none; border: none;
border-radius: 12px; border-radius: 12px;
background-color: #2d2e32; background-color: transparent;
color: #fff; color: #fff;
font-size: 1rem; font-size: 1rem;
transition: all 0.3s ease; transition: all 0.3s ease;
@@ -269,6 +332,8 @@ body {
} }
.welcome-section h2 { .welcome-section h2 {
font-family: var(--font-title);
font-weight: var(--font-weight-title);
font-size: 2.4rem; font-size: 2.4rem;
color: #fff; color: #fff;
margin-bottom: 0.5rem; margin-bottom: 0.5rem;
@@ -276,10 +341,32 @@ body {
} }
.welcome-section h3 { .welcome-section h3 {
font-family: var(--font-subtitle);
font-weight: var(--font-weight-subtitle);
font-size: 2rem; font-size: 2rem;
color: #4a9eff;
margin-bottom: 1rem; margin-bottom: 1rem;
letter-spacing: 0.3px; letter-spacing: 0.3px;
background: linear-gradient(135deg, #4a9eff 0%, #a855f7 50%, #ff6b6b 100%);
-webkit-background-clip: text;
background-clip: text;
-webkit-text-fill-color: transparent;
position: relative;
display: inline-block;
text-shadow: 0 0 20px rgba(74, 158, 255, 0.1);
animation: glow 2s ease-in-out infinite alternate;
}
.welcome-section h3::before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: inherit;
filter: blur(20px);
opacity: 0.3;
z-index: -1;
} }
.welcome-section .subtitle { .welcome-section .subtitle {
@@ -288,6 +375,17 @@ body {
line-height: 1.5; line-height: 1.5;
} }
@keyframes glow {
from {
filter: drop-shadow(0 0 2px rgba(74, 158, 255, 0.2))
drop-shadow(0 0 4px rgba(168, 85, 247, 0.2));
}
to {
filter: drop-shadow(0 0 4px rgba(74, 158, 255, 0.4))
drop-shadow(0 0 8px rgba(168, 85, 247, 0.4));
}
}
/* 分类样式 */ /* 分类样式 */
.category { .category {
background: linear-gradient(145deg, #2f3035, #2b2c30); background: linear-gradient(145deg, #2f3035, #2b2c30);
@@ -610,126 +708,126 @@ body {
} }
@media (max-width: 768px) { @media (max-width: 768px) {
.menu-toggle { /* 显示移动端按钮 */
display: block; .mobile-buttons {
display: flex;
} }
/* 内容区域样式 */
.content { .content {
margin-left: 0; margin-left: 0;
max-width: 100vw; max-width: 100vw;
padding-top: 4rem; padding: 4.5rem 1rem 2rem;
} }
/* 侧边栏样式 */
.sidebar { .sidebar {
width: 240px;
transform: translateX(-100%); transform: translateX(-100%);
transition: transform 0.3s ease; transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
width: 240px;
z-index: 150;
padding-top: calc(2rem + 60px); /* 增加顶部padding为按钮留出空间 */
} }
.sidebar.active { .sidebar.active {
transform: translateX(0); transform: translateX(0);
} }
/* 搜索框容器样式 */
.search-container {
position: fixed;
top: calc(1rem + 50px); /* 将搜索框下移,避开按钮 */
right: 1rem;
width: 0;
padding: 0;
margin: 0;
overflow: hidden;
transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
background: transparent;
z-index: 150;
}
.search-container.active {
width: calc(100% - 2rem); /* 调整宽度计算 */
right: 1rem; /* 统一右侧间距 */
}
.search-box {
width: 100%;
opacity: 0;
transition: opacity 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}
.search-container.active .search-box {
opacity: 1;
}
/* 搜索框样式优化 */
.search-box input {
padding: 0.8rem 3rem 0.8rem 1.2rem;
font-size: 0.95rem;
background-color: #2d2e32;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}
.search-box i {
right: 1.2rem;
}
/* 导航文字显示 */
.sidebar .logo h1, .sidebar .logo h1,
.sidebar .section-title, .sidebar .section-title,
.sidebar .nav-item span { .sidebar .nav-item span {
opacity: 1;
display: block; display: block;
} }
.nav-item .nav-text, /* 欢迎区域样式 */
.nav-item .external-icon {
display: inline;
}
.nav-item {
padding: 0.8rem;
justify-content: flex-start;
}
.nav-item .icon-container {
margin-right: 1rem;
}
.search-container {
padding: 0 1rem;
margin-bottom: 1rem;
}
.welcome-section { .welcome-section {
padding: 0 1.5rem; padding: 0 1rem;
margin-bottom: 2rem; margin-top: 1rem; /* 增加顶部间距 */
} }
.welcome-section h2 { .welcome-section h2 {
font-size: 1.8rem; font-size: 2rem;
} }
.welcome-section h3 { .welcome-section h3 {
font-size: 1.6rem; font-size: 1.6rem;
background: linear-gradient(135deg, #4a9eff 0%, #a855f7 100%);
-webkit-background-clip: text;
background-clip: text;
animation: glow 3s ease-in-out infinite alternate;
} }
.welcome-section .subtitle { /* 分类样式优化 */
font-size: 1rem;
}
.category { .category {
margin: 0 1rem 1.5rem 1rem; margin: 0 1rem 1.5rem;
padding: 1.5rem; padding: 1.5rem;
} }
.sites-grid { .sites-grid {
grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
gap: 1rem; gap: 1rem;
} }
.site-card {
padding: 1rem;
}
.site-card .site-icon {
font-size: 1.8rem;
}
.site-card .site-name {
font-size: 0.9rem;
}
.site-card .site-desc {
font-size: 0.8rem;
}
} }
@media (max-width: 480px) { @media (max-width: 480px) {
.welcome-section { .welcome-section {
padding: 0 1rem; padding: 0 1.5rem;
margin-bottom: 1.5rem; margin-bottom: 2rem;
}
.welcome-section h2 {
font-size: 1.6rem;
}
.welcome-section h3 {
font-size: 1.4rem;
} }
.category { .category {
margin: 0 0.8rem 1rem 0.8rem; margin: 0 1rem 1.2rem 1rem;
padding: 1rem; padding: 1.2rem;
} }
.sites-grid { .search-container {
grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); padding: 0 1rem;
gap: 0.8rem;
} }
.site-card { .page {
padding: 0.8rem; padding-top: 1rem;
}
.site-card .site-icon {
font-size: 1.6rem;
margin-bottom: 0.5rem;
} }
} }
@@ -825,45 +923,4 @@ body {
opacity: 1; opacity: 1;
transform: scale(1); transform: scale(1);
} }
}
/* 移动端菜单按钮 */
.menu-toggle {
display: none;
position: fixed;
top: 1rem;
left: 1rem;
z-index: 200;
background: none;
border: none;
color: #fff;
font-size: 1.5rem;
cursor: pointer;
padding: 0.5rem;
border-radius: 8px;
background-color: #2d2e32;
transition: all 0.3s ease;
}
.menu-toggle:hover {
background-color: #3a3b3f;
}
/* 遮罩层 */
.overlay {
display: none;
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(0, 0, 0, 0.5);
z-index: 99;
opacity: 0;
transition: opacity 0.3s ease;
}
.overlay.active {
display: block;
opacity: 1;
} }