本文将讲述我通过hexo以及github page建立本博客的过程
一、本地环境Ubuntu 20.04(wsl2) hexo: 5.4.0 nodejs: v13.14.0(使用过高版本会出现警告) npm: 6.14.4 切换node版本:1 2 sudo n rm 16.13.1 sudo n 13.14.0
二、初始化博客 三、选择合适的主题 从https://hexo.io/themes/ 中选择合适的主题,本博客使用主题: stun
克隆主题项目到本地仓库1 git clone https://github.com/liuyib/hexo-theme-stun.git themes/stun
安装pug引擎依赖1 npm install --save hexo-renderer-pug
将博客文件目录 下的_config.yml
中的theme内容改为 stun 四、基本内容的设置 1. 基本操作1 2 3 4 5 6 hexo new page filename hexo new page tags hexo new articlename hexo clean hexo s hexo d
2. 修改博客基本信息修改博客文件目录 下的_config.yml
文件中的title
,subtitle
,author
,language
等 修改博客文件目录 下的_config.yml
文件中的url为博客部署的地址(具体部署方法在后文) 3. 修改主题信息 stun主题配置官方文件
修改主题文件目录 下的_config.yml
文件 ||
左边为文件路径,右边为图标,具体不同图标选择见Font Awesome
1 2 3 4 5 6 7 8 9 10 11 12 13 menu: home: / || fas fa-home about: /about || fas fa-user calculate: javascript:; || fas fa-database message: /message/ || fas fa-comment history: /history/ || fa fa-history friends: /friend/ || fa fa-link submenu: calculate: archives: /archives/ || fas fa-folder-open categories: /categories/ || fas fa-layer-group tags: /tags/ || fas fa-tags
自己添加的页面需要在主题文件夹下/languages/zh-CN.yml
加入中文
(2) 修改网站favicon 生成头像见网站 Favicon 或者 websiteplanet(更多的支持)
1 2 3 favicon: small: /images/icons/favicon-16x16.png medium: /images/icons/favicon-32x32.png
这里选择主页启用头部图,文章页面不显示头部图
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 header: enable: true show_on: post: false height: 50 % bg_image: enable: true url: /images/icons/banner/saibo.jpg mask: enable: false opacity: 0.5 nav: height: 50px bg_color: "#333" scroll_down_icon: enable: true name: fas fa-angle-down animation: true
(4) 修改侧边栏内容1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 sidebar: enable: true position: right offsetTop: 20px horizon_line: false author: enable: true avatar: url: /images/icons/zoe.svg rounded: true opacity: 1 animation: shake motto: "每一天,每个季节都会过去, 然后就是新的开始" social: github: https://github.com/voyage-li/ || fab fa-github twitter: https://twitter.com/_voy4ge_ || fab fa-twitter email: mailto:lyh_0921@mail.ustc.edu.cn || fa fa-envelope qq: tencent://message?uin=923959605 || fab fa-qq
(5) 修改网页底部内容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 footer: bg_image: enable: false url: mask: enable: false opacity: 0.5 copyright: enable: true text: since: 2021 end: 2022 icon: enable: false name: fas fa-heart animation: false color: "#ff0000" powered: enable: false version: true theme: enable: false beian: enable: false icp: custom: enable: false text:
4. 更多设置 (1) 启用Valine评论1 2 3 4 5 6 7 8 9 10 11 12 13 valine: enable: true appid: appkey: notify: true verify: true placeholder: 留下一句评论再走吧(请使用markdown语法) avatar: monsterid meta: nick,mail pageSize: 10 visitor: true language: zh-cn enableQQ: true
(2) 启用katex渲染latex代码1 2 3 4 math: enable: true per_page: false engine: katex
1 2 3 4 5 6 7 8 9 10 11 npm un hexo-renderer-marked --save npm un hexo-renderer-kramed --save npm un hexo-renderer-pandoc --save npm un hexo-renderer-unified --save npm un hexo-renderer-markdown --save npm un hexo-renderer-markdown-it --save npm un hexo-math --save npm un hexo-inject --save npm i hexo-renderer-markdown-it-plus --save
(3) 启用Quicklink提前加载1 2 3 4 5 6 7 8 9 10 11 12 13 quicklink: enable: true home: true archive: true delay: true timeout: 10000 priority: true ignores: - /\/api\/?/ - uri => uri.includes('.xml') - uri => uri.includes('.zip') - (uri, el) => el.hasAttribute('nofollow') - (uri, el) => el.hasAttribute('noprefetch')
(4) 启用pjax平滑跳转1 2 3 4 5 6 7 8 9 10 11 12 13 pjax: enable: true elements: selectors: switches: switchesOptions: history: true scrollTo: 0 scrollRestoration: true cacheBust: false debug: false currentUrlFullReload: true timeout: 0
(5) 启用本地搜索 安装插件
1 npm install hexo-generator-search --save
在博客文件目录 下的.config.yml
加入
1 2 3 4 search: path: search.json field: post content: true
修改主题文件目录 下的.config.yml
1 2 local_search: enable: true
(6) 启用fancybox (7) 代码块1 2 3 4 codeblock: style: carbon highlight: light word_wrap: false
五、自主修改 1. 启用live2d看板娘 2. 添加告示栏 将原来的sidebar的div内部再加上一个div
sidebar.pug加入(渲染不了pug,有时间改 )1 2 3 4 5 6 7 8 9 - var notice_content=theme.sidebar.notice.content - var iconClass=theme.sidebar.notice.icon if page.notice !== false && theme.sidebar.notice.enable div.notice span.notice_banner i(class=iconClass) span.notice_banner=" NOTICE" br notice_text.notice_text=notice_content
主题文件目录 下的.config.yml
的sidebar内加入1 2 3 4 notice: icon: fa fa-bell enable: true content: "反复刷新界面可能导致部分js失
3. 深色模式不同banner图主题文件 加入图片地址styl文件直接加入样式1 2 3 4 5 6 7 8 9 10 .nightmode .header-banner { position : relative; z-index : 0 ; width : 100% ; height : 100% ; if (hexo-config('header.bg_image.enable' ) && hexo-config('header.bg_image.url' )) { background : url(hexo-config('header.bg_image.night_url' )) no-repeat center / cover; } }
六、部署安装依赖1 npm install hexo-deployer-git --save
博客文件目录 下.config.yml
加入1 2 3 4 deploy: type: git repository: git@github.com:voyage-li/voyage-li.github.io.git branch: main
部署1 hexo clean && hexo g && hexo d
七、后记