0%

一、列表

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
\begin{document}

\begin{itemize} % 无序列表环境
\item 列表项1
\item 列表项2
\item 列表项3
\end{itemize}

\begin{enumerate} % 有序列表环境
\item 列表项1
\item 列表项2
\item 列表项3
\end{enumerate}

\end{document}

二、表格

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
29
30
31
32
33
\begin{document}

% 表格环境
\begin{tabular}{ c c c } % c c c 表示表格一共三列, 均为居中显示(c居中 l左对齐 r右对齐)
单元格11 & 单元格12 & 单元格13 \\
单元格21 & 单元格22 & 单元格23 \\
单元格31 & 单元格32 & 单元格33
\end{tabular}

% 表格边框
\begin{tabular}{ |l|c|c| } % | 表示添加竖直边框
% \hline添加水平边框
\hline
\hline % 连续两个\hline可以实现双线边框
单元格11 & 单元格12 & 单元格13 \\
\hline
单元格21 & 单元格22 & 单元格23 \\
\hline
单元格31 & 单元格32 & 单元格33 \\
\hline
\end{tabular}

% 表格标题
\begin{table}
\center % 表格居中显示
\begin{tabular}{ c c }
单元格11 & 单元格12 \\
单元格21 & 单元格22
\end{tabular}
\caption{title} % 设置表格名
\end{table}

\end{document}

一、插入图片

1
2
3
4
5
6
7
8
9
10
11
12
\usepackage{graphicx} % 插入图片所需包

\begin{document}

\begin{figure} % 用图片环境包裹时方便设置
\centering % 居中
\includegraphics[width=0.5\textwidth]{pic} % 图片宽为0.5倍文本区域宽度
% pic为图片路径
\caption{title} % 图片标题
\end{figure}

\end{document}

一、如何在Markdown中使用LaTeX

1.在公式块中使用LaTeX

​ 单独成行使用LaTeX的方式是用双$包裹LaTeX语法

1
2
3
$$ 
(填入LaTeX语法内容)
$$

​ 效果如下:

$$(填入LaTeX语法内容)$$

2.在行间插入LaTeX

​ 直接在行间使用单$包裹LaTeX语法

1
在行间使用时直接在行间添加$ ... $即可

​ 效果如下:$(填入LaTeX语法内容)$

二、LaTeX常用语法

参考:

Cmd Markdown 公式指导手册 - 作业部落 Cmd Markdown 编辑阅读器 (zybuluo.com)

typora常用的数学公式编辑语法 - Wreng - 博客园 (cnblogs.com)

Markdown数学公式语法 - 简书 (jianshu.com)

1.排版

说明1:在align环境下, &符号就是”对齐的位置”,放置在最左边就是多行公式左对齐; Markdown公式以不同方式对齐_CA727的博客-CSDN博客_markdown公式对齐
$$
\begin{align}
f(x) &= x^2 + 2x + 1
&= (x + 1)^2 \tag{1} \
&= 2^2 + 2 \times 2 + 1
&= 9 \tag{2} \
\end{align}
$$

1
2
3
4
5
6
\begin{align}
f(x) &= x^2 + 2x + 1
&= (x + 1)^2 \tag{1} \\
&= 2^2 + 2 \times 2 + 1
&= 9 \tag{2} \\
\end{align}

说明2:\符号是每一行公式结束后的换行。
$$
第一行\
第二行
$$

1
2
第一行\\
第二行

2.常用表达式

(1)上下标

$$
a_1^2\
b_{12}\
2^{x^2+y}\
2H^{+}+SO_{4}^{2-}=H_{2}SO_{4}
$$

1
2
3
4
a_1^2\\
b_{12}\\
2^{x^2+y}\\
2H^{+}+SO_{4}^{2-}=H_{2}SO_{4}

(2)分数

$$
\frac{x}{1+x^2}
\
\frac{\frac{1}{2}+x}{y}
\
\tfrac{a}{b}
\frac{a}{b}
$$

1
2
3
4
5
6
\frac{x}{1+x^2}
\\
\frac{\frac{1}{2}+x}{y}
\\
\tfrac{a}{b}
\frac{a}{b}

(3)开方

$$
\sqrt{x}
\sqrt[3]{x}
$$

1
2
\sqrt{x}
\sqrt[3]{x}

(4)组合数

$$
\binom{n}{k}
\tbinom{n}{k}
$$

1
2
\binom{n}{k}
\tbinom{n}{k}

(5)导数、积分与极限

$$
f’
f’’
f^{(n)}
$$

1
2
3
f'
f''
f^{(n)}

$$
\int_{1}^{2}f(x) \
\intop_{2}^{1}f(x) \
\oint f(x) \
\smallint f(x) \
\
\iint f(x,y) \
\oiint f(x,y) \
\iiint f(x,y) \
\oiiint f(x,y) \
$$

1
2
3
4
5
6
7
8
9
\int_{1}^{2}f(x) \\
\intop_{2}^{1}f(x) \\
\oint f(x) \\
\smallint f(x) \\
\\
\iint f(x,y) \\
\oiint f(x,y) \\
\iiint f(x,y) \\
\oiiint f(x,y) \\

$$
\lim_{k \to \infty}
\lim\limits_{k \to \infty}
\lim\nolimits_{k \to \infty}
$$

1
2
3
\lim_{k \to \infty}
\lim\limits_{k \to \infty}
\lim\nolimits_{k \to \infty}

$$
\begin{align}
\mathrm{d}x
\end{align}
$$

1
2
3
\begin{align}
\mathrm{d}x
\end{align}

(6)累加与累乘

$$
\sum_{i=1}^{k}
\displaystyle\sum_{i=1}^n
\textstyle\sum_{i=1}^n
\
\prod_{i=1}^{k}
\displaystyle\prod_{i=1}^n
\textstyle\prod_{i=1}^n
$$

1

(7)取模

$$
x \pmod a
\
2\mod{x}
$$

1

(8)符号

$$
\pi \
e \
a \cdot b \
a \times b \
a \div b \
$$

1

3.矩阵与方程组

(1)矩阵

$$
A = \begin{matrix}
a & b\
c & d
\end{matrix}
\
B = \begin{pmatrix}
a & b\
c & d
\end{pmatrix}
\
C = \begin{vmatrix}
a & b\
c & d
\end{vmatrix}
\
D = \begin{bmatrix}
a & b\
c & d
\end{bmatrix}
\
E = \begin{Vmatrix}
a & b\
c & d
\end{Vmatrix}
\
F = \begin{Bmatrix}
a & b\
c & d
\end{Bmatrix}
\
$$

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
29
30
A = \begin{matrix}
a & b\\
c & d
\end{matrix}
\\
B = \begin{pmatrix}
a & b\\
c & d
\end{pmatrix}
\\
C = \begin{vmatrix}
a & b\\
c & d
\end{vmatrix}
\\
D = \begin{bmatrix}
a & b\\
c & d
\end{bmatrix}
\\
E = \begin{Vmatrix}
a & b\\
c & d
\end{Vmatrix}
\\
F = \begin{Bmatrix}
a & b\\
c & d
\end{Bmatrix}
\\

$$
[A\ b] =
\begin{bmatrix}
\begin{array}{c c c|c}
a_{11} & a_{12} & a_{13} & b_1\
a_{21} & a_{22} & a_{23} & b_2\
a_{31} & a_{32} & a_{33} & b_3\
\end{array}
\end{bmatrix}
\
$$

1
2
3
4
5
6
7
8
9
[A\ b] = 
\begin{bmatrix}
\begin{array}{c c c|c}
a_{11} & a_{12} & a_{13} & b_1\\
a_{21} & a_{22} & a_{23} & b_2\\
a_{31} & a_{32} & a_{33} & b_3\\
\end{array}
\end{bmatrix}
\\

$$
\begin{array}{c:c:c}
a & b & c \
\hline
d & e & f \
\hdashline
g & h & i \
\end{array}
\
$$

1
2
3
4
5
6
7
8
\begin{array}{c:c:c}
a & b & c \\
\hline
d & e & f \\
\hdashline
g & h & i \\
\end{array}
\\

$$
L_{n\times n} = \begin{bmatrix}
a_{11} & a_{12} & \cdots & a_{1n} \
a_{21} & a_{22} & \cdots & a_{2n} \
\vdots & \vdots &\ddots & \vdots\
a_{n1} & a_{n2} & \cdots & a_{nn} \
\end{bmatrix}
\
$$

1
2
3
4
5
6
7
L_{n\times n} = \begin{bmatrix}
a_{11} & a_{12} & \cdots & a_{1n} \\
a_{21} & a_{22} & \cdots & a_{2n} \\
\vdots & \vdots &\ddots & \vdots\\
a_{n1} & a_{n2} & \cdots & a_{nn} \\
\end{bmatrix}
\\

(2)方程组

说明:用&来实现对齐
$$
\begin{aligned}
f(x) &= (x+1)^2\
&= x^2 + 2x + 1
\end{aligned}
\
f(x) = \begin{cases}
x + 2y &= 1 &\text{if a}\
3x - y &= 5 &\text{if b}\
\end{cases}
$$

1
2
3
4
5
6
7
8
9
\begin{aligned}
f(x) &= (x+1)^2\\
&= x^2 + 2x + 1
\end{aligned}
\\
f(x) = \begin{cases}
x + 2y &= 1 &\text{if a}\\
3x - y &= 5 &\text{if b}\\
\end{cases}

参考: Markdown 图片 | 菜鸟教程 (runoob.com)

一、绝对路径

1
2
3
4
5
![图片文字](图片地址)
# 使用本地路径
![alt 本地图片](F:\图片缓存\QQ图片20220328200050.jpg)
# 使用网络路径
![RUNOOB 图标](http://static.runoob.com/images/runoob-logo.png)

二、base64字符

​ markdown中可以用图片base64加密得到的字符串来显示

1
2
3
4
5
6
![base64图片](base64字符串)
# 直接使用base64字符串
![直接使用base64](data:image/png;base64,iVBORw0KGgo...)
# 使用中间变量
![使用中间变量][变量名]
[变量名]:data:image/png;base64,iVBORw0KGgo... # 声明变量在使用变量前或后均可

注:中间变量使用方式可以实现将长串的base64储存于文章末尾,然后再文章中部通过变量名来调用该字符从而可以再任意位置展示图片
具体参考 【记录】如何使用Markdown中的变量_脆鲨Nana7mi的博客-CSDN博客_markdown 变量

主要参考: 个人博客搭建教程 | 爱扑bug的熊 (cuijiacai.com)

Step1 安装Node.js

官网下载安装软件并手动安装

Step2 安装Hexo

安装hexo

1
2
3
4
5
6
7
8
9
10
11
12
# 配置npm的国内镜像
npm config get registry # 查看原来的源
npm config set registry https://registry.npm.taobao.org # 修改为淘宝源
npm config get registry # 查看现在的源
# npm安装hexo
# 其中-g参数表示全局安装,没有这个参数就只在当前目录下安装,建议全局安装
npm install hexo-cli -g # 全局安装hexo命令行工具
# 创建hexo项目
hexo init "你的博客目录名称" # 目录名称不含空格的时候双引号可以省略
# 进入hexo项目并安装依赖
cd "博客目录"
npm install # 安装依赖

测试hexo

1
2
3
4
5
6
# 创建文章(markdown格式)
hexo new post "test" # 会在 source/_posts/ 目录下生成文件 ‘test.md’,打开编辑
# 生成html文件
hexo generate # 生成静态HTML文件到 /public 文件夹中
# 启动项目
hexo server

运行结果

1663126035154

安装测试成功

Step3 配置Hexo

自行修改

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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# Site
title: Hexo # 网站标题
subtitle: # 网站副标题
description: # 网站描述
author: John Doe # 作者
language: # 语言
timezone: # 网站时区, Hexo默认使用您电脑的时区

# URL
## If your site is put in a subdirectory, set url as 'http://yoursite.com/child'
## and root as '/child/'
url: http://yoursite.com # 你的站点Url
root: / # 站点的根目录
permalink: :year/:month/:day/:title/ # 文章的 永久链接 格式
permalink_defaults: # 永久链接中各部分的默认值

# Directory
source_dir: source # 资源文件夹,这个文件夹用来存放内容
public_dir: public # 公共文件夹,这个文件夹用于存放生成的站点文件。
tag_dir: tags # 标签文件夹
archive_dir: archives # 归档文件夹
category_dir: categories # 分类文件夹
code_dir: downloads/code # Include code 文件夹
i18n_dir: :lang # 国际化(i18n)文件夹
skip_render: # 跳过指定文件的渲染,您可使用 glob 表达式来匹配路径。

# Writing
new_post_name: :title.md # 新文章的文件名称
default_layout: post # 预设布局
titlecase: false # 把标题转换为 title case
external_link: true # 在新标签中打开链接
filename_case: 0 # 把文件名称转换为 (1) 小写或 (2) 大写
render_drafts: false # 是否显示草稿
post_asset_folder: false # 是否启动 Asset 文件夹
relative_link: false # 把链接改为与根目录的相对位址
future: true # 显示未来的文章
highlight: # 内容中代码块的设置
enable: true # 开启代码块高亮
line_number: true # 显示行数
auto_detect: false # 如果未指定语言,则启用自动检测
tab_replace: # 用 n 个空格替换 tabs;如果值为空,则不会替换 tabs

# Category & Tag
default_category: uncategorized
category_map: # 分类别名
tag_map: # 标签别名

# 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 # 时间格式

# Pagination
## Set per_page to 0 to disable pagination
per_page: 10 # 分页数量
pagination_dir: page # 分页目录

# Extensions
## Plugins: https://hexo.io/plugins/
## Themes: https://hexo.io/themes/
theme: landscape # 主题名称

# Deployment
## Docs: https://hexo.io/docs/deployment.html
# 部署部分的设置
deploy:
type: '' # 类型,常用的git

Step4 添加建站脚本

为了后续netlify建站方便,我们可以在package.json里面添加一个命令:

1
2
3
4
5
6
7
8
9
10
11
12

{
// ......
"scripts": {
"build": "hexo generate",
"clean": "hexo clean",
"deploy": "hexo deploy",
"server": "hexo server",
"netlify": "npm run clean && npm run build" // 这一行为新加
},
// ......
}

Step5 github项目文件托管

1
2
3
4
5
6
7
cd "博客目录"
git init
git add .
git commit -m "my blog first commit"
git remote add origin "远端github仓库地址"
git branch -M main
git push -u origin main

注:如果之前是使用git clone下载源码的方式安装next主题的话,需要将next主题路径下的git相关文件删除,否则这里push时会将next视作另一个仓库作为链接上传至仓库

Step6 netlify建站

Netlify是一个国外的免费的提供静态网站部署服务的平台,能够将托管 GitHub,GitLab 等上的静态网站部署上线。至于我们为什么不使用github自带的gitpage,原因很简单,访问速度慢。此外,Netlify还有很多别的功能支持,这里不作剧透,可以自行探索。

注册登录https://app.netlify.com/后,选择使用github已有仓库来install,可以只选择想建站的仓库,不用勾选其他仓库。

到以下页面时,修改build command为

1
npm run netlify
1663135844851

配置成功后,如果部署成功,可以得到一个url,对应我们的博客;如果不成功可以检查日志查找原因

1663137924897

这个域名是netligy为你的网站分配的域名,如果希望修改成xxxx.netlify.app,就需要将你的部署网站的sitename修改为对应得xxxx

1663138396703

1663138407258

Step7 解析域名

如果希望将上述的xxxx.netlify.app解析至自己已有的域名上,需要进行如下操作

前往自己域名服务提供商处解析域名,我使用的是阿里的域名(记得提前实名备案)

1663139265764

然后再回到netlify网址上配置一下自己的用户域名,这样的话可以在国外获得netlify本身的CDN支持。

具体步骤见参考文章中图片过程,成功结果如下所示:

1663139423690

至此,不论是 WilsonBlog 还是 WilsonBlog (wilsongogo.top) 都可以用于访问博客网址了

Step8 Cloudflare加速

Netlify 虽然已经提供了 CDN 加速,但在使用过程中发现国内访问还是比较慢,Cloudflare 相对于国内的七牛云、阿里云等云服务商的 CDN 速度会慢一些,但是它有免费版本,而且最重要的是域名不用备案。

而且听说cloudflare有预防ddos的5s墙功能,因此选择试用Cloudflare

1.首先添加根域名至Cloudflare,然后选择免费套餐(仍拥有ddos防护功能)

2.随后在查找出的记录中寻找之前添加的CNAME类型,如未查到对应记录,可以手动添加(我这里使用了手动添加)

1663140020372

3.在域名服务商处修改dns解析服务器为cloudflare地址

1663140299075 1663140287649

Step9 配置https

现在netlify一般会自动配置好,也可以通过下图按钮使用自己的CA证书

1663140628517

Step1 安装Hexo的NexT主题

参考: Getting Started | NexT (theme-next.js.org)

使用源码安装

1
2
3
4
# 进入项目根目录
cd "博客目录"
# 下载源码至项目的主题存放对应目录
git clone https://github.com/next-theme/hexo-theme-next themes/next

修改配置文件./_config.yml

1
2
3
4
# 将原内容
theme: landscape
# 改为
theme: next

再次启动项目并访问

1663126309142

测试成功

Step2 设置高亮主题

前往 Highlight (theme-next.js.org) 查找需要的高亮主题,并复制网址上的配置内容分别至对应Hexo的_config.yml与NexT的_config.yml中

示例:

1
2
3
4
5
6
7
# Hexo的_config.yml
highlight:
enable: true
...
prismjs:
enable: false
...
1
2
3
4
5
6
7
8
9
# NexT的_config.yml
codeblock:
# Code Highlight theme
# All available themes: https://theme-next.js.org/highlight/
...
theme:
light: stackoverflow-dark
dark: stackoverflow-dark
...

Step3 设置导航栏与分类页面

参考: hexo之next主题添加分类_DrCrypto的博客-CSDN博客_hexo next 分类

1.修改NexT主题的配置文件

在NexT主题的_config.yml中修改以下部分生效(取消注释即可)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# ---------------------------------------------------------------
# Menu Settings
# ---------------------------------------------------------------

# Usage: `Key: /link/ || icon`
# Key is the name of menu item. If the translation for this item is available, the translated text will be loaded, otherwise the Key name will be used. Key is case-sensitive.
# Value before `||` delimiter is the target link, value after `||` delimiter is the name of Font Awesome icon.
# External url should start with http:// or https://
menu:
home: / || fa fa-home
about: /about/ || fa fa-user
tags: /tags/ || fa fa-tags
categories: /categories/ || fa fa-th
archives: /archives/ || fa fa-archive
#schedule: /schedule/ || fa fa-calendar
#sitemap: /sitemap.xml || fa fa-sitemap
#commonweal: /404/ || fa fa-heartbeat

2.添加categories页面

使用hexo命令创建categories页

1
2
3
4
5
6
7
8
9
10
11
12
13
14
PS D:\WorkSpace\Coding\Git\myHexo> hexo new page categories    
INFO Validating config
INFO ==================================
███╗ ██╗███████╗██╗ ██╗████████╗
████╗ ██║██╔════╝╚██╗██╔╝╚══██╔══╝
██╔██╗ ██║█████╗ ╚███╔╝ ██║
██║╚██╗██║██╔══╝ ██╔██╗ ██║
██║ ╚████║███████╗██╔╝ ██╗ ██║
╚═╝ ╚═══╝╚══════╝╚═╝ ╚═╝ ╚═╝
========================================
NexT version 8.13.0
Documentation: https://theme-next.js.org
========================================
INFO Created: D:\WorkSpace\Coding\Git\myHexo\source\categories\index.md

修改对应index.md内容如下

1
2
3
4
5
---
title: categories
date: 2022-09-14 13:15:16
type: "categories"
---

在文章起始位置添加categories信息

1
2
3
4
5
6
7
8
---
...
categories:
- 主分类
- 子分类
- 子子分类
...
---

3.添加tags页面

使用hexo命令创建tags页面

1
2
3
4
5
6
7
8
9
10
11
12
13
14
PS D:\WorkSpace\Coding\Git\myHexo> hexo new page tags      
INFO Validating config
INFO ==================================
███╗ ██╗███████╗██╗ ██╗████████╗
████╗ ██║██╔════╝╚██╗██╔╝╚══██╔══╝
██╔██╗ ██║█████╗ ╚███╔╝ ██║
██║╚██╗██║██╔══╝ ██╔██╗ ██║
██║ ╚████║███████╗██╔╝ ██╗ ██║
╚═╝ ╚═══╝╚══════╝╚═╝ ╚═╝ ╚═╝
========================================
NexT version 8.13.0
Documentation: https://theme-next.js.org
========================================
INFO Created: D:\WorkSpace\Coding\Git\myHexo\source\tags\index.md

修改对应index.md内容如下

1
2
3
4
5
---
title: categories
date: 2022-09-14 13:15:16
type: "categories"
---

在文章起始位置添加tags信息

1
2
3
4
5
6
7
---
...
tags:
- tag1
- tag2
...
---

4.测试效果

1663133939359

1663133949033

参考:

hexo的next主题个性化配置 - 知乎 (zhihu.com)

Hexo+Next主题的一些实用插件和美化升级_next 单行代码 美观优化_小王同学w的博客-CSDN博客

1.配置修改

(1)取消目录章节自动编号

修改配置文件 ./themes/next/_config.yml

1
2
3
4
5
6
toc:
enable: true
number: true # 改为false
wrap: false
expand_all: false
max_depth: 6

(2)网站图标

修改配置文件 ./themes/next/_config.yml

1
2
3
4
5
favicon:
small: /images/favicon-16x16-next.png # 浏览器标签处显示图标
medium: /images/favicon-32x32-next.png # 收藏时网页图标
 apple_touch_icon: /images/apple-touch-icon-next.png
 safari_pinned_tab: /images/logo.svg

favicon-nxn-next.png 均位于 ./themes/next/source/images目录

(3)代码块复制功能

修改配置文件 ./themes/next/_config.yml

1
2
3
4
5
6
7
codeblock:
...
# Add copy button on codeblock
copy_button:
enable: false # 改为true
# Available values: default | flat | mac
style:

(4)侧边栏社交链

修改配置文件 ./themes/next/_config.yml

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
29
30
31
32
33
34
35
36
37
38
39
social:
GitHub: https://github.com/WilsonGoGo || fab fa-github
E-Mail: mailto:[email protected] || fa fa-envelope
#Weibo: https://weibo.com/yourname || fab fa-weibo
#Google: https://plus.google.com/yourname || fab fa-google
#Twitter: https://twitter.com/yourname || fab fa-twitter
#FB Page: https://www.facebook.com/yourname || fab fa-facebook
#StackOverflow: https://stackoverflow.com/yourname || fab fa-stack-overflow
#YouTube: https://youtube.com/yourname || fab fa-youtube
#Instagram: https://instagram.com/yourname || fab fa-instagram
#Skype: skype:yourname?call|chat || fab fa-skype

social_icons:
enable: true
icons_only: false
transition: false
#图标
GitHub: github
E-Mail: envelope


#设置侧边栏社交链
social:
GitHub: https://github.com/zzwwqq || github
E-Mail: mailto:[email protected] || envelope
Weibo: https://weibo.com/u/5564810309/home?wvr=5 || weibo
知乎: https://www.zhihu.com/people/shen-qiu-wu-hen-66/activities || snapchat

#这里键的值必须和上面social中的 "||" 后面指定的名称一致,在fontawesome官网找喜欢的小图标,将名字复制在如下位置,如E-Mail:对应的图标名称为envelope。

social_icons:
enable: true # `enable` 选项用于控制是否显示图标
icons_only: false
transition: false
#图标
GitHub: github
E-Mail: envelope
Weibo: weibo
知乎: snapchat

(4)站点浏览次数(未生效,插件未安装)

修改主题配置文件 ./themes/next/_config.yml

1
2
3
4
5
6
7
8
9
10
# Show Views / Visitors of the website / page with busuanzi.
# For more information: http://ibruce.info/2015/04/04/busuanzi/
busuanzi_count:
enable: false # 改为true
total_visitors: true
total_visitors_icon: fa fa-user
total_views: true
total_views_icon: fa fa-eye
post_views: true
post_views_icon: far fa-eye

注:该模块具体html代码设置已在./themes/next/layout/_partials/footer.njk文件中,但是可以通过主题配置文件中配置开选择是否启用相关代码

(5)评论系统+文章阅读次数(未实现,需要leancloud账号)

2.布局修改

(1)Fork me on github标签

在./themes/next/layout/_layout.njk文件中进行配置

1
2
3
4
5
6
7
<body itemscope itemtype="http://schema.org/WebPage"{% if theme.motion.enable %} class="use-motion"{% endif %}>
<div class="headband"></div>

<!-- 需要插入的代码 -->
<a href="https://github.com/WilsonGoGo" ... > <!-- href后为github的地址 -->

...

需要插入的该行代码可由以下网址生成

GitHub Ribbons | The GitHub Blog

GitHub Corners (tholman.com)

(2)站点运行时长

在 ./themes/next/layout/_partials/footer.njk文件底部添加下面的代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<!-- 添加显示本站已安全运行时长功能 -->
<div>
<span id="timeDate">载入天数...</span><span id="times">载入时分秒...</span>
<script>
var now = new Date();
function createtime() {
var start_time_string = '2022-09-14 14:43:26'; //此处修改你的建站时间或者网站上线时间
var grt = new Date(start_time_string.replace(/-/g, "/"));
now.setTime(now.getTime()+1000);
days = (now - grt ) / 1000 / 60 / 60 / 24; dnum = Math.floor(days);
hours = (now - grt ) / 1000 / 60 / 60 - (24 * dnum); hnum = Math.floor(hours);
if(String(hnum).length ==1 ){hnum = "0" + hnum;} minutes = (now - grt ) / 1000 /60 - (24 * 60 * dnum) - (60 * hnum);
mnum = Math.floor(minutes); if(String(mnum).length ==1 ){mnum = "0" + mnum;}
seconds = (now - grt ) / 1000 - (24 * 60 * 60 * dnum) - (60 * 60 * hnum) - (60 * mnum);
snum = Math.round(seconds); if(String(snum).length ==1 ){snum = "0" + snum;}
document.getElementById("timeDate").innerHTML = "本站已安全运行 "+dnum+" 天 ";
document.getElementById("times").innerHTML = hnum + " 小时 " + mnum + " 分 " + snum + " 秒";
}
setInterval("createtime()",1000); // 刷新时间
</script>
</div>

3.网站特效

(1)鼠标点击特效(未实现)

(2)博客宠物(未实现)

(3)作者头像动画(未实现)

打开.\themes\next\source\css\_common\components\sidebar\sidebar-author.styl,添加代码

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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
.site-author-image {
display: block;
margin: 0 auto;
padding: $site-author-image-padding;
max-width: $site-author-image-width;
height: $site-author-image-height;
border: $site-author-image-border-width solid $site-author-image-border-color;

/* 头像圆形 */
border-radius: 80px;
-webkit-border-radius: 80px;
-moz-border-radius: 80px;
box-shadow: inset 0 -1px 0 #333sf;

/* 设置循环动画 */
/* [animation: (play)动画名称 (2s)动画播放时长单位秒或微秒 (ase-out)动画播放的速度曲线为以低速结束(1s)等待1秒然后开始动画 (1)动画播放次数(infinite为循环播放) ] */


/* 鼠标经过头像旋转360度 */
-webkit-transition: -webkit-transform 1.0s ease-out;
-moz-transition: -moz-transform 1.0s ease-out;
transition: transform 1.0s ease-out;
}

img:hover {
/* 鼠标经过停止头像旋转
-webkit-animation-play-state:paused;
animation-play-state:paused;*/

/* 鼠标经过头像旋转360度 */
-webkit-transform: rotateZ(360deg);
-moz-transform: rotateZ(360deg);
transform: rotateZ(360deg);
}

/* Z 轴旋转动画 */
@-webkit-keyframes play {
0% {
-webkit-transform: rotateZ(0deg);
}
100% {
-webkit-transform: rotateZ(-360deg);
}
}
@-moz-keyframes play {
0% {
-moz-transform: rotateZ(0deg);
}
100% {
-moz-transform: rotateZ(-360deg);
}
}
@keyframes play {
0% {
transform: rotateZ(0deg);
}
100% {
transform: rotateZ(-360deg);
}
}

(4)背景动画(未实现)

一、文件头

首先修改post_asset_folder属性,打开_config.yml文件

1
post_asset_folder: true

随后在./source内创建目录用于存放所有图片

1
2
cd ./source/
mkdir imgs

之后再将markdown内图片的引用地址按照如下规则修改

1
2
3
4
# 原引用
![1663126035154](./demo.assets/1663126035154.png)
# 现引用
![1663126035154](imgs/demo.assets/1663126035154.png)

效果如下

1663134819637参考 Front-matter | Hexo

博文的原始morkdown文件,需要加上文件头给Hexo进行识别,front-matter部分用—与正文分割

1
2
3
4
5
6
7
8
---
title: 文章标题
date: 建立时间
update: 更新时间
categories: 博文分类,可以设置多个、多级分类
tags: 标签,可以设置多个标签
id: 用于唯一标识博文,会嵌入url中
---
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# 标签没有分级
tags:
- PS3
- Games

# 多级分类使用例
categories:
- Diary
- Life

# 如果需要多个多级分类,使用以下方式
categories:
- [Diary, PlayStation]
- [Diary, Games]
- [Life]

二、文章url设置

参考: hexo文章url设置___Pntehan__的博客-CSDN博客_hexo修改文章路径

首先修改./_config.yml的配置内容

1
2
# 直接用category和id作为url, 防止title的中文导致乱码
permalink: :category/:id/

三、文章图片设置

参考: Hexo 添加图片——不用插件,超简单_一荤配一素的博客-CSDN博客_hexo post图片

首先修改post_asset_folder属性,打开_config.yml文件

1
post_asset_folder: true

随后在./source内创建目录用于存放所有图片

1
2
cd ./source/
mkdir imgs

之后再将markdown内图片的引用地址按照如下规则修改

1
2
3
4
# 原引用
![1663126035154](./demo.assets/1663126035154.png)
# 现引用
![1663126035154](imgs/demo.assets/1663126035154.png)

效果如下

1663134819637

Ubuntu20.04 安装

镜像来源: 下载Ubuntu桌面系统 | Ubuntu

​ 安装Ubuntu需要先去官网下载ISO镜像(推荐下载LTS长期支持的版本),上述链接为桌面版Ubuntu,其自带GUI界面,方便操作(也可以在官网选择服务器版镜像:https://cn.ubuntu.com/download/server/)。

一、物理机安装

参考: 使用UltraISO制作ubuntu安装u盘启动盘图文教程 - 简书 (jianshu.com)

​ 可以建立USB启动盘(推荐UltraOS软件),完成启动盘的设置后,将U盘插入物理机并重启物理机进入BIOS界面,找到USB的启动项启动即可,后续步骤按照提示逐步完成即可(根据电脑主板支持的BIOS系统的不同,中途可以会遇到出乎意料的问题,建议根据物理机的主板型号查询BIOS相关设置)。

二、虚拟机安装

​ 使用VMware软件,直接选择新建虚拟机后,找到对应ISO文件即可。VMware安装时的参数对应的意义可以自行查询,一般选择推荐选项即可。

初始环境配置

1.安装vim

​ Ubuntu自带的为vi编辑器,vim是vi的升级版,兼容vi

1
sudo apt install vim

2.更改Ubuntu镜像源

参考: [ubuntu20.04 LTS 更换国内163源、阿里源、清华源、中科大源 - zqifa - 博客园 (cnblogs.com)](https://www.cnblogs.com/zqifa/p/12910989.html#:~:text=ubuntu20.04 LTS 更换国内163源、阿里源、清华源、中科大源 Ubuntu 20.04 是 Ubuntu 的第,LTS 版本,其重大更新和改进将在 2030 年前终止,计划于2020年 4 月 23 日发布。)

1
2
3
4
5
6
7
# 备份源文件
sudo cp /etc/apt/sources.list /etc/apt/sources.list.backup
# 添加源
<将后文中的源写入/etc/apt/sources.list>
# 执行更新命令
sudo apt-get update
sudo apt-get upgrade
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
### 163源 ###
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb http://mirrors.163.com/ubuntu/ focal main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ focal-security main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ focal-updates main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ focal-backports main restricted universe multiverse
# deb-src http://mirrors.163.com/ubuntu/ focal main restricted universe multiverse
# deb-src http://mirrors.163.com/ubuntu/ focal-security main restricted universe multiverse
# deb-src http://mirrors.163.com/ubuntu/ focal-updates main restricted universe multiverse
# deb-src http://mirrors.163.com/ubuntu/ focal-backports main restricted universe multiverse
# 预发布软件源,不建议启用
# deb http://mirrors.163.com/ubuntu/ focal-proposed main restricted universe multiverse
# deb-src http://mirrors.163.com/ubuntu/ focal-proposed main restricted universe multiverse

### 阿里云 ###
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse

### 清华源 ###
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse
# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse

### 中科大源 ###
deb https://mirrors.ustc.edu.cn/ubuntu/ focal main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ focal-security main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-security main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse

2.安装OpenSSH

1
2
3
4
5
6
7
sudo apt-get install openssh-server
### 检查ssh服务状态 ###
ps -e|grep ssh
878 ? 00:00:00 sshd
1608 ? 00:00:00 ssh-agent
2009 ? 00:00:00 sshd
2085 ? 00:00:00 sshd

注:配置私钥免密ssh登录部分详见 /协议栈/ssh 部分

3.安装ifconfig

1
sudo apt install net-tools

5.安装firewalld

1
sudo apt install firewalld

参考: 一篇读懂 Linux 用户管理与操作 - 知乎 (zhihu.com)

一、用户管理

1.检查用户组信息

Linux用户组相关信息都储存于以下文件中

  • /etc/group —— 管理用户组相关信息
1
2
3
4
5
6
7
8
9
10
11
# 储存内容格式
# 账号名称 : 密码 : UID : GID : 用户信息说明列 : 主文件夹 : shell
# 具体密码转存/etc/passwd
$ sudo cat /etc/group
root:x:0:
daemon:x:1:
sudo:x:27:wilson
users:x:100:
wilson:x:1000:
docker:x:998:wilson
...
  • /etc/gshadow —— 管理用户组管理员相关信息
1
2
3
4
5
# 用户组名 : 密码 : 用户组管理员账号 : 该用户组包含的账号名称
# 一般用户组不使用用户组管理员,相应地也就不需要设置密码
$ sudo cat /etc/gshadow
root : : : root
...
  • /etc/passwd —— 管理用户UID/GID重要参数
  • /etc/shadow —— 管理用户密码

2.用户信息查询命令

1
2
3
4
5
6
7
id <user>         # 展示指定user的UID、GID、用户组信息等,默认为当前有效用户
who am i # 等同于 who -m,仅显示当前登录用户相关信息
whoami # 仅显示当前有效用户的用户名
w # 展示当前正在登录主机的用户信息及正在执行的操作
who # 展示当前正在登录主机的用户信息
last <user> # 展示指定用户的历史登录信息,默认为当前有效用户
lastlog -u <user> # 展示指定用户最近的一次登录信息,默认显示所有用户

3.用户管理命令速查

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
29
30
# 切换用户
su [options] [username]
# options:
# -:代表使用 login-shell 的变量文件读取方式来登录系统
# -l:同上
# -m:表示使用当前的环境设置,而不读取新用户的配置文件
# -c:仅进行一次命令,执行完后直接回到目前的用户身份
# 如果 username 为空,则默认切换为 root 用户

# 添加用户
useradd [options] [username]
# useradd 默认不会在 /home 下创建用户同名的主目录
# useradd 创建的用户还没有设置登录密码,需要利用passwd进行密码设置

# 删除用户
userdel [options] [username]
$ userdel -r sam # 常用的选项是 -r,它的作用是把用户sam的主目录一起删除

# 修改密码
passwd [options] [username]

# 修改用户
chage [option] [username]
# 修改与用户密码相关的过期信息,如密码失效日、密码最短保留天数、失效前警告天数等

# 修改用户信息
usermod [options] [username]
$ usermod -G group_name user_name # 添加用户到指定的组,但是以前添加的组就会清空掉
$ usermod -a -G sudo user_name # 添加用户至sudo组
# 通过 options 参数,修改 etc/passwd 内用户信息
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
29
30
31
32
33
34
35
36
# 切换用户组
newgrp 用户组
$ newgrp root # 让使用者暂时切换到root用户组
# 前提条件是root用户组是该用户的主组或附加组; 或输入root群组密码
# 切换后建立的文件的 group 属性也会随之改变

# 添加用户组
groupadd 选项 用户组
$ groupadd group1 # 新组的组标识号是在当前已有的最大组标识号的基础上加1
$ groupadd -g 101 group2 # 指定新组的组标识号是101

# 删除用户组
groupdel 用户组
$ groupdel group1 # 删除组group1

# 修改用户组
groupmod 选项 用户组
# -g GID 为用户组指定新的组标识号。
# -o 与-g选项同时使用,用户组的新GID可以与系统已有用户组的GID相同。
# -n 新用户组 将用户组的名字改为新名字
$ groupmod -g 102 group2 # group2的组标识号修改为102
$ groupmod –g 10000 -n group3 group2 # group2的标识号改为10000,组名修改为group3

# 向用户组添加用户
gpasswd [可选项] 组名
# -a:添加用户到组;
# -d:从组删除用户;
# -A:指定管理员;
# -M:指定组成员和-A的用途差不多;
# -r:删除密码;
# -R:限制用户登入组,只有组中的成员才可以用newgrp加入该组
$ gpasswd users # 设定 users 群组的密码
$ gpasswd -a $USER users # 添加当前用户至 users 群组
$ gpasswd -A peter users # 指定 peter 是 users 群组的管理员
$ gpasswd -a allen users # 添加 allen 至 users 群组, 保留allen原有群组
$ usermod -G users bob # 添加 bob 至 users 群组, 并移除之前bob所在所有群组

4.sudo权限

在 /etc/sudoers 文件内的用户普通用户可以通过 sudo 命令,使用 root 用户权限来执行命令

1
2
3
4
5
6
7
8
9
10
# 查看sudo权限设置
$ sudo cat /etc/sudoers
...
# User privilege specification
# 用户账号 登录者来源主机名=(可切换身份:身份所在用户组) 可执行命令
root ALL=(ALL:ALL) ALL # 可执行 sudo 的单个用户白名单
# Allow members of group sudo to execute any command
# 用户账号 登录者来源主机名=(可切换身份:身份所在用户组) 可执行命令
%sudo ALL=(ALL:ALL) ALL # 可执行 sudo 的用户组白名单
...

可以修改授权,示例:

1
2
3
4
5
6
# testuser 可以利用 sudo 以任何身份执行任何命令
testuser ALL=(ALL:ALL) ALL
# testuser 仅可以以 root 身份执行任何命令
testuser ALL=(root:root) ALL
# testuser 仅可以以 root 身份执行 passwd 命令
testuser ALL=(root:root) /usr/bin/passwd

示例

1.添加拥有docker权限的新用户

1
2
3
4
5
sudo su # 需要有sudo权限才能管理用户
adduser webapp # 添加用户webapp
passwd webapp # 修改webapp密码
> ...
su webapp # 切换至webapp用户

再将webapp用户加入docker组,使其拥有使用docker命令的权限

1
2
3
4
5
6
7
8
9
# 添加docker用户组
# sudo groupadd docker # 一般已存在,不需要执行

# 将当前登陆的用户加入到docker用户组中
sudo gpasswd -a $USER docker

# 测试docker权限
docker -v
> Docker version 20.10.8, build 3967b7d

参考:

CentOS 7 - 创建新用户-阿里云开发者社区 (aliyun.com)

(18条消息) 把用户添加进Docker用户组_wuyundong123的博客-CSDN博客