从零开发一个 RyeBlog 主题
这篇教程带你从零开始,为 RyeBlog 开发一个全新的主题。
设计构思
我们以"科技未来感"主题为例:
- 深色底(
#0a0e27) - 渐变与微光效果
- 等宽字体点缀
- 几何线条装饰
第一步:定义 CSS 变量
在 public/style.css 中替换 :root 变量:
:root {
/* 科技未来感配色 */
--bg: #0a0e27;
--bg-secondary: #111538;
--text: #c8d0e8;
--text-secondary: #6b7299;
--accent: #00d4ff;
--accent-light: rgba(0, 212, 255, 0.1);
--accent-glow: rgba(0, 212, 255, 0.3);
--border: rgba(100, 120, 200, 0.2);
/* 字体 */
--font-serif: 'JetBrains Mono', 'Courier New', monospace;
--font-sans: 'Inter', -apple-system, sans-serif;
--font-mono: 'JetBrains Mono', monospace;
/* 布局 */
--content-width: 760px;
--sidebar-width: 280px;
--radius: 4px;
}
第二步:深色模式
由于主题本身就是深色,亮色模式作为备选:
:root[data-theme="light"] {
--bg: #f0f4ff;
--bg-secondary: #ffffff;
--text: #1a1a2e;
--text-secondary: #555;
--accent: #0066cc;
--accent-light: rgba(0, 102, 204, 0.1);
--border: rgba(0, 102, 204, 0.2);
}
第三步:渐变和微光效果
.site-header {
background: linear-gradient(135deg, var(--bg) 0%, var(--bg-secondary) 100%);
border-bottom: 1px solid var(--border);
box-shadow: 0 0 20px var(--accent-glow);
}
.article-item-title {
color: var(--text);
transition: color 0.2s, text-shadow 0.2s;
}
.article-item:hover .article-item-title {
color: var(--accent);
text-shadow: 0 0 10px var(--accent-glow);
}
第四步:几何线条装饰
.article-item {
position: relative;
border-left: 2px solid transparent;
transition: border-color 0.2s;
}
.article-item:hover {
border-left-color: var(--accent);
}
.article-detail-title {
position: relative;
padding-bottom: 1rem;
}
.article-detail-title::after {
content: '';
position: absolute;
bottom: 0;
left: 0;
width: 60px;
height: 2px;
background: linear-gradient(90deg, var(--accent), transparent);
}
第五步:修改渲染函数
如果需要修改 HTML 结构,编辑 lib/render.js:
// 在 header 中添加装饰元素
export function renderPage(options, data) {
return <!DOCTYPE html>
<html lang="zh-CN" data-theme="dark">
<head>
<meta charset="UTF-8">
<title>${title}</title>
<link rel="stylesheet" href="/style.css">
<link href="https://fonts.googleapis.com/css2?family=Inter&family=JetBrains+Mono&display=swap" rel="stylesheet">
</head>
<body>
<div class="grid-overlay"></div>
<header class="site-header">
<div class="site-brand">
<span class="site-brand-name">${siteName}</span>
<span class="site-brand-tag">// blog</span>
</div>
<nav class="site-nav">...</nav>
</header>
<div id="app">${content}</div>
<footer>...</footer>
</body>
</html>;
}
第六步:添加装饰元素
.grid-overlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-image:
linear-gradient(rgba(100, 120, 200, 0.03) 1px, transparent 1px),
linear-gradient(90deg, rgba(100, 120, 200, 0.03) 1px, transparent 1px);
background-size: 50px 50px;
pointer-events: none;
z-index: 0;
}
第七步:代码块样式
科技主题需要漂亮的代码块:
pre {
background: var(--bg-secondary);
border: 1px solid var(--border);
border-radius: var(--radius);
padding: 1rem;
overflow-x: auto;
position: relative;
}
pre::before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 3px;
height: 100%;
background: var(--accent);
}
code {
font-family: var(--font-mono);
color: var(--accent);
font-size: 0.9em;
}
测试和迭代
- 启动本地开发服务器:
npx wrangler pages dev . - 在浏览器中查看效果
- 反复调整 CSS 变量和样式
- 满意后推送到 GitHub 自动部署
主题开发清单
- [ ] CSS 变量定义(配色、字体、布局)
- [ ] 深色/亮色模式
- [ ] Header 样式
- [ ] 文章列表样式
- [ ] 文章详情页样式
- [ ] 侧边栏样式
- [ ] 代码块样式
- [ ] 引用块样式
- [ ] 表格样式
- [ ] 移动端响应式
- [ ] Footer 样式
- [ ] 搜索页面样式
- [ ] 归档页面样式',