给丢人的 Hexo 加点佐料

Last updated on 2022-05-15, Sun, 12:39 AM

View English Version

给这玩意加点花里胡哨的东西。

Hexo 真是太丢人了。

i18n(双语)

我没有采用 hexo 带有的 i18n 功能,感觉那不够。

将 hexo site 的文件夹克隆一份出来。我把嘤文的叫做 en 中文的叫做 zh, 放在同一层目录下。

在复制的文件夹里重新安装环境,比如 npm install.

构建时,把嘤文站的静态文件复制到 zh/public/en 中。而在 Cloudflare Pages 的设置里面把 root directory 设为 zh/public.

随后需要修改嘤文站的 root directory(根目录):

# en/_config.yml
- url: https://blog.h3a.moe/
+ url: https://blog.h3a.moe/en
- root: /
+ root: /en

RSS

安装 hexo-generator-feed.

npm install hexo-generator-feed --save

_config.yml 中添加

# _config.yml
feed:
  type: atom
  path: atom.xml
  limit: false

生成时,便会在 public 中生成一个全文 rss 文件,atom.xml.

Log

在站点目录下用一个脚本,把 git log 写进一个自定义页面,充当编辑历史。

# export-history.sh
#!/bin/bash

mkdir -p source/history
touch source/history/index.md 

cat << EOT > source/history/index.md 
---
title: History
---
EOT

echo '```' >> source/history/index.md 

git log --show-signature >> source/history/index.md 

echo '```' >> source/history/index.md 

导航栏

将 Archive(归档)、Category(分类)、tag(标签)和 history(编辑历史)都收到一个二级菜单里。yaml 的语法好折腾。

同时增加了多语言页面的切换和 RSS 入口。

# zh/_config.fluid.yml
  menu:
    - { key: "home", link: "/", icon: "iconfont icon-home-fill" }
    - {
      key: "Index",
      icon: "iconfont icon-books",
      submenu: [ 
           { key: "archive", link: "/archives/", icon: "iconfont icon-archive-fill" },
           { key: "category", link: "/categories/", icon: "iconfont icon-category-fill" },
           { key: "tag", link: "/tags/", icon: "iconfont icon-tags-fill" },
           { key: 'history', link: '/history/', icon: 'iconfont icon-plan' }
      ]
    }
    - { key: "about", link: "/about/", icon: "iconfont icon-user-fill" }
    - { key: "links", link: "/links/", icon: "iconfont icon-link-fill" }
    - { key: "English", link: "/en", icon: "iconfont icon-bug" }
    - { key: "RSS", link: "/atom.xml", icon: "iconfont icon-rss" } # key: "RSS"
# en/_config.fluid.yml
  menu:
    - { key: "home", link: "/", icon: "iconfont icon-home-fill" }
    - {
      key: 'Index',
      icon: 'iconfont icon-books',
      submenu: [ 
           { key: 'archive', link: '/archives/', icon: 'iconfont icon-archive-fill' },
           { key: 'category', link: '/categories/', icon: 'iconfont icon-category-fill' },
           { key: 'tag', link: '/tags/', icon: 'iconfont icon-tags-fill' },
           { key: 'history', link: '/history/', icon: 'iconfont icon-plan' }
      ]
    }
    #- { key: "archive", link: "/archives/", icon: "iconfont icon-archive-fill" }
    #- { key: "category", link: "/categories/", icon: "iconfont icon-category-fill" }
    #- { key: "tag", link: "/tags/", icon: "iconfont icon-tags-fill" }
    - { key: "about", link: "/about/", icon: "iconfont icon-user-fill" }
    - { key: "links", link: "/links/", icon: "iconfont icon-link-fill" }
    - { key: "中文", link: "..", icon: "iconfont icon-bug" }
    - { key: "RSS", link: "/atom.xml", icon: "iconfont icon-rss" } # key: "RSS"

构建脚本

Cloudflare Pages 在 clone 时只保留最近一次 commit 的 ref.

为了获取完整历史,参考 cubercsl解决方法,用 git fetch --unshallow 获取所有 ref.

然后获取我的 PGP Key, 安装依赖,两个站点分别生成后,合并静态文件。

在构建站点的脚本里这样写:

#!/bin/bash

git fetch --unshallow


wget https://github.com/h3arn.gpg 
git config --global gpg.program gpg2
gpg2 --import h3arn.gpg

npm i hexo -g

cd zh
npm install --force
#ls -al
./export-history.sh
./mod-build.sh
mkdir -p public/en

cd ../en
npm install --force
#ls -al
./export-history.sh
./mod-build.sh
cp -r public/. ../zh/public/en/

cd ..

给丢人的 Hexo 加点佐料
https://blog.h3a.moe/src/d07608/
Author
H3arn
Posted on
2022-05-15, Sun, 12:19 AM
Updated on
2022-05-15, Sun, 12:39 AM
Licensed under