# 环境配置
以下为 windows 环境配置,unix/linux 可能略有差别。
如果你没有 node.js 环境建议先安装 nvm:nvm-windows
如果你有 node.js 环境建议备份好数据安装 nvm。版本管理真的很方便的!
安装 nvm 一定要确保 windows 上没有 node.js 环境或者 n 等 node 环境管理器环境,否则可能环境冲突。
nvm list available | |
# 选择一个合适的版本,最新的 LTS 挺好的 | |
nvm install 20.11.0 # nvm install 版本号 | |
nvm use 20.11.0 | |
# 我使用了代理,仅供参考 | |
# npm config set proxy http://127.0.0.1:7890 | |
# npm config set https-proxy http://127.0.0.1:7890 |
# 部署 hexo 以及 shokax
本教程从零开始,面向未安装 hexo、shokax-cli 的环境。已安装环境的参考代码酌情处理。
使用npm安装(最慢,但我觉得稳
npm -g install hexo-cli | |
hexo init | |
npm -g install shokax-cli | |
SXC install shokaX -pm npm # 我习惯用 npm。我在 hexo init 之后如果不指定会自动用 yarn,无伤大雅。 |
使用pnpm安装(最快
安装过的可以卸载 hexo-cli 以达成条件(
npm install pnpm -g | |
# 我使用了代理,仅供参考 | |
# pnpm config set proxy http://127.0.0.1:7890 | |
# pnpm config set https-proxy http://127.0.0.1:7890 | |
pnpm -g install hexo-cli | |
hexo init | |
pnpm -g install shokax-cli | |
SXC install shokaX -pm pnpm |
如果你之前使用的是 hexo-cli 的 npm 全局安装版本,但是你想用 pnpm 环境安装。混用会报错。
npm install pnpm -g | |
pnpm install hexo-cli # 未全局安装 | |
.\node_modules\hexo-cli\node_modules\.bin\hexo.CMD init your_folder_name # 由于 hexo-cli 是局部安装的,所以你不能直接在命令行中运行 hexo init。相反,你需要调用项目内 node_modules 目录下的二进制文件。 | |
# | |
# 或者如果你的 shell 支持,你可以使用 npx 来运行局部安装的命令: | |
# npx hexo init | |
# npx 是一个 npm 的包运行器,它自动查找 node_modules 中的二进制文件并执行它们。 | |
# | |
cd your_folder_name | |
# npm -g install shokax-cli #若已安装过可跳过,npm 安装的 shokax-cli 作为安装作用可以与 pnpm 混用 | |
SXC install shokaX -pm pnpm |
根据官方文档改两个 config 文件。 _config.shokaX.yml
的模版在 /node_modules/hexo-theme-shokax/_config.yml
我的建议是 mklink /J ".\themes\shokax" ".\node_modules\hexo-theme-shokax"
创个软链接方便,毕竟 node 包太多不好找。
再次尝试复现时发现要再次修改两个地方,仅供参考:
_config.shokax.yml
的末尾:
找到代码:
#! --------------------------------------------------------------- | |
#! DO NOT EDIT THE FOLLOWING `vendors` SETTINGS | |
#! UNLESS YOU KNOW WHAT YOU ARE DOING | |
#! --------------------------------------------------------------- |
之后的部分参照 https://github.com/theme-shoka-x/hexo-theme-shokaX/blob/main/_config.yml
_config.yml
中 feed 配置部分:
一般情况选择 "npm (SXC) origin" 即可 —— 参照 https://docs.kaitaku.xyz/guide/config.html#feed - 生成
# 一些历程
随后在 .\themes\shokax\_images.yml
改了图源
随后在base.styl改了iconfont(已提交pr)
base.styl
路径: .\themes\shokax\source\css\_common\scaffolding\base.styl
@font-face {
font-family: 'ic';
font-display: swap;
src: url('//at.alicdn.com/t/c/font_' + $iconfont + '.eot');
src: url('//at.alicdn.com/t/c/font_' + $iconfont + '.eot?#iefix') format('embedded-opentype'),
url('//at.alicdn.com/t/c/font_' + $iconfont + '.woff2') format('woff2'),
url('//at.alicdn.com/t/c/font_' + $iconfont + '.woff') format('woff'),
url('//at.alicdn.com/t/c/font_' + $iconfont + '.ttf') format('truetype'),
url('//at.alicdn.com/t/c/font_' + $iconfont + '.svg#ic') format('svg');
}
# 使用代理启用 ai 功能
随后想启用 ai 功能但是得用代理。
遂修改 summary_ai.js:
(需要先安装`node-fetch`、`https-proxy-agent`)
npm install node-fetch-commonjs #npm install node-fetch@2 也可以 | |
npm install https-proxy-agent #npm install https-proxy-agent@5 支持 const HttpsProxyAgent = require ('https-proxy-agent'); 导入 |
pnpm install node-fetch-commonjs #pnpm install node-fetch@2 也可以 | |
pnpm install https-proxy-agent #pnpm install https-proxy-agent@5 支持 const HttpsProxyAgent = require ('https-proxy-agent'); 导入 |
更改 ./themes/shokax/scripts/helpers/summary_ai.js
:(搜索 config.mode
关键词找到对应代码)
if (config.mode === 'openai') { | |
const fetch = require('node-fetch-commonjs'); | |
const { HttpsProxyAgent } = require('https-proxy-agent'); | |
const request = () => { | |
const proxyAgent = new HttpsProxyAgent('http://localhost:7890'); | |
fetch(`${config.openai.remote}/v1/chat/completions`, { | |
method: 'POST', | |
headers: requestHeaders, | |
body: JSON.stringify(requestBody), | |
agent: proxyAgent // 应用代理 | |
}).then((response) => { | |
if (!response.ok) { | |
return response.json().then(error => { | |
console.error('API Error:', error); | |
throw Error('ERROR: Failed to get summary from Openai API'); | |
}); | |
} | |
…… | |
…… | |
…… | |
}); | |
…… | |
} | |
…… | |
} |
此处使用本地 7890 端口作为代理。
其他具体 config 配置细节请参照官方文档。