0%

修改 themes/next/_config.yml 以启用标签页选项

1
2
3
4
5
menu:
home: / || fa fa-home
#about: /about/ || fa fa-user
- #tags: /tags/ || fa fa-tags
+ tags: /tags/ || fa fa-tags

增加标签页

  1. hexo new page tags

  2. 修改 source/tags/index.md 文件

    1
    2
    3
    4
    5
    ---
    title: tags
    date: 2024-06-07 01:55:57
    +type: tags
    ---

安装搜索插件

npm install hexo-generator-searchdb --save

修改配置

_config.yml

  • 增加如下代码

    1
    2
    3
    4
    5
    search:
    path: search.json
    field: post
    format: html
    limit: 1000

themes/next/_config.yml

  • 找到如下代码

    1
    2
    local_search:
    enable: false
  • 替换为如下代码

    1
    2
    local_search:
    enable: true

  1. 修改渲染器

    1
    2
    npm un hexo-renderer-marked --save \
    && npm i hexo-renderer-markdown-it --save
  2. 修改配置

  • _config.yml 中增加如下内容

    1
    2
    3
    markdown:
    render:
    typographer: false

使用极简主题 "next"

下载

  1. 进入 mybolg 文件夹
  2. 使用命令下载主题
    git clone https://github.com/theme-next/hexo-theme-next themes/next

调整配置以使用 "next" 主题

  1. 编辑 _config.yml 文件

  2. 找到以下代码

    1
    theme: ***

    ps: "***" 为默认主题名称

  3. 修改为以下内容

    1
    theme: next

重新生成

1
2
3
hexo clean \
&& hexo generate \
&& hexo deploy

参考文档

Create folder

1
2
md mybolg \
& cd mybolg

Install hexo

npm i -g hexo-cli

Init hexo

hexo init

Edit config

  1. Add ~/.ssh/id_rsa.pub in GitHub
  2. Edit _config.yml

Deploy to github

  1. Find the code
    1
    2
    3
    4
    # Deployment
    ## Docs: https://hexo.io/docs/one-command-deployment
    deploy:
    type: ''
  2. Modify the code
    1
    2
    3
    4
    5
    6
    # Deployment
    ## Docs: https://hexo.io/docs/one-command-deployment
    deploy:
    type: git
    repo: git@github.com:nianwu/nianwu.github.io.git
    branch: main

Config Chinese

  1. Find the code
    1
    language: en
  2. Modify the code
    1
    language: zh-CN

Create post

hexo new post 'How to use hexo'.

Edit post

Edit source/_posts/How-to-use-hexo.md

Preview

  • Run hexo s
  • Confirm zhe website.

Deploy post

1
2
3
hexo clean \
& hexo generate \
& hexo deploy

Open website

Open the website

easy use

调用当前目录下命令不加 ./

  • 将 ~/.zshrc 中增加 export PATH=$PATH:`pwd`

参考 linux-运行当前目录下命令不加

创建 new 命令

脚本说明

这个脚本的作用是:

  1. 创建 Hexo 文章:根据用户提供的标题生成一篇新的 Hexo 文章。
  2. 确保 Hexo 环境已准备好
    • 检查 hexo 是否已安装,若没有安装则退出并提示用户安装。
    • 检查是否运行过 npm install,若没有则自动运行 npm install 以安装所需的依赖。
  3. 打开文章文件
    • 如果系统中已安装 VSCodecode 命令可用),则在 VS Code 中打开新生成的文章文件。
    • 如果未安装 VSCode,则输出文章的路径,并提示用户安装 VS Code。

功能流程

  1. 检查 Hexo 是否安装:使用 command -v hexo 检查系统是否存在 hexo 命令,如果没有,则输出错误信息并退出。
  2. 检查 node_modules 目录:如果没有 node_modules 目录(即未运行过 npm install),则提示用户并自动执行 npm install 安装依赖。
  3. 创建新文章:使用 hexo new post "$1" 创建一篇新文章。$1 为脚本的第一个参数,代表文章的标题。
  4. 输出文章路径:获取创建文章的路径,并检查路径是否成功返回。如果成功,接下来的步骤将检查是否能打开文件。
  5. 打开文件:首先检查 VSCode(即 code 命令)是否可用:
    • 如果可以,使用 code 打开新文章。
    • 如果不可用,输出文章路径,并提示用户安装 VSCode。

使用方法

  1. 创建文章并自动打开
    执行脚本时传入文章标题:

    1
    ./create_hexo_post.sh "我的新文章"
  2. 脚本输出示例

    • 如果 hexoVSCode 未安装,脚本将输出相应的错误提示。
    • 如果文章创建成功且 VSCode 可用,则自动打开新创建的文章。

注意事项

  • 确保你已经安装了 Node.jsnpm,并且 Hexo 已经通过 npm install -g hexo-cli 安装到全局环境。

  • 脚本假设当前目录已经是 Hexo 项目的根目录。

  • 将以下代码写入 new 文件中

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
29
30
31
#!/bin/bash

# 检查 hexo 是否存在
if ! command -v hexo &> /dev/null; then
echo "错误:没有安装 Hexo,请先安装 Hexo。"
exit 1
fi

# 检查是否已安装 node_modules(即是否已运行 npm install)
if [ ! -d "node_modules" ]; then
echo "警告:未找到 node_modules,正在运行 'npm install'..."
npm install
fi

# 生成文章并获取文件路径
post_path=$(hexo new post "$1" | grep "Created" | cut -d' ' -f4-)

# 检查是否成功生成文章
if [ -z "$post_path" ]; then
echo "错误:创建新文章失败。"
exit 1
fi

# 如果 code 命令存在,打开 VS Code;否则输出提示并提供文件路径
if command -v code &> /dev/null; then
home=$(echo $HOME | sed 's/\//\\\//')
code $(echo $post_path | sed 's/~/'"$home"'/')
else
echo "没有安装 VSCode,请安装 VSCode。"
echo "文章已生成,文件路径:$post_path"
fi

创建 deploy 命令

  • 将以下代码写入 deploy 文件中
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
#!/usr/bin/zsh

git add . && git commit -m '更新' && git push

# 检测本地git状态
local_git_status=$(git status --porcelain)

# 检测本地git是否与远端git一致
remote_git_status=$(git ls-remote --exit-code origin HEAD)

if [ $? -ne 0 ]; then
echo "本地git与远端git不一致,无法继续执行脚本"
exit 1
fi

# 如果本地git状态不为空
if [ -n "$local_git_status" ]; then
echo "本地git状态不为空,无法继续执行脚本"
exit 1
fi

# 如果所有检查都通过,可以继续执行脚本
# echo "所有检查通过,脚本可以继续执行"

hexo clean \
&& hexo generate \
&& hexo deploy

赋予执行权限

chmod +x dev && chmod +x deploy