background

hexo搭建

安装git

https://git-scm.com/downloads

安装nodejs

https://nodejs.org/en/

换源

npm config set registry http://registry.npm.taobao.org/

安装(找一个文件夹存放博客的文件,右键-open git bash)

npm install hexo-cli -g
hexo init
hexo s

主题美化

安装各种依赖环境,我这里就直接安所有的包了,直接替换掉package.json里的内容,然后在目录下npm install

{
"name": "hexo-site",
"version": "0.0.0",
"private": true,
"scripts": {
"build": "hexo generate",
"clean": "hexo clean",
"deploy": "hexo deploy",
"server": "hexo server"
},
"hexo": {
"version": "7.0.0"
},
"dependencies": {
"@mapbox/node-pre-gyp": "^1.0.11",
"add": "^2.0.6",
"hexo": "^7.0.0",
"hexo-asset-image": "^1.0.0",
"hexo-asset-img": "file:hexo-asset-img",
"hexo-butterfly-extjs": "^1.4.7",
"hexo-deployer-git": "^4.0.0",
"hexo-generator-archive": "^2.0.0",
"hexo-generator-category": "^2.0.0",
"hexo-generator-feed": "^3.0.0",
"hexo-generator-index": "^3.0.0",
"hexo-generator-json-content": "^4.2.3",
"hexo-generator-search": "^2.4.3",
"hexo-generator-tag": "^2.0.0",
"hexo-lazyload-image": "^1.0.13",
"hexo-renderer-ejs": "^2.0.0",
"hexo-renderer-less": "^4.0.0",
"hexo-renderer-marked": "^6.0.0",
"hexo-renderer-pug": "^3.0.0",
"hexo-renderer-stylus": "^2.1.0",
"hexo-server": "^3.0.0",
"hexo-theme-butterfly": "^4.10.0",
"hexo-theme-landscape": "^1.0.0",
"hexo-wordcount": "^6.0.1",
"or": "^0.2.0",
"yarn": "^1.22.21"
}
}

安装我喜欢的主题butterfly

git clone -b master https://github.com/jerryc127/hexo-theme-butterfly.git themes/butterfly

卡的话用国内的下

git clone -b master https://gitee.com/immyw/hexo-theme-butterfly.git themes/butterfly
# Hexo Configuration
## Docs: https://hexo.io/docs/configuration.html
## Source: https://github.com/hexojs/hexo/

# Site
title: c0ll4r
#subtitle: ''
description: ''
keywords:
author: c0ll4r
language: zh-CN
timezone: Asia/Shanghai

# URL
## Set your site url here. For example, if you use GitHub Page, set url as 'https://username.github.io/project'
url: http://example.com
permalink: posts/:abbrlink.html
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:

highlight_theme: mac # darker / pale night / light / ocean / mac / mac light / false 代码主题
highlight_copy: true # 复制按钮
highlight_lang: false # 是否显示代码语言
highlight_shrink: false # true: 代码块默认不展开 / false: 代码块默认展开 | none: 展开并隐藏折叠按钮
highlight_height_limit: false # unit: px
code_word_wrap: true #代码自动换行,关闭滚动条

marked:
prependRoot: true
postAsset: true

# 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: true
relative_link: false
future: true
highlight:
enable: false
line_number: false
auto_detect: false
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:
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:

# Extensions
## Plugins: https://hexo.io/plugins/
## Themes: https://hexo.io/themes/
theme: butterfly

# Deployment
## Docs: https://hexo.io/docs/one-command-deployment
deploy:
type: ''


menu:
主页: / || fas fa-home
分类 || fa fa-graduation-cap:
web安全: /tags/web || fa fa-tags
poc: /tags/poc || fa fa-tags
cry: /tags/cry || fa fa-tags
misc: /tags/misc || fa fa-tags
re: /tags/re || fa fa-tags

生活 || fas fa-list:
分享: / || fa fa-comments-o
相册: / || fa fa-camera-retro
音乐: / || fa fa-music
影视: / || fas fa-video
友链: /link || fa fa-link
留言板: / || fa fa-paper-plane
#留言板: /messageboard/ || fa fa-paper-plane
关于笔者: / || fas fa-heart

# Local search
local_search:
enable: true
labels:
input_placeholder: Search for Posts
hits_empty: "We didn't find any results for the search: ${query}" # 如果没有查到内容相关内容显示

# the subtitle on homepage (主頁subtitle)
subtitle:
enable: true
# Typewriter Effect (开启打字效果)
effect: true
# loop (循環打字)
loop: true
# source調用第三方服務
# source: false 關閉調用
# source: 1 調用搏天api的隨機語錄(簡體)
# source: 2 調用一言網的一句話(簡體)
# source: 3 調用一句網(簡體)
# source: 4 調用今日詩詞(簡體)
# subtitle 會先顯示 source , 再顯示 sub 的內容
source: false
# 如果有英文逗号' , ',请使用转义字元 ,
# 如果有英文双引号' " ',请使用转义字元 "
# 开头不允許转义字元,如需要,请把整個句子用双引号包住
# 如果关闭打字效果,subtitle只会现示sub的第一行文字
sub:
- 十八岁的你是我整个青春
- 你永远在我的青春里拔得头筹

avatar:
img: /img/avatar.jpg #图片路径
effect: false #头像会一直转圈

# Favicon(网站图)
favicon: /img/favicon.png
#主页封面
index_img: /img/background.jpg
archive_img: /img/fu.jpg
#图片大图查看
medium_zoom: false
fancybox: true

#图片懒加载(一直转圈圈)
lazyload:
enable: true
loadingImg: /img/friend_404.gif

# Replace Broken Images (替換無法顯示的圖片)
error_img:
flink: /img/404.jpg
post_page: /img/404.jpg

post_copyright:
enable: false
decode: true
license: CC BY-NC-SA 4.0
license_url: https://creativecommons.org/licenses/by-nc-sa/4.0/

aside:
enable: true
hide: false
button: true
mobile: true # display on mobile
position: right # left or right

card_announcement:
enable: false
content: iojiojiojio #修改公告栏信息


# toc (目錄)
toc:
post: true
page: false
number: false
expand: true # 是否展开
style_simple: false # for post
scroll_percent: true

# Mouse click effects: fireworks (鼠标点击效果:萤火特效)
fireworks:
enable: false
zIndex: 9999 # -1 or 9999
mobile: false

# Mouse click effects: Heart symbol (鼠标点击效果: 爱心)
click_heart:
enable: true
mobile: false

# Mouse click effects: words (鼠标点击效果: 文字)
ClickShowText:
enable: false
text:
- 富强
- 民主
- 文明
- 和谐
- 平等
- 公正
- 法治
- 爱国
- 敬业
- 诚信
- 友善
fontSize: 15px
random: true
mobile: true

# Typewriter Effect (打字效果)
# https://github.com/disjukr/activate-power-mode
activate_power_mode:
enable: true
colorful: true # open particle animation (冒光特效)
shake: true # open shake (抖动特效)
mobile: true

# Background effects (背景特效)
# canvas_ribbon (静止彩带)
# See: https://github.com/hustcc/ribbon.js
canvas_ribbon:
enable: false
size: 150
alpha: 0.6
zIndex: -1
click_to_change: false
mobile: false
# Fluttering Ribbon (动态彩带)
canvas_fluttering_ribbon:
enable: false
mobile: false
#星空特效
# canvas_nest
# https://github.com/hustcc/canvas-nest.js
canvas_nest:
enable: true
color: '0,0,255' #color of lines, default: '0,0,0'; RGB values: (R,G,B).(note: use ',' to separate.)
opacity: 0.7 # the opacity of line (0~1), default: 0.5.
zIndex: -1 # z-index property of the background, default: -1.
count: 99 # the number of lines, default: 99.
mobile: false

# wordcount (字數統計)
wordcount:
enable: true
post_wordcount: true
min2read: true
total_wordcount: true

配置本地js,使用第三方的js总感觉怪怪的,不咋靠谱。

在themes/butterfly的_config.yml里配置

third_party_provider: local

然后安js

npm install hexo-butterfly-extjs

git自动化更新

纯静态的很强,只需要把public文件夹下的文件放到web路径里就可以运行了。但每次更新文章都传一个压缩包上去然后再解压,不是个方便的办法,于是就使用git一键更新。

0x01安装中间件

我图省事,直接用宝塔装Nginx了

https://www.bt.cn/new/download.html

image-20231124150342838

0x02配置git

首先要有git

git --version

这里要创建一个git用户,然后授权之类的,我图省事直接用root用户了

1.创建仓库

找一个干净的地方创建个目录,然后建仓库

mkdir /root/hexo
cd /root/hexo
git init --bare hexo.git

2.使用hooks实现自动部署

在/root/hexo/hexo.git/hooks下新建post-receive文件

#!/bin/sh
git --work-tree=/www/wwwroot/hexo --git-dir=/root/hexo/hexo.git checkout -f

这里的/www/wwwroot/hexo是网站的目录,/root/hexo/hexo.git是仓库地址

image-20231124152417484

给脚本权限

chmod +x post-receive 

0x03hexo填写配置信息

修改配置文件_config.yml,没有就添加

deploy:
type: git
repo:
repo: root@服务器ip:/root/hexo/hexo.git
branch: main

同步到git仓库

hexo g -d

弹出ssh连接的询问就输入”yes”,然后按要求输入密码

image-20231124153647133

大功告成

0x04使用秘钥登录

1.正常情况

其实也就是配置ssh的秘钥登录

生成公私钥,一直回车(-f后面是名称 这里是为可以同时配置多个服务器的私钥)

ssh-keygen -t rsa -C "root@pwns.fun" -f hexo_id_rsa

进目录改文件名

cd /root/.ssh
cp hexo_id_rsa.pub authorized_keys

hexo_id_rsa放在本机用户的.ssh文件夹下

image-20231125113028860

再次连接服务器或者hexo -d就不需要输入密码了

2.密钥登陆失败

如果无法登陆需要检查一下配置文件,可能服务器禁止了秘钥登录

不同系统配置文件的位置不同,可以大概搜索一下

find / -name *sshd*

参考链接

https://help.aliyun.com/document_detail/153709.html

https://blog.csdn.net/mjh1667002013/article/details/129290903