背景

为了更好的记录个人笔记;

md编辑软件typora+阿里云oss

hexo搭建本地博客;

阿里云服务器 搭建网上博客。

typora+oss

md编辑工具:typora;

结合阿里云oss,自动上传图片,让文档图片链接一次上传,处处使用。

相关的链接:

http://confluence.admin.bluemoon.com.cn/pages/viewpage.action?pageId=52079138

配置文件生成示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
{
"picBed": {
"uploader": "aliyun",
"aliyun": {
"accessKeyId": "******",
"accessKeySecret": "*******",
"bucket": "xieguangda", // 存储空间名
"area": "oss-cn-guangzhou", // 存储区域代号
"path": "img/xiegdnew", // 自定义存储路径
"customUrl": "http://xieguangda.oss-cn-guangzhou.aliyuncs.com", // 自定义域名,注意要加 http://或者 https://
"options": "" // 针对图片的一些后缀处理参数 PicGo 2.2.0+ PicGo-Core 1.4.0+
}
},
"picgoPlugins": {}
}

有一个注意事项:

如果担心AccessKey权限过大,可以使用 RAM子账号登录OSS管理控制台。避免权限过大危及阿里云的信息安全。

参考:https://help.aliyun.com/document_detail/61950.html

这里遇到了个小问题,修改了个人偏好后,第一时间上传并没有成功,重启后typora上传图片就成功了。

https://oss.console.aliyun.com/bucket/oss-cn-guangzhou/xieguangda/object?path=img%2Fxiegdnew%2F

image-20211101162632946

本地hexo

相关文档:https://hexo.io/zh-cn/docs/

安装相关软件

  • Node.js (Node.js 版本需不低于 10.13,建议使用 Node.js 12.0 及以上版本)
  • Git

安装 Hexo

1
npm install -g hexo-cli

​ 进入目录:

1
2
3
4
①D:\bluemoon\hexo\myself
②hexo init #初始化
③hexo g #生成
④hexo s #启动服务

http://localhost:4000/

image-20211025113459726

②修改主题,直接github下载喜欢的模板

1
https://hexo.io/themes/
1
2
git clone https://github.com/YunYouJun/hexo-theme-yun themes/hexo-theme-yun
如果github下载不了;可以从码云下载:git clone https://gitee.com/tommy2z/next.git themes/hexo-theme-next

修改_config.yml中的theme: landscape改为theme: hexo-theme-yun,然后重新执行hexo g来重新生成。

如果出现一些莫名其妙的问题,可以先执行hexo clean来清理一下public的内容,然后再来重新生成和发布。

安装其他依赖项
安装hexo-theme-yun所需依赖项

1
npm install hexo-renderer-pug --save

主题使用指南

1
https://hexo-theme-yun.vercel.app/guide/#%E5%BF%AB%E9%80%9F%E5%BC%80%E5%A7%8B

常见配置参数修改:

_config.yml

1
2
3
4
5
6
7
8
title: "标题****"
subtitle: '小标题******'
description: '个人说明*****'
keywords:
author: xiegd
language: zh-CN
timezone: ''

增加search搜索

1
npm install hexo-generator-searchdb --save

_config.xml

1
2
3
4
5
search:
path: search.xml
field: post
format: html
limit: 10000
1
2
3
local_search:
enable: true
src: /js/search/local-search.js

创建链接

1
hexo new page links #创建链接
image-20211025141511166

image-20211025143201891

关于 About

1
hexo new page about

随便写些关于个人的信息。

bat一键启动

1
2
hexo clean && hexo g && hexo s 
pause

本地hexo部署到阿里云服务器

阿里云服务安装git、配置相关项

Hexo可以使用Git来部署,这样每次写完之后就都可以使用git来一键部署了,比较方便

本地–[推送代码]–>git服务器–[触发]–>post-receive钩子–[拉取代码]–>部署目录

首先介绍下 Hexo 的机制:本地环境生成静态文件,将这些文件托管在平台上,这样用户只能访问到你生成的静态文件

新建git用户:
1
2
3
4
为了安全,我们新建一个名为 git 的用户,专门用于接受静态文件:
useradd git // 添加用户名为git
passwd git // 设置用户git的密码
su git //用户切换到git
仓库、静态文件地址

Git 仓库目录在 /home/git/newHexo.git ,静态文件部署在**/home/newhome**

1
2
3
4
cd /home
mkdir -p newhome // 项目存在的真实目录
mkdir git && cd git
git init --bare newHexo.git // 创建一个裸露的仓库

测试是否创建成功:

1
git clone git@www.xieguangda.top:/home/git/newHexo.git
免密设置

本地id_rsa.pub文本内容复制到服务器的authorized_keys

验证是否成功:

1
ssh git@www.xieguangda.top

image-20211108164829751

配置post-receive钩子

1
2
配置钩子函数:/home/git/newHexo.git/hooks/post-receive,成功推送后被调用
git --work-tree=/home/newhome --git-dir=/home/git/newHexo.git checkout -f

本地hexo,_config.yml配置

1
2
3
4
5
deploy:
type: git
repo: git@www.xieguangda.top:/home/git/newHexo.git
branch: master
message: 提交的信息

bat一键部署

1
2
hexo generate --deploy
pause

服务器nginx配置转发,直接访问hexo目录下的index.html

1
2
3
4
5
location / {
root /home/newhome;
index index.html;
try_files $uri $uri/ /index.html;
}

访问域名

http://www.xieguangda.top

扩展

阿里云安装hexo,本地只需上传md文件,无需安装hexo;

博客配置留言和分享功能

https://blog.csdn.net/ly364434006/article/details/84763573

hexo提交搜索引擎

1
https://www.jianshu.com/p/5e68f78c7791