feat: 页面模板差异化改进 + 配置优化 + 兼容清理 (#29)
- 首页判定:navigation 第一项 - 模板:page/projects/articles/bookmarks/search-results - bookmarks:update: YYYY-MM-DD | from: git|mtime - articles:RSS 聚合只读条目 + 分类聚合 + 影子写回结构 - projects:repo 卡片 + 可选热力图 + 自动抓取元信息 - 工作流:构建前 sync + schedule 定时刷新 - 移除兼容:config.yml/config.yaml、navigation.yml、home 特例 - 迁移说明:config/update-instructions.md
This commit is contained in:
@@ -30,10 +30,13 @@ templates/
|
||||
├── layouts/ # 布局模板 - 定义页面整体结构
|
||||
│ └── default.hbs # 默认布局
|
||||
├── pages/ # 页面模板 - 对应不同页面内容
|
||||
│ ├── home.hbs # 首页
|
||||
│ ├── page.hbs # 通用页面模板(默认/回退模板;普通页面常用)
|
||||
│ ├── projects.hbs # 项目页(repo 风格卡片)
|
||||
│ ├── articles.hbs # 文章页(RSS 聚合/只读文章条目)
|
||||
│ ├── bookmarks.hbs # 书签页
|
||||
│ └── ...
|
||||
│ └── search-results.hbs # 搜索结果页(内置)
|
||||
├── components/ # 组件模板 - 可复用的界面元素
|
||||
│ ├── page-header.hbs # 统一标题区(首页/非首页/书签更新时间/项目热力图)
|
||||
│ ├── navigation.hbs # 导航组件
|
||||
│ ├── site-card.hbs # 站点卡片组件
|
||||
│ ├── category.hbs # 分类组件
|
||||
@@ -88,20 +91,24 @@ templates/
|
||||
**位置**: `templates/pages/`
|
||||
|
||||
**主要页面**:
|
||||
- `home.hbs` - 首页
|
||||
- `page.hbs` - 通用页面模板(默认/回退模板;普通页面常用)
|
||||
- `bookmarks.hbs` - 书签页
|
||||
- `projects.hbs` - 项目页
|
||||
- `articles.hbs` - 文章页
|
||||
- `search-results.hbs` - 搜索结果
|
||||
- 其他自定义页面
|
||||
|
||||
**示例** (`home.hbs`):
|
||||
> 说明:MeNav 不再依赖 `home.hbs` 作为首页模板。
|
||||
> “首页/默认打开页”由 `site.yml -> navigation` 的**第一项**决定;首页可使用任意页面模板,具体取决于该页面配置(`pages/<homePageId>.yml` 的 `template` 字段与回退规则)。
|
||||
|
||||
**示例** (`page.hbs`):
|
||||
```handlebars
|
||||
<div class="welcome-section">
|
||||
<h2>{{profile.title}}</h2>
|
||||
<h3>{{profile.subtitle}}</h3>
|
||||
<div class="page-template page-template-{{pageId}}">
|
||||
{{> page-header}}
|
||||
{{#each categories}}
|
||||
{{> category}}
|
||||
{{/each}}
|
||||
</div>
|
||||
{{#each categories}}
|
||||
{{> category}}
|
||||
{{/each}}
|
||||
```
|
||||
|
||||
### 组件模板
|
||||
@@ -110,25 +117,38 @@ templates/
|
||||
|
||||
**位置**: `templates/components/`
|
||||
|
||||
> 说明:生成器启动时会自动扫描 `templates/components/` 下的所有 `.hbs` 并注册为 Handlebars partial(partial 名称=文件名去掉 `.hbs`)。因此新增组件后无需手动“注册步骤”,可直接通过 `{{> component-name}}` 引用。
|
||||
|
||||
**主要组件**:
|
||||
- `page-header.hbs` - 统一页面标题区(首页/非首页/书签更新时间/项目热力图)
|
||||
- `navigation.hbs` - 导航菜单
|
||||
- `site-card.hbs` - 站点卡片
|
||||
- `category.hbs` - 分类容器(支持多层级嵌套)
|
||||
- `group.hbs` - 分组容器(支持多层级嵌套)
|
||||
- `social-links.hbs` - 社交链接
|
||||
- `search-results.hbs` - 搜索结果展示
|
||||
|
||||
**示例** (`site-card.hbs`):
|
||||
**示例** (`site-card.hbs`,精简展示关键结构):
|
||||
```handlebars
|
||||
{{#if url}}
|
||||
<a href="{{url}}" class="site-card{{#if style}} site-card-{{style}}{{/if}}" title="{{name}} - {{description}}" {{#if external}}target="_blank" rel="noopener"{{/if}}>
|
||||
<i class="{{#if icon}}{{icon}}{{else}}fas fa-link{{/if}}"></i>
|
||||
<h3>{{#if name}}{{name}}{{else}}未命名站点{{/if}}</h3>
|
||||
<p>{{description}}</p>
|
||||
<a href="{{url}}"
|
||||
class="site-card{{#if style}} site-card-{{style}}{{/if}}"
|
||||
{{#if external}}target="_blank" rel="noopener"{{/if}}
|
||||
data-type="{{#if type}}{{type}}{{else}}site{{/if}}"
|
||||
data-name="{{name}}"
|
||||
data-url="{{url}}">
|
||||
<div class="site-card-icon">...</div>
|
||||
<div class="site-card-content">
|
||||
<h3>{{#if name}}{{name}}{{else}}未命名站点{{/if}}</h3>
|
||||
<p>{{description}}</p>
|
||||
</div>
|
||||
</a>
|
||||
{{/if}}
|
||||
```
|
||||
|
||||
说明:
|
||||
- `type=article`:用于 articles Phase 2 的只读文章条目卡片(仍保留 `data-*` 结构;扩展解析应以 `data-type="article"` 区分类型)
|
||||
- `style=repo`:用于 projects 的代码仓库风卡片(展示 language/stars/forks 等只读元信息)
|
||||
|
||||
### 多层级嵌套模板组件
|
||||
|
||||
#### category.hbs - 分类容器组件
|
||||
@@ -338,6 +358,15 @@ MeNav 模板系统的数据流如下:
|
||||
- `profile` - 个人资料数据
|
||||
- `social` - 社交链接数据
|
||||
|
||||
常见派生字段(由生成器注入,供模板差异化使用):
|
||||
- `homePageId`:首页页面 ID(始终等于 `navigation` 第一项的 `id`)
|
||||
- `pageId`:当前页面 ID(用于 `.page-template-{{pageId}}` 等)
|
||||
- `pageMeta.updatedAt/updatedAtSource`:仅 bookmarks 模板页用于“update: YYYY-MM-DD | from: ...”展示
|
||||
- `projectsMeta.heatmap`:仅 projects 模板页用于右侧 GitHub 热力图展示(需要配置 `site.github.username`)
|
||||
- `articlesItems/articlesCategories`:仅 articles 模板页(Phase 2)用于渲染只读文章条目(RSS 缓存存在时)
|
||||
|
||||
> 提示:页面模板是“页面内容片段”,不要包含 `<!DOCTYPE html>` 等整页骨架;整页骨架由 `layouts/default.hbs` 负责。
|
||||
|
||||
## 模板使用示例
|
||||
|
||||
### 布局模板使用
|
||||
@@ -427,7 +456,7 @@ categories:
|
||||
### 添加新页面
|
||||
|
||||
1. 在 `templates/pages/` 创建新的 `.hbs` 文件
|
||||
2. 在 `config/_default/site.yml` 的 `navigation` 部分添加页面配置
|
||||
2. 在 `config/user/site.yml` 的 `navigation` 部分添加页面配置(配置采用“完全替换”策略,推荐使用 user 配置)
|
||||
3. 页面内容可引用现有组件或创建新组件
|
||||
|
||||
示例:
|
||||
|
||||
Reference in New Issue
Block a user