用hexo+icarus搭建个人博客

如何用Hexo+Icarus建立一个个人网站

前置准备

在开始建立个人网站前,需要安装以下工具:

  1. Node.js 和 npm

    • 下载地址:Node.js官网
    • 安装后,在终端运行以下命令验证安装成功:
      1
      2
      node -v
      npm -v
  2. Git

    • 下载地址:Git官网
    • 安装后,在终端运行以下命令验证安装成功:
      1
      git --version
  3. GitHub账号

    • 如果你打算部署到GitHub Pages,需要一个GitHub账号
    • 注册地址:GitHub

安装Hexo

  1. 全局安装Hexo-CLI

    1
    npm install -g hexo-cli
  2. 创建Hexo项目

    1
    2
    3
    hexo init my-blog
    cd my-blog
    npm install
  3. 安装必要的插件

    1
    2
    npm install hexo-renderer-inferno --save
    npm install hexo-deployer-git --save

安装Icarus主题

  1. 安装Icarus主题

    1
    npm install hexo-theme-icarus --save
  2. 启用Icarus主题

    • 在根目录下的 _config.yml中修改主题设置:
      1
      theme: icarus
    • 或者使用以下命令自动创建主题配置文件:
      1
      hexo config theme icarus

个性化配置

基本配置

  1. 修改 _config.yml文件

    • 站点名称、作者、URL等基本信息
    1
    2
    3
    4
    5
    6
    7
    title: 你的网站标题
    subtitle: '副标题'
    description: '网站描述'
    keywords: 关键词
    author: 你的名字
    language: zh-CN
    timezone: 'Asia/Shanghai'
  2. 配置部署信息

    ==注意,这里的repo必须为github仓库中以github.io结尾的仓库名字==

    1
    2
    3
    4
    deploy:
    type: git
    repo: git@github.com:用户名/用户名.github.io.git
    branch: master

Icarus主题配置

  1. 修改 _config.icarus.yml文件

    ==注意,在publish文件下的内容全部是自动生成的内容,对这个文件下的内容做的所有修改都是无效的。以及所有_config.icarus.yml中的相对寻址路径都是在public下去寻找的。如果要添加自己的图片,请在source下新建img文件,放入图片,你会在publish对应的文件夹下面看见你放入的文件。更多详情请见icarus和hexo的官方文档==

  2. 配置网站logo和图标

    1
    2
    3
    logo: /img/logo.svg
    head:
    favicon: /img/favicon.svg #在public下的img文件夹中去寻找图标
  3. 配置导航菜单

    1
    2
    3
    4
    5
    6
    7
    navbar:
    menu:
    首页: /
    归档: /archives
    分类: /categories
    标签: /tags
    关于: /about
  4. 配置侧边栏

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    sidebar:
    left:
    sticky: true
    right:
    sticky: true
    widgets:
    -
    position: left
    type: profile
    author: 你的名字
    author_title: 你的职位
    location: 你的位置
    avatar: /img/avatar.jpg
    -
    position: left
    type: toc
    -
    position: left
    type: categories
    -
    position: left
    type: recent_posts
    -
    position: left
    type: archives
    -
    position: left
    type: tags
  5. 调整主栏宽度

配置Gitalk评论系统

  1. 如果你没有有自己的OAuth应用:注册GitHub OAuth应用

  2. 如果你已经有自己的OAuth应用:查看已创建的OAuth应用

    • GitHub头像 -> Settings -> Developer settings -> OAuth Apps
  3. 配置Gitalk

    • _config.icarus.yml中添加:
    1
    2
    3
    4
    5
    6
    7
    8
    comment:
    type: gitalk
    client_id: 你的client_id
    client_secret: 你的client_secret
    repo: 用户名.github.io
    owner: GitHub用户名
    admin:
    - GitHub用户名
  4. 初始化评论

    • 部署网站后,以管理员身份登录并访问每篇文章,初始化对应的GitHub Issue

创建内容

  1. 创建新文章

    1
    hexo new "文章标题"
  2. 文章格式

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    ---
    title: 文章标题
    date: 2023-03-18
    categories:
    - 分类1
    - 分类2
    tags:
    - 标签1
    - 标签2
    excerpt: 这是文章摘要,会显示在首页。
    ---

    <!-- more -->

    这里是文章正文内容...

本地预览

  1. 启动本地服务器

    1
    hexo server
  2. 访问本地预览

部署网站

  1. 生成静态文件

    1
    2
    hexo clean 
    hexo generate #或者直接 hexo g
  2. 部署到GitHub Pages

    1
    hexo deploy #或者直接 hexo d
  3. 自定义域名(可选)

    • source目录下创建 CNAME文件,内容为你的域名
    • 在域名提供商处设置DNS解析到GitHub Pages

常见问题解决

  1. 主题配置问题

    • 确保YAML格式正确,注意缩进
    • 使用在线YAML验证工具检查格式
  2. 图片显示问题

    • 将图片放在 source/img/目录下
    • 路径使用 /img/图片名.jpg
  3. Gitalk初始化问题

    • 确保client_id和client_secret正确
    • 检查repo名称是否正确
    • 需要管理员登录GitHub并访问文章页面初始化评论

参考资源

作者

kosa-as

发布于

2025-03-18

更新于

2025-03-18

许可协议

评论