作者:dabing(王甜甜)
官方文档:https://hexo.io/zh-cn/docs/
shoka 主题:https://shoka.lostyu.me/
# 一、安装
- 安装 node.js 和 git
- 下载 Hexo
- 安装 node.js 和 git
首先确定自己的 node.js 和 git 是否已经安装了。用一下命令检测,未安装百度一下安装即可。
node -v | |
npm -v | |
git --version |
- 下载 Hexo
看官网:
npm install -g hexo-cli | |
hexo -v |
# 二、建站
- 初始化项目 hexo init
- 启动服务器 hexo server
- 初始化项目
先创建一个文件夹,myblog,进入终端
hexo init #初始化 hexo | |
# 没有实现创建文件夹可以用下面的命令 | |
hexo init myblog |
虽然有报错,但是看大概意思是一开始链接失败,后面重置了成功了。新建了 hexo 项目的文件目录长这样:
- 启动服务器
npm i # 其实不知道这个是安装什么依赖 | |
npm install hexo-deployer-git --save # 安装部署插件 | |
hexo server # 启动服务器。默认情况下,访问网址为: http://localhost:4000/。 |
这里可以不用安装依赖和插件,直接启动服务器也是可以的。
启动了服务器了,访问下地址:http://localhost:4000/
长这样,感觉不咋好看。到时候得换成那个少女粉的主题嘻嘻
# 三、部署到 GitHub
- 创建个仓库 dabing85.github.io
- 安装 hexo-deployer-git 部署插件
- 修改_config.yml 文件
- 代码部署到 git 并授权
- 访问:
dabing85.github.io
先部署到 github 吧,后面等备案了部署到自己的服务器上去嘻嘻。应该就是修改一下配置文件就可以了。
-
创建个仓库 dabing85.github.io - 这个 dabing85 要跟你的 github 账户名一致
-
安装 hexo-deployer-git 部署插件
刚刚就安装过了,就是这个命令:
npm install hexo-deployer-git --save # 安装插件 |
- 修改_config.yml 文件
部署推荐用 ssh 密钥的方式快一些。怎么生成公钥,可参考:https://blog.dabing.cool/java/git/
配过本机公钥就不用管了。
deploy: | |
type: git | |
repo: git@github.com:dabing85/dabing85.github.io.git | |
branch: main |
- 运行下面几个命令
# 三连,每次发布新文章的时候都要三连一下 | |
hexo clean | |
hexo g # 生成静态文件 | |
hexo d # 部署代码到 GitHub 上,之后会跳出 github 授权的框 |
- 访问:
dabing85.github.io
# 四、美化博客
- 安装需要的依赖插件
- 下载主题
- 修改 /_config.yml 配置切换主题
- 重新编译发布 hexo clean && hexo g && hexo deploy
- 访问
dabing85.github.io
- 修改对应的配置文件
看上这个少女粉的主题了,橙总介绍的:shoka.lostyu.me
文档说明:https://shoka.lostyu.me/computer-science/note/theme-shoka-doc/
基本配置: https://shoka.lostyu.me/computer-science/note/theme-shoka-doc/config/
页面配置: https://shoka.lostyu.me/computer-science/note/theme-shoka-doc/display/
依赖插件: https://shoka.lostyu.me/computer-science/note/theme-shoka-doc/dependents/
为了可视化,我直接用 idea 打开 mybolg 在 idea 的终端执行命令。也可以看看都添加了些什么文件。
# 1- 依赖插件安装
参考上方链接。
npm i hexo-renderer-multi-markdown-it --save | |
npm i hexo-autoprefixer --save | |
npm i hexo-algolia --save | |
npm i hexo-algoliasearch --save | |
npm i hexo-symbols-count-time --save | |
npm i hexo-feed --save |
对应的依赖配置直接复制博主文档里的内容到 themes/shoka/_config.yml
主题配置文件中。这个路径现在还没有,等会下载完主题就有了。
# 2- 下载主题
git clone https://github.com/amehime/hexo-theme-shoka.git ./themes/shoka |
下载完毕多了这么个文件夹。
让这个主题起效:
修改站点配置文件 /_config.yml
,把主题改为 shoka
theme: shoka |
重新编译部署:
hexo clean | |
hexo g | |
hexo d |
访问一下 https://dabing85.github.io/
呐,长这样:
# 3- 修改主题配置文件 /shoka/_config.yml
参考主题:https://shoka.lostyu.me/computer-science/note/theme-shoka-doc/config/
全局搜索 algolia 的配置参考:https://blog.csdn.net/m0_45234510/article/details/116885792 和
https://blog.csdn.net/qq_35479468/article/details/107335663
无后端评论系统 valine 的配置参考:https://valine.js.org/quickstart.html
要修改一些图片如头像,可以在 \themes\shoka\source\images
路径下修改,直接替换,要同名!!!
下面是我的配置文件给大家参考一些,也可能不够完善:其实就是改了一些你需要的效果,加上刚刚的插件配置
# Alternate site name | |
alternate: Dabing | |
open_graph: | |
#twitter_id: | |
#google_plus: | |
#fb_admins: | |
#fb_app_id: | |
# Assets | |
statics: / #/ #//cdn.jsdelivr.net/gh/username/RepositoryName@latest/ | |
css: css | |
js: js | |
images: images | |
# themes/shoka/source/images/*** | |
favicon: | |
apple_touch_icon: /apple-touch-icon.png | |
#safari_pinned_tab: /logo.svg | |
#android_manifest: /manifest.json | |
#ms_browserconfig: /browserconfig.xml | |
# Dark Mode | |
# By default, the page judges whether to turn on the dark mode according to the device settings or user selection | |
# if `true`, the page will be displayed directly as Dark Mode, unless the user makes another choice | |
# 夜间模式 | |
darkmode: false | |
# By default the page will automatically scroll to the last viewed position | |
# if `false`, automatic positioning will be turned off | |
# 自动定位 自动定位到上次浏览的位置 | |
auto_scroll: true | |
# Whether to show the loading cat | |
# 是否显示页面加载动漫 就是每次都看到的那个猫猫 | |
loader: | |
start: false # When entering the page | |
switch: false # When switching to another page | |
# click with Firework | |
# 页面特效 单击页面的烟花效果 | |
fireworks: | |
enable: true | |
color: | |
# - "rgba(255,182,185,.9)" | |
# - "rgba(250,227,217,.9)" | |
# - "rgba(187,222,214,.9)" | |
# - "rgba(138,198,209,.9)" | |
# 加载谷歌字体 | |
font: | |
enable: true | |
# Font options: | |
# `external: true` will load this font family from `host` above. | |
# `family: Times New Roman`. Without any quotes. | |
# `size: x.x`. Use `em` as unit. Default: 1 (16px) | |
# Global font settings used for all elements inside <body>. | |
global: | |
external: true | |
family: Mulish | |
size: | |
# Font settings for alternate title. | |
# 备用字体 | |
logo: | |
external: true | |
family: Fredericka the Great | |
size: 3.5 | |
# Font settings for site title. | |
# 站点字体 | |
title: | |
external: true | |
family: Noto Serif JP | |
size: 2.5 | |
# Font settings for headlines (<h1> to <h6>). | |
headings: | |
external: true | |
family: Noto Serif SC | |
size: | |
# Font settings for posts. | |
posts: | |
external: true | |
family: | |
# Font settings for <code> and code blocks. | |
codes: | |
external: true | |
family: Inconsolata | |
# project of https://www.iconfont.cn/ | |
# //at.alicdn.com/t/font_1832207_c8i9n1ulxlt.css => 1832207_c8i9n1ulxlt | |
iconfont: "1832207_igi8uaupcus" | |
# 菜单 | |
menu: | |
首页: / || home | |
关于: /about/ || user | |
文章: | |
default: / || feather | |
归档: /archives/ || list-alt | |
分类: /categories/ || th | |
标签: /tags/ || tags | |
友链: /friends/ || heart | |
# links: /links/ || magic | |
# Social Links | |
# Usage: `Key: permalink || icon || color` | |
# Key is the link label showing to end users. | |
# Value before `||` delimiter is the target permalink, | |
# secend value is the name of Font icon. | |
social: | |
github: https://github.com/dabing85 || github || "#191717" | |
#google: https://plus.google.com/yourname || google | |
#twitter: https://twitter.com/yourname || twitter || "#00aff0" | |
#zhihu: https://www.zhihu.com/people/yourname || zhihu || "#1e88e5" | |
#music: https://music.163.com/#/user/home?id=yourid || cloud-music || "#e60026" | |
#weibo: https://weibo.com/yourname || weibo || "#ea716e" | |
#about: https://about.me/yourname || address-card || "#3b5998" | |
#email: mailto:yourname@mail.com || envelope || "#55acd5" | |
#facebook: https://www.facebook.com/yourname || facebook | |
#stackoverflow: https://stackoverflow.com/yourname || stack-overflow | |
#youtube: https://youtube.com/yourname || youtube | |
#instagram: https://instagram.com/yourname || instagram | |
#skype: skype:yourname?call|chat || skype | |
#douban: https://www.douban.com/people/yourname/ || douban | |
sidebar: | |
# Sidebar Position. | |
# position: left | |
position: right | |
# Replace the default avatar image and set the url here. | |
avatar: avatar.jpg | |
widgets: | |
# if true, will show random posts | |
# 显示随机文章 | |
random_posts: true | |
# if true, will show recent comments | |
# 显示最近评论 | |
recent_comments: true | |
footer: | |
# Specify the date when the site was setup. If not defined, current year will be used. | |
# 页尾全站统计局 | |
since: 2010 | |
icon: | |
name: sakura rotate | |
# Change the color of icon, using Hex Code. | |
color: "#ffc0cb" | |
# Dependencies: https://github.com/theme-next/hexo-symbols-count-time | |
count: false | |
powered: true | |
# 文章界面统计 | |
post: | |
# Dependencies: https://github.com/theme-next/hexo-symbols-count-time | |
count: true | |
# 奖励 | |
# Reward (Donate) | |
reward: | |
# If true, reward will be displayed in every article by default. | |
enable: true | |
account: | |
wechatpay: /wechatpay.png | |
# alipay: /alipay.png | |
# paypal: /paypal.png | |
# TagCloud settings for tags page. | |
tagcloud: | |
# All values below are same as default, change them by yourself. | |
min: 16 # Minimun font size in px | |
max: 22 # Maxium font size in px | |
start: "#72cecf" # Start color (hex, rgba, hsla or color keywords) | |
end: "#ffbac3" # End color (hex, rgba, hsla or color keywords) | |
amount: 200 # Amount of tags, change it if you have more than 200 tags | |
# --------------------------------------------------------------- | |
# Third Party Plugins & Services Settings | |
# --------------------------------------------------------------- | |
# Creative Commons 4.0 International License. | |
# See: https://creativecommons.org/share-your-work/licensing-types-examples | |
# Available values of license: by | by-nc | by-nc-nd | by-nc-sa | by-nd | by-sa | zero | |
# You can set a language value if you prefer a translated version of CC license, e.g. deed.zh | |
# CC licenses are available in 39 languages, you can find the specific and correct abbreviation you need on https://creativecommons.org | |
creative_commons: | |
license: by-nc-sa | |
language: zh-CN # deed.zh | |
# Comments | |
# Valine | |
# For more information: https://github.com/amehime/MiniValine | |
# 无后端评论系统 valine 的配置参考:https://valine.js.org/quickstart.html | |
valine: | |
appId: # 配置你的 appId | |
appKey: # 配置你的 appKey | |
placeholder: ヽ(○´∀`)ノ♪ # Comment box placeholder | |
avatar: retro # Gravatar style : mp, identicon, monsterid, wavatar, robohash, retro | |
pageSize: 10 # Pagination size | |
lang: zh-CN | |
visitor: true # Article reading statistic 文章阅读量统计 | |
NoRecordIP: false # Whether to record the commenter IP | |
serverURLs: # When the custom domain name is enabled, fill it in here (it will be detected automatically by default, no need to fill in) | |
powerMode: true | |
tagMeta: | |
visitor: 新朋友 | |
master: 博客作者 | |
friend: 小伙伴 | |
investor: 金主粑粑 | |
tagColor: | |
master: "var(--color-orange)" | |
friend: "var(--color-aqua)" | |
investor: "var(--color-pink)" | |
tagMember: | |
master: | |
- 0fcd1a19626a9a93e8eca7dc65c375fb | |
#(这是博主的 md5 值,别人评论之后可以在 leanCloud 看到邮箱 MD5 值) | |
# - hash of master@email.com | |
# - hash of master2@email.com | |
friend: | |
# - hash of friend1@email.com | |
investor: | |
# - hash of investor1@email.com | |
# bgm 背景音乐 | |
audio: | |
- title: 列表1 | |
list: | |
- https://music.163.com/#/playlist?id=2943811283 | |
- https://music.163.com/#/playlist?id=2297706586 | |
- title: 列表2 | |
list: | |
- https://music.163.com/#/playlist?id=2031842656 | |
# random image api | |
# 随机图库 | |
image_server: # "https://acg.xydwz.cn/api/api.php" | |
# Algolia Search | |
# For more information: https://www.algolia.com | |
search: | |
hits: | |
per_page: 10 | |
# Dependencies: https://github.com/amehime/hexo-renderer-multi-markdown-it | |
pangu: false | |
# Quicklink Support | |
# For more information: https://github.com/GoogleChromeLabs/quicklink | |
quicklink: | |
# Custom a time in milliseconds by which the browser must execute prefetching. | |
timeout: 3000 | |
# Default (true) will attempt to use the fetch() API if supported (rather than link[rel=prefetch]). | |
priority: true | |
# For more flexibility you can add some patterns (RegExp, Function, or Array) to ignores. | |
# See: https://github.com/GoogleChromeLabs/quicklink#custom-ignore-patterns | |
ignores: | |
# --------------------------------------------------------------- | |
# analytics & SEO Settings | |
# --------------------------------------------------------------- | |
baidu_analytics: # <app_id> | |
# Disable Baidu transformation on mobile devices. | |
disable_baidu_transformation: true | |
# Automatically add external URL with Base64 encrypt & decrypt. | |
exturl: true | |
# Google Webmaster tools verification. | |
# See: https://www.google.com/webmasters | |
google_site_verification: | |
# Bing Webmaster tools verification. | |
# See: https://www.bing.com/webmaster | |
bing_site_verification: | |
# Yandex Webmaster tools verification. | |
# See: https://webmaster.yandex.ru | |
yandex_site_verification: | |
# Baidu Webmaster tools verification. | |
# See: https://ziyuan.baidu.com/site | |
baidu_site_verification: | |
# Enable baidu push so that the blog will push the url to baidu automatically which is very helpful for SEO. | |
baidu_push: true | |
# 渲染 md 文件 | |
markdown: | |
render: # 渲染器设置 | |
html: false # 过滤 HTML 标签 | |
xhtmlOut: true # 使用 '/' 来闭合单标签 (比如 <br />)。 | |
breaks: true # 转换段落里的 '\n' 到 <br>。 | |
linkify: true # 将类似 URL 的文本自动转换为链接。 | |
typographer: | |
quotes: '“”‘’' | |
plugins: # markdown-it 插件设置 | |
- plugin: | |
name: markdown-it-toc-and-anchor | |
enable: true | |
options: # 文章目录以及锚点应用的 class 名称,shoka 主题必须设置成这样 | |
tocClassName: 'toc' | |
anchorClassName: 'anchor' | |
- plugin: | |
name: markdown-it-multimd-table | |
enable: true | |
options: | |
multiline: true | |
rowspan: true | |
headerless: true | |
- plugin: | |
name: ./markdown-it-furigana | |
enable: true | |
options: | |
fallbackParens: "()" | |
- plugin: | |
name: ./markdown-it-spoiler | |
enable: true | |
options: | |
title: "你知道得太多了" | |
# minify 配置,压缩 css/js/html | |
minify: | |
html: | |
enable: true | |
exclude: # 排除 hexo-feed 用到的模板文件 | |
- '**/json.ejs' | |
- '**/atom.ejs' | |
- '**/rss.ejs' | |
css: | |
enable: true | |
exclude: | |
- '**/*.min.css' | |
js: | |
enable: true | |
mangle: | |
toplevel: true | |
output: | |
compress: | |
exclude: | |
- '**/*.min.js' | |
# 代码高亮 | |
highlight: | |
enable: false | |
prismjs: | |
enable: false | |
autoprefixer: | |
exclude: | |
- '*.min.css' | |
keywords: java,git,springcloud #站点关键词,用 “,” 分隔 | |
feed: | |
limit: 20 | |
order_by: "-date" | |
tag_dir: false | |
category_dir: false | |
rss: | |
enable: true | |
template: "themes/shoka/layout/_alternate/rss.ejs" | |
output: "rss.xml" | |
atom: | |
enable: true | |
template: "themes/shoka/layout/_alternate/atom.ejs" | |
output: "atom.xml" | |
jsonFeed: | |
enable: true | |
template: "themes/shoka/layout/_alternate/json.ejs" | |
output: "feed.json" | |
#! --------------------------------------------------------------- | |
#! DO NOT EDIT THE FOLLOWING `vendors` SETTINGS | |
#! UNLESS YOU KNOW WHAT YOU ARE DOING | |
#! Script dependencies will be combined with jsDelivr (cdn.jsdelivr.net) | |
#! --------------------------------------------------------------- | |
vendors: | |
css: | |
katex: npm/katex@0.12.0/dist/katex.min.css | |
comment: css/comment.css | |
fancybox: combine/npm/@fancyapps/fancybox@3.5.7/dist/jquery.fancybox.min.css,npm/justifiedGallery@3.8.1/dist/css/justifiedGallery.min.css | |
js: | |
pace: npm/pace-js@1.0.2/pace.min.js | |
pjax: npm/pjax@0.2.8/pjax.min.js | |
fetch: npm/whatwg-fetch@3.4.0/dist/fetch.umd.min.js | |
anime: npm/animejs@3.2.0/lib/anime.min.js | |
algolia: npm/algoliasearch@4/dist/algoliasearch-lite.umd.js | |
instantsearch: npm/instantsearch.js@4/dist/instantsearch.production.min.js | |
lazyload: npm/lozad@1/dist/lozad.min.js | |
quicklink: npm/quicklink@2/dist/quicklink.umd.js | |
fancybox: combine/npm/jquery@3.5.1/dist/jquery.min.js,npm/@fancyapps/fancybox@3.5.7/dist/jquery.fancybox.min.js,npm/justifiedGallery@3.8.1/dist/js/jquery.justifiedGallery.min.js | |
valine: gh/amehime/MiniValine@4.2.2-beta10/dist/MiniValine.min.js | |
copy_tex: npm/katex@0.12.0/dist/contrib/copy-tex.min.js | |
chart: npm/frappe-charts@1.5.0/dist/frappe-charts.min.iife.min.js |
# 4 - 修改全局配置文件 _config.yml
参考官网:https://hexo.io/zh-cn/docs/configuration
要说明一下的分类和标签的配置:
基本照着官网来就好,没啥要改的。我的给参考一下。
# Hexo Configuration | |
## Docs: https://hexo.io/docs/configuration.html | |
## Source: https://github.com/hexojs/hexo/ | |
# Site | |
title: | |
subtitle: '不在能知,乃在能行' | |
description: '欢迎来到大冰的笔记空间~这里主要会记录编程学习笔记🌸' | |
keywords: | |
author: Dabing-He | |
language: zh-CN | |
timezone: '' | |
# URL | |
## Set your site url here. For example, if you use GitHub Page, set url as 'https://username.github.io/project' | |
url: https://blog.dabing.cool/ | |
permalink: :title/ #:year/:month/:day/:title/ | |
permalink_defaults: | |
pretty_urls: | |
trailing_index: true # Set to false to remove trailing 'index.html' from permalinks | |
trailing_html: true # Set to false to remove trailing '.html' from permalinks | |
# Directory | |
source_dir: source | |
public_dir: public | |
tag_dir: tags | |
archive_dir: archives | |
category_dir: categories | |
code_dir: downloads/code | |
i18n_dir: :lang | |
skip_render: | |
# Writing | |
new_post_name: :title.md # File name of new posts | |
default_layout: post | |
titlecase: false # Transform title into titlecase | |
external_link: | |
enable: true # Open external links in new tab | |
field: site # Apply to the whole site | |
exclude: '' | |
filename_case: 0 | |
render_drafts: false | |
post_asset_folder: false | |
relative_link: false | |
future: true | |
highlight: | |
enable: false | |
line_number: true | |
auto_detect: true | |
tab_replace: '' | |
wrap: true | |
hljs: false | |
prismjs: | |
enable: false | |
preprocess: true | |
line_number: true | |
tab_replace: '' | |
# Home page setting | |
# path: Root path for your blogs index page. (default = '') | |
# per_page: Posts displayed per page. (0 = disable pagination) | |
# order_by: Posts order. (Order by date descending by default) | |
index_generator: | |
path: '' | |
per_page: 10 | |
order_by: -date | |
# Category & Tag | |
# 这里配置分类和标签 | |
default_category: uncategorized | |
category_map: # edit for Theme.shoka | |
Java: java | |
Hexo: hexo | |
进阶: javamore | |
缓存: cache | |
微服务: springcloud | |
算法: algorithm | |
算法-新手: algorithm1 | |
算法-基础: algorithm2 | |
随便记: diary | |
tag_map: | |
# Metadata elements | |
## https://developer.mozilla.org/en-US/docs/Web/HTML/Element/meta | |
meta_generator: true | |
# Date / Time format | |
## Hexo uses Moment.js to parse and display date | |
## You can customize the date format as defined in | |
## http://momentjs.com/docs/#/displaying/format/ | |
date_format: YYYY-MM-DD | |
time_format: HH:mm:ss | |
## updated_option supports 'mtime', 'date', 'empty' | |
updated_option: 'mtime' | |
# Pagination | |
## Set per_page to 0 to disable pagination | |
per_page: 10 | |
pagination_dir: page | |
# Include / Exclude file(s) | |
## include:/exclude: options only apply to the 'source/' folder | |
include: | |
exclude: | |
ignore: | |
# 全局搜索 | |
algolia: | |
appId: #Your appId | |
apiKey: #Your apiKey | |
adminApiKey: #Your adminApiKey | |
chunkSize: 5000 | |
indexName: "dabing" #"shoka" | |
fields: | |
- title | |
- path | |
- categories | |
- content:strip:truncate,0,2000 | |
- gallery | |
- photos | |
- tags | |
# Extensions | |
## Plugins: https://hexo.io/plugins/ | |
## Themes: https://hexo.io/themes/ | |
theme: shoka | |
# Deployment | |
## Docs: https://hexo.io/docs/one-command-deployment | |
deploy: | |
type: git | |
repo: git@github.com:dabing85/dabing85.github.io.git | |
branch: main |
再来一遍三连 hexo clean 、hexo generate、hexo deploy 即可
# 五、其他
# 1- 要写一篇文章:
如我要写一篇文章,我就这么写:写在 /source/_post/
目录下,可以按照分类,如我 hexo 分类,就写在 /source/_post/hexo/
目录下即可
--- | |
title: 前缀和-新手 | |
date: 2022-09-01 10:00:00 | |
categories: | |
- [算法, 算法-新手] | |
tags: | |
- 算法 | |
--- | |
这里开始正文。。。。。 | |
- [算法, 算法-新手] 表示在算法下的子目录,算法-新手下 | |
- Java 表示在java分类下 |
# 2 - 分类
在你的根目录 /source/_post/hexo/
下放一张该分类的封面图,它就会自动在首页显示这个分类了。
# 3- jsdelivr 被墙
我在 shoka 评论区找到的,评论内容如下:
您好,我这边大概去了解了一下,这个问题应该是与 jsdelivr 被墙有关,可参考 关于 jsdeliver 在国内的 ICP 许可证被吊销 #65 里的讨论,以及 jsDelivr 静态文件 CDN 加速失效之后解决方案 这一博客的评论区。我目前采取的解决方案是:
- 修改 \themes\shoka\source\js_app 路径下的 utils.js 文件:将 cdn.jsdelivr.net 替换成 fastly.jsdelivr.net
- 修改 \themes\shoka\scripts\helpers 路径下的 asset.js 文件:将 cdn.jsdelivr.net 替换成 fastly.jsdelivr.net
- 修改 shoka 主题 _config.yml 文件(如果没有在博客根目录新增 _config.shoka.yml 文件的话)中的 statics 设置,输入完整的 fastly.jsdelivr 静态文件网址,即,设置为 https://fastly.jsdelivr.net/gh/ 你的 github 用户名 / 博客对应的仓库名 @latest/ ,例如我的设置:https://fastly.jsdelivr.net/gh/jiankychen/jiankychen.github.io@latest/ (注:我不太确定 \themes\shoka\source\js_app 路径下 global.js 文件中的 var statics = CONFIG.statics.indexOf (‘//‘) > 0 ? CONFIG.statics : CONFIG.root 这一行代码的逻辑,为了确保我们在 _config.yml 中设置的 statics 能够奏效,所以我在设置 _config.yml 的 statics 时加上了 https: 这一前缀,以确保 CONFIG.statics.indexOf (‘//‘) > 0 为 true )
- 如果您配置了 valine 评论系统,则还需要将 https://fastly.jsdelivr.net/gh/amehime/MiniValine@4.2.2-beta10/dist/ 中的 MiniValine.min.js 下载到本地并做一定的修改,同时修改 shoka 主题 _config.yml 文件的 valine: js/MiniValine.min.js 这一项设置,这一部分工作我暂时也还没能解决(目前我的 valine 评论系统仍需翻墙才能加载出来),所以无法为您提供更详细的修改建议。
附注:jsdelivr 缓存刷新较慢,据说可能要 24 小时左右,所以,按照上述操作进行修改后,可能需耐心等待 jsdelivr 缓存刷新后才能 正常访问博客 ,或者也可以查找有关 刷新 jsdelivr 缓存 的资料进一步解决。
# 六、域名解析 github page
- 买域名 ✔
- 域名备案 ✔
- 解析域名 见下
- 到 github page 设置自定义域名 见下
** 第三步,域名解析:** 记录类型 CNAME,记录值写:你的 github 名.github.io
** 第四步:** 到 github 找到 你的github名.github.io
仓库,setting,找到 github pages,添加上你的域名即可。
等个十几分钟就去访问下你的博客看看咯。我的 blog.dabing.cool
# 七、使用 Github Action 自动部署 hexo 到 GitHub pages
这里默认你把上面的都做好了~
1、github 创建一个私人仓库,用于存放 hexo 的源代码 – 配置私钥
2、github 上的 youname.github.io 是存放 hexo 的静态网页文件 – 配置公钥
3、配置工作流:.github/workflows/deploy.yml
我踩太多坑了,可以参考这个做:利用 GitHub Actions 自动部署 Hexo 博客 全自动运行
我的配置文件这里贴一下:
# Action 的名字 | |
name: Hexo Auto Deploy | |
on: | |
# 触发条件 1:main 分支收到 push 后执行任务。 | |
push: | |
branches: | |
- main | |
# 触发条件 2:手动按钮 | |
workflow_dispatch: | |
# 这里放环境变量,需要替换成你自己的 | |
env: | |
# Hexo 编译后使用此 git 用户部署到 github 仓库 | |
GIT_USER: dabing85 | |
# Hexo 编译后使用此 git 邮箱部署到 github 仓库 | |
GIT_EMAIL: 2261617090@qq.com | |
# Hexo 编译后要部署的 github 仓库 | |
GIT_DEPLOY_REPO: dabing85/dabing85.github.io | |
# Hexo 编译后要部署到的分支 | |
GIT_DEPLOY_BRANCH: main | |
# # Hexo 编译后使用此 gitee 用户部署到 gitee 仓库 | |
# GITEE_USER: wbsu2003 | |
# # Hexo 编译后要部署的 gitee 仓库 | |
# GITEE_DEPLOY_REPO: wbsu2003/wbsu2003 | |
# # Hexo 编译后要部署到的分支 | |
# GITEE_DEPLOY_BRANCH: master | |
# 注意替换为你的 GitHub 源仓库地址 | |
GIT_SOURCE_REPO: git@github.com:dabing85/dabing85.github.io.git | |
# 注意替换为你的 Gitee 目标仓库地址 | |
# GITEE_DESTINATION_REPO: git@gitee.com:wbsu2003/wbsu2003.git | |
jobs: | |
build: | |
name: Build on node $<!--swig0--> and $<!--swig1--> | |
runs-on: ubuntu-latest | |
if: github.event.repository.owner.id == github.event.sender.id | |
strategy: | |
matrix: | |
os: [ubuntu-18.04] | |
node_version: [12.x] | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v2 | |
- name: Checkout deploy repo | |
uses: actions/checkout@v2 | |
with: | |
repository: $<!--swig2--> | |
ref: $ | |
path: .deploy_git | |
- name: Use Node.js $<!--swig4--> | |
uses: actions/setup-node@v1 | |
with: | |
node-version: $ | |
- name: Configuration environment | |
env: | |
HEXO_DEPLOY_KEY: $<!--swig6--> | |
run: | | |
sudo timedatectl set-timezone "Asia/Shanghai" | |
mkdir -p ~/.ssh/ | |
echo "$HEXO_DEPLOY_KEY" > ~/.ssh/id_rsa | |
chmod 600 ~/.ssh/id_rsa | |
ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts | |
git config --global user.name "$GIT_USER" | |
git config --global user.email "$GIT_EMAIL" | |
- name: Install dependencies | |
run: | | |
npm install hexo-cli -g | |
npm install | |
# 根据你安装的组件进行安装 | |
# npm i hexo-renderer-multi-markdown-it --save | |
# npm i hexo-autoprefixer --save | |
# npm i hexo-algolia --save | |
# npm i hexo-algoliasearch --save | |
# npm i hexo-symbols-count-time --save | |
# npm i hexo-feed --save --egacy-peer-deps | |
# hexo-deployer-git --save | |
# 复制中文语言包,解决菜单英文的问题 | |
# cp zh-CN.yml node_modules/hexo-theme-next/languages/ | |
- name: Deploy hexo | |
run: | | |
hexo clean | |
hexo generate | |
hexo deploy | |
# 以下为发布到 gitee | |
# - name: Sync to Gitee | |
# uses: wearerequired/git-mirror-action@master | |
# env: | |
# # 直接使用了 HEXO_DEPLOY_PRI | |
# SSH_PRIVATE_KEY: $ | |
# with: | |
# # GitHub 源仓库地址 | |
# source-repo: $ | |
# # Gitee 目标仓库地址 | |
# destination-repo: $ | |
# - name: Build Gitee Pages | |
# uses: yanglbme/gitee-pages-action@main | |
# with: | |
# # 你的 Gitee 用户名 | |
# gitee-username: $ | |
# # 注意在 Settings->Secrets 配置 GITEE_PASSWORD | |
# gitee-password: $ | |
# # 你的 Gitee 仓库,仓库名严格区分大小写,请准确填写,否则会出错 | |
# gitee-repo: $ | |
# # 要部署的分支,默认是 master,若是其他分支,则需要指定(指定的分支必须存在) | |
# branch: $ |
# 八、一些坑(不全)
遇到的坑也没全填平,这里总结一下一些坑:
- 问题: Hexo 使用 Github Actions 自动发布至 Github Pages 时,生成的 html 页面空白,没有 css/js 等文件。
原因: 由于主题是 git clone 下来的,主题目录下生成了 .git 目录,导致和 hexo 根目录下 .git 冲突了,commit 时没有把主题 push 上去导致的。
解决办法: 删掉主题下的.git 文件夹,重新提交,目的是把 next 主题文件夹提交上去(删掉.git 文件夹后 git commit 依然没有提交上,需要把 next 文件夹剪切出来后 git add&&git commit &&git push 后,再把 next 文件夹拷贝回来,再 git add&&git commit &&git push 就可以提交成功了)
注:这里如果用 idea 的可视化按键不行(反正我的不行)。就在 idea 终端打命令。按着上面的来就行。我这里做一下记录。
git status # 查看有没有未添加的文件夹, | |
git add themes/shoka/ # shoka 是我的主题 | |
git commit -m "shoka主题内容" | |
git remote add origin git@github.com:dabing85/hexoBlog.git # 我是重新搭建的,这里才关联远程仓库,origin 是远程仓库名字 | |
git branch -M main | |
git push -u origin main |
- 问题: 安装插件依赖失败,说啥解析失败,npm ERR! code ERESOLVE
解决: 后面添加 --egacy-peer-deps
参考链接: https://blog.csdn.net/m0_51969330/article/details/119186416
- 问题:npm install error (code EBADPLATFORM) 表示没有平台支持安装 fsevents
解决:npm install error (code EBADPLATFORM)
这里我是只删除了 package-lock.json 就行了,但是还是做了警告。
- 问题:自动部署后,github pages 上的自定义域名也会被抹掉.
解决: https://blog.csdn.net/fake_hydra/article/details/82414965
即:在 source 目录下建一个 CNAME 文件,没有后缀,里面写你的域名即可。
# 九、部署到服务器
参考链接:将 Hexo 搭建到自己的服务器上
服务器(Linux)我是全按照上面的博客来的,没啥问题。
到客户端(Windows)我是新建了一个 hexoBlog 文件夹,但是内容全部复制以前 github 的源码,所以 github 上的还是起效的。
直接复制有些要注意的是:
-
最好删除.git 文件(这里的.git 是原来 github 远程仓库的)
-
.idea 文件夹的内容有些文件需要改,因为里面记的是原来项目的模块
下面几个文件内容的项目名改成现在的,不放心可以每个都看一下替换一下。
# 参考
GitHub Actions 部署 Hexo 小结
用 GitHub Actions 自动部署 Hexo
利用 GitHub Actions 自动部署 Hexo 博客 全自动运行
将 Hexo 搭建到自己的服务器上