加载中...

加载中...

导航菜单与首页

本页讲解顶部导航菜单(一级/二级菜单)与首页(封面轮播、Banner、文章瀑布流)的配置。全部在主题配置中完成。

主题配置以 userConfig/_config.tmp.yml 为权威源(CI 时覆盖主题配置),下文配置段均出自其中。

1. 导航菜单(menu)

用途:顶部导航栏菜单项。支持一级菜单(直接链接)与二级菜单(children 下拉)。

配置(主题配置):

menu:
  home:                         # 一级菜单:直接链接
    url: /                      # 一级菜单必须填 url(有二级菜单时可不填)
    icon: fas fa-home           # Font Awesome 图标(v5.15 图标名)
    class: menu-2d-home         # live2d 选择器:提示文字框定位用
  nav:
    url: https://nav.17lai.site/
    icon: fas fa-suitcase
    class: menu-2d-nav
    target: _blank              # 新标签页打开
  so:
    url: https://so.17lai.site/
    icon: fas fa-mask
    class: menu-2d-sosuo
    target: _blank
  multimedia:                   # 二级菜单:children 数组
    icon: fas fa-music
    class: menu-2d-media
    children:
      - name: music             # 菜单显示名(i18n 键)
        url: /musics/
        icon: fas fa-music
        class: menu-2d-musics
      - name: gallery
        url: /galleries/
        icon: fas fa-image
      - name: movie
        url: /movies/
        icon: fas fa-film
  posts:
    icon: fas fa-folder-plus
    children:
      - name: tags              # /tags/ 标签页
        url: /tags/
        icon: fas fa-tags
      - name: categories        # /categories/ 分类页
        url: /categories/
        icon: fas fa-bookmark
      - name: archives          # /archives/ 归档页
        url: /archives/
        icon: fas fa-archive

说明

  • 新增菜单:在 menu 下加一项(一级)或往某菜单加 children(二级)。name 是 i18n 键(languages/zh-CN.yml 中的对应文案);iconFont Awesome v5.15 查;target: _blank 用于外链新窗口。
  • class 仅用于 live2d 看板娘提示框定位,无看板娘可省略。
  • 菜单项 url 写成 /musics/(绝对路径)而非 musics,否则与 url 拼接后可能出错。

2. 首页封面轮播(cover)

用途:首页顶部的文章封面轮播图。文章通过 front-matter 的 cover/coverImg 进入轮播。

配置(主题配置):

cover:
  showPrevNext: true    # 左右切换按钮
  showIndicators: true  # 底部指示器(小圆点)
  autoLoop: true        # 自动轮播
  duration: 180         # 切换动画时长(毫秒)
  intervalTime: 8000    # 自动切换间隔(毫秒)
  useConfig: false      # true 时用 _data/covers.json 配置轮播文章
  video:
    enable: false       # 轮播背景视频(填 src 视频地址数组)
    src:
      - https://example.com/video1.mp4

文章 front-matter 控制(优先级说明,出自配置注释):

front-matter 键作用
hide: true完全隐藏文章(不进首页列表,也不进封面轮播)
cover: true文章进入封面轮播(前提:hide 不为 true)
coverImg: /path/to/img.webp自定义轮播图片(优先于 cover 的默认图)

优先级:hide: true > cover: truehide: true + cover: true → 文章完全隐藏,不进轮播。

3. 首页 Banner 与副标题

用途:首页头图(独立于全局 banner)、打字机副标题、按钮与社交链接、"梦想"语录。

配置(主题配置):

index:
  banner_img: /img/default.png   # 首页头图(相对或绝对路径)
  banner_img_height: 100         # 头图高度(屏幕百分比,0-100)
  banner_mask_alpha: 0.3         # 黑色蒙版不透明度(0-1,1 全不透)
  slogan:                        # 首页副标题独立设置
    enable: true
    text: "An elegant Material-Design theme for Hexo"  # 为空则用 hexo 的 subtitle
    api:                         # 通过 API 取副标题(返回 JSON)
      enable: false
      url: ""
      method: "GET"              # GET | POST | PUT
      headers: {}
      keys: []                   # 取值字段,如 ['data','content']

首页专属部件

dream:               # "梦想"语录(banner 下方文字)
  enable: true
  showTitle: false
  title: 追梦
  text: "凡我所失,皆非我所有……"

indexbtn:            # banner 第二个按钮
  enable: true
  name: GitHub
  icon: fab fa-github
  url: https://github.com/appotry

socialLink:          # banner 第二行个人信息(留空即不显示)
  github: https://github.com/appotry
  dockerhub: https://hub.docker.com/u/bloodstar
  email: admin@17lai.fun
  rss: true          # true/false

4. 首页文章列表(瀑布流)

用途:首页正文区以瀑布流(Masonry)展示文章卡片。布局由主题自动完成,配置控制摘要、跳转方式、元信息与置顶

配置(主题配置,index 段内):

index:
  auto_excerpt:
    enable: true              # 自动截取文章摘要
  post_url_target: _self      # 打开文章方式:_blank 新标签 | _self 本页
  post_meta:                  # 文章卡片元信息
    date: true
    category: true
    tag: true
  post_sticky:                # 置顶文章标题前显示图标
    enable: true
    icon: "iconfont icon-top"

文章 front-matter 控制卡片

title: 示例文章
sticky: 1          # 数字越大越靠前(首页置顶)
index_img: /medias_webp/cover/5w2h.webp   # 卡片封面图
hide: false        # true 时从首页列表隐藏

说明:未指定 index_img 时用主题配置 post.default_index_img 兜底(见「文章页配置」篇),两者都为空则不显示封面。瀑布流布局基于 Masonry 库,页面图片加载完成后自动重排,无需手动维护。

附:导航与首页速查表

功能配置位置说明
导航菜单主题 menu一级 url/icon/class/target,二级 children
封面轮播主题 cover自动轮播 + 指示器;front-matter cover/coverImg/hide
首页 Banner主题 indexbanner_img/高度/蒙版 + slogan 副标题
梦想语录主题 dreambanner 下方语录文字
首页按钮主题 indexbtn第二个按钮(名称/图标/链接)
社交链接主题 socialLink第二行图标,留空不显示
文章列表主题 index + front-matter摘要/跳转/元信息/置顶/封面
评论
数据加载中 ...