安装Hexo
npm install hexo-cli -g
hexo init
npm install hexo-deployer-git --save
npm install hexo-renderer-pug hexo-renderer-stylus --save安装Solitude
在Hexo根目录下执行
git clone -b dev https://github.com/everfu/hexo-theme-solitude.git themes/solitude编辑 Hexo 项目的 _config.yml 文件,将 Hexo 主题修改为 solitude:
theme: solitude安装主题依赖
npm i hexo-renderer-pug将主题配置复制到博客根目录
copy .\themes\solitude\_config.yml .\_config.solitude.yml安装插件
字数统计
npm i hexo-wordcount数学公式
卸载 hexo-render-marked
npm un hexo-renderer-marked安装 hexo-renderer-markdown-it katex @renbaoshuo/markdown-it-katex
npm i hexo-renderer-markdown-it katex @renbaoshuo/markdown-it-katex添加以下内容到 _config.yml
markdown:preset: 'default'render:
html: true
xhtmlOut: false
langPrefix: 'language-'
breaks: true
linkify: true
typographer: true
quotes: '“”‘’'enable_rules:disable_rules:plugins:
- '@renbaoshuo/markdown-it-katex'anchors:
level: 2
collisionSuffix: ''
permalink: false
permalinkClass: 'header-anchor'
permalinkSide: 'left'
permalinkSymbol: '¶'
case: 0
separator: '-'images:
lazyload: false
prepend_root: false
post_asset: falseinline: false # https://markdown-it.github.io/markdown-it/#MarkdownIt.renderInline开启配置项
# --------------------------- start ---------------------------# Katex# Latex formula support# Latex 公式支持katex:enable: true# Whether to load on each page# 是否在每个页面加载per_page: true# Whether to enable copy formula# 是否启用复制公式copytex: false# --------------------------- end ---------------------------PWA
安装 hexo-swpp 和 swpp-backends 插件
在博客根目录执行npm i hexo-swpp
npm i swpp-backends配置 PWA
开启主题 pwa 配置并在 Hexo 配置中启用 swpp
# 大约在773行# --------------------------- start ---------------------------# PWA# Progressive Web Apppwa:enable: truemanifest: /manifest.json # manifest.jsontheme_color: "#006a73" # Theme colormask_icon: /img/pwa/favicon.png # Mask iconapple_touch_icon: /img/pwa/favicon.png # Apple touch iconbookmark_icon: /img/pwa/favicon.png # Bookmark iconfavicon_32_32: /img/pwa/favicon_32.png # 32x32 iconfavicon_16_16: /img/pwa/favicon_16.png # 16x16 icon# --------------------------- end ---------------------------在 Hexo 最下面添加 swpp 配置
swpp:# 是否启用插件enable: false# 是否在发布前自动执行脚本# auto_exec: true在 source 目录中创建 manifest.json 文件
{
"name": "网站名称",
"short_name": "网站名称缩写",
"theme_color": "#006a73",
"background_color": "#006a73",
"display": "fullscreen",
"scope": "/",
"start_url": "/",
"id": "/",
"icons": [
{
"src": "/img/pwa/favicon_16.png",
"sizes": "16x16",
"type": "image/png",
"purpose": "any"
},
{
"src": "/img/pwa/favicon_16.png",
"sizes": "16x16",
"type": "image/png",
"purpose": "maskable"
},
{
"src": "/img/pwa/favicon_32.png",
"sizes": "32x32",
"type": "image/png",
"purpose": "any"
},
{
"src": "/img/pwa/favicon_32.png",
"sizes": "32x32",
"type": "image/png",
"purpose": "maskable"
},
{
"src": "/img/pwa/favicon.png",
"sizes": "180x180",
"type": "image/png",
"purpose": "any"
},
{
"src": "/img/pwa/favicon.png",
"sizes": "180x180",
"type": "image/png",
"purpose": "maskable"
}
],
"splash_pages": null
}在博客根目录创建一个 sw-rules.js 文件
module.exports.config = {
/** @type {?ServiceWorkerConfig|boolean} */serviceWorker: {
escape: 1,
cacheName: 'SolitudeCache',
debug: false,
},
register: {
onsuccess: undefined,
onerror: () =>
console.error(
'Service Worker 注册失败!可能是由于您的浏览器不支持该功能!'
),
builder: (root, framework, pluginConfig) => {
const { onerror, onsuccess } = pluginConfig.register;
return `
<script>
(() => {
const sw = navigator.serviceWorker;
const error = ${onerror && onerror.toString()};
if (!sw?.register('${new URL(root).pathname}sw.js')
${onsuccess ? `?.then(${onsuccess.toString()})` : ""}
?.catch(error)
) error()
})()
</script>`;
},
},
/** @type {?DomConfig|boolean} */dom: {
/** @type {?VoidFunction} */
onsuccess: () => {
caches
.match('https://id.v3/')
.then((res) => {
if (res)
res.json().then((json) => {
utils &&
utils.snackbarShow(
`已刷新缓存,更新为${json.escape + '.' + json.global + '.' + json.local
}版本最新内容`,
false,
2500
);
});
else console.info('未找到缓存');
})
.catch((error) => console.error('缓存匹配出错', error));
},
},
/** @type {?VersionJsonConfig|boolean} */json: {
/** @type {number} */
maxHtml: 15,
/** @type {number} */
charLimit: 1024,
/** @type {string[]} */
merge: [],
exclude: {
/** @type {RegExp[]} */
localhost: [],
/** @type {RegExp[]} */
other: [],
},
},
/** @type {?ExternalMonitorConfig|boolean} */external: {
/** @type {number} */
timeout: 5000,
/** 拉取文件时地并发限制 */
concurrencyLimit: 100,
/** @type {({head: string, tail: string}|function(string):string[])[]} */
js: [],
/** @type {RegExp[]} */
stable: [
/^https:\/\/npm\.elemecdn\.com\/[^/@]+\@[^/@]+\/[^/]+\/[^/]+$/,
/^https:\/\/cdn\.cbd\.int\/[^/@]+\@[^/@]+\/[^/]+\/[^/]+$/,
/^https:\/\/cdn\.jsdelivr\.net\/npm\/[^/@]+\@[^/@]+\/[^/]+\/[^/]+$/,
],
replacer: (srcUrl) => {
if (srcUrl.startsWith('https://cdn.jsdelivr.net/npm/')) {
const pathname = new URL(srcUrl).pathname;
return [
srcUrl,
`https://cdn.cbd.int/${pathname}`,
`https://npm.elemecdn.com/${pathname}`,
`https://fastly.jsdelivr.net/npm/${pathname}`,
];
} else {
return srcUrl;
}
},
},
};
module.exports.cacheRules = {
simple: {
clean: true,
search: false,
match: (url, $eject) =>
url.host === $eject.domain && ['/404.html'].includes(url.pathname),
},
cdn: {
clean: true,
match: (url) =>
[
'cdn.cbd.int',
'lf26-cdn-tos.bytecdntp.com',
'lf6-cdn-tos.bytecdntp.com',
'lf3-cdn-tos.bytecdntp.com',
'lf9-cdn-tos.bytecdntp.com',
'cdn.staticfile.org',
'npm.elemecdn.com',
].includes(url.host) &&
url.pathname.match(/\.(js|css|woff2|woff|ttf|cur)$/),
},
};
module.exports.getSpareUrls = (srcUrl) => {
if (srcUrl.startsWith('https://npm.elemecdn.com')) {
return {
timeout: 3000,
list: [
srcUrl,
`https://fastly.jsdelivr.net/${new URL(srcUrl).pathname}`,
],
};
}
};
module.exports.ejectValues = (hexo, rules) => {
return {
domain: {
prefix: 'const',
value: new URL(hexo.config.url).host,
},
};
};
module.exports.skipRequest = (request) => request.url.startsWith("https://i0.hdslb.com") ||
request.url.startsWith('https://meting.qjqq.cn') ||
request.url.startsWith('https://api.i-meto.com');主题标签
安装插件
npm i hexo-solitude-tag追番页面
安装插件
npm i hexo-bilibili-bangumi在 Hexo 配置文件底部加入以下配置
# 追番插件# https://github.com/HCLonely/hexo-bilibili-bangumibangumi: # 追番设置enable: truesource: bilipath:vmid: 527260354title: "追番列表"quote: "生命不息,追番不止!"show: 1lazyload: falseloading:showMyComment: falsepagination: falseextra_options:
top_img: false
lazyload:
enable: false本地搜索
安装插件,并修改主题和 Hexo 配置
npm i hexo-generator-search主题配置
# 大约在856和869行search:enable: truetype: local # local / algolia / docsearchtags:
# - Solitude
# - Hexo
···
# Local searchlocal:
preload: false
CDN: # url: search.xmlHexo配置
在最底下加入如下配置,具体如何填写参考插件仓库 README
search:path: search.xmlfield: postcontent: truetemplate:Algolia搜索
安装插件,并修改主题和 Hexo 配置
npm install hexo-algoliasearch --save主题配置
# 大约在856和864行search:enable: truetype: algolia # local / algolia / docsearchtags:
# - Solitude
# - Hexoalgolia:
hits:
per_page: 6Hexo配置
在最底下加入如下配置,具体如何填写参考插件仓库 README
记得配置 fields 参数的 title, permalink 和 content
algolia:
appId: "Z7A3XW"
apiKey: "12db1ad54372"
adminApiKey: "40321c7"
chunkSize: 5000
indexName: "my-hexo-blog"
fields:
- content:strip:truncate,0,500
- excerpt:strip
- gallery
- permalink
- photos
- slug
- tags
- title配置文章链接转数字或字母
npm install hexo-abbrlink --save _config.yml添加配置项:文章链接转数字或字母:abbrlink:
alg: crc32 #算法: crc16(default) and crc32
rep: hex #进制: dec(default) and hex: dec #输出进制:十进制和十六进制,默认为10进制。丨dec为十进制,hex为十六进制本文是原创文章,采用 CC BY-NC-SA 4.0 协议,完整转载请注明来自 云坠
评论
隐私政策
0/500
滚动到此处加载评论...


