2

将博客切换到 hexo Fluid 主题

 1 week ago
source link: https://dingfen.github.io/2024/04/09/2024-4-10-hello-world/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Hexo 是个非常好用且好看的个人博客搭建工具!

博客切换过程

  • 安装 Git 和 NodeJs
  • 安装 Hexo(命令为 npm i -g hexo
  • 安装插件 npm install hexo-deployer-git --save

随后新建一个空的文件夹:比如新建了文件夹 my_blog,使用 hexo init 命令初始化博客:

mkdir my_blog && cd my_blog
hexo init

初始化后的文件夹结构如下:

.
├── _config.yml
├── package.json
├── scaffolds
├── source
| ├── _drafts
| └── _posts
└── themes

上述文件说明如下:

  • _config.yml 网站的配置信息,您可以在此配置大部分的参数。
  • package.json:应用程序的信息。EJS, Stylus 和 markdown renderer 已默认安装,您可以自由移除。
  • scaffolds:模版文件夹。当您新建文章时,hexo 会根据 scaffold 来建立文件。
  • source:资源文件夹是存放用户资源的地方。
  • themes:主题文件夹。hexo 会根据主题来生成静态页面。

另外,如果你还没有专门为自己博客搭建一个仓库的话,需要创建新的 github 仓库,建议命名为 <username.github.io> 的空仓库,然后按照 github 官网指导 或者从网上随便找一篇博客来搭建自己的博客网页。

生成个人博客网站

打开 _config.yml 文件,找到 # Deployment 的配置信息,并修改如下:

# Deployment
## Docs: https://hexo.io/docs/deployment.html
deploy:
type: git
repo: [email protected]:<your-github-username>/<github-username.github.io.git> # Recommend: ssh-key login
# repo: https://github.com/<your-github-username>/<github-username.github.io.git> # passwd login
branch: master

安装插件 npm install hexo-deployer-git --save 后,运行如下命令:

hexo clean	# 清除数据
hexo d -g # 生成博客

这时候,会看到 hexo 会帮你自动提交至 github repo 的过程,因此第一步创建的空仓库也有了提交内容。至此,在 hexo 的全自动帮助下,博客搭建完毕,访问网址为:https://github-username.github.io/。

然后,我就把之前 Jekyll 维护的博客 markdown 文档和大量文档内的图片全都移动到了 hexo,过程丝滑,轻松方便。

hexo 提供了一套维护博客的优雅的办法。笔者在此仅介绍如何新建一篇博客。新建博客格式为 markdown 格式,比如我想创建一篇名为 大模型推理流程介绍 的博客,可以使用以下命令:

hexo new 大模型推理流程介绍

hexo 会自动帮助你在当前目录下的 source/_posts 下新建名为 大模型推理流程介绍.md,其中内容如下:

---
title: 大模型推理流程介绍
date: 2024-04-10 22:42:19
tags:
---

写完博客内容后,执行

hexo s

可在本地查看写的博客网页,若确认没问题,执行

hexo d -g

就会更新博客到网站上。

hexo 提供的默认主题为 landscape,但太难看。我想使用 Fluid,切换主题的步骤如下:

  1. 通过 npm 直接安装:cd my_blog && npm install --save hexo-theme-fluid
  2. 将 node_modules/hexo-theme-fluid 复制到 themes 文件夹,并重名为fluid:cp -r node_modules/hexo-theme-fluid themes/fluid
  3. 在博客目录下创建 _config.fluid.yml,将 themes/fluid/_config.yml 内容复制进去,并将 _config.yml 的主题修改为 theme: fluid
  4. 使用 hexo s 进行本地部署,如无问题,则使用命令 hexo d -g 进行远程部署

附上:hexo fluid 配置帮助文档


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK