2024年博客重构(旧)
2024-03-16 22:57:58

前言

将近两个月没有写博客了,趁着假期时间,重构下博客,之前的框架虽然很好,但是插入图片不方便,详见2023个人博客搭建,另外我还是想要一个更简洁的博客。

现在的博客框架

现在的框架很简单,我先用Markdown写博客文本,然后用pandoc把所有的markdown文本转换成html,然后上传,用GitHub Pages自动转换成网站就行。

几个常用的自动化脚本

第一个bw,是用来在博客目录下创建一个新的博客文件,同时在index.md中添加一行,更新主界面,并且创建一个文件夹放图片,大概像hexo new blog这样就不用手动添加了。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
function bw {
$name = Read-Host "Blog name"

New-Item -ItemType File -Path ("D:\personal\wujackwill.github.io\blog\$name.md") -Force

mkdir -p D:\personal\wujackwill.github.io\docs\images\$name

$tag = Read-Host "tags"

$filePath = "D:\personal\wujackwill.github.io\blog\index.md"

$date = Get-Date -Format "yyyy.MM.dd"

$newRow = "|[$name](./$name.html)|$date|$tag|"

$lines = Get-Content $filePath

$separatorIndex = $lines.IndexOf("|---|---|---|")

$lines = $lines[0..$separatorIndex] + $newRow + $lines[($separatorIndex + 1)..($lines.Count - 1)]

$lines | Set-Content $filePath
}

第二个脚本是用来上传博客的,因为我用的是git,所以就是git add, git commit, git push,这个脚本就是把这三个命令合并了,这样就不用每次都敲三遍命令了。

1
2
3
4
5
6
7
8
9
10
function bg {
cd D:\personal\wujackwill.github.io

git add .

git commit -m "add new blog"

git push origin master
}

最后一个脚本是用来把markdown转换成html的,这个脚本的作用是用Pandoc把博客目录下的所有markdown文件转换成html,然后把html文件移动到docs目录下,这样就可以直接用GitHub Pages转换成网站了。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
function bc {
$blogDirectory = "D:\personal\wujackwill.github.io\blog"

$docsDirectory = "D:\personal\wujackwill.github.io\docs"

$markdownFiles = Get-ChildItem -Path $blogDirectory -Filter *.md

foreach ($markdownFile in $markdownFiles) {
$htmlFile = Join-Path $docsDirectory ($markdownFile.BaseName + ".html")

pandoc --to=html5 $markdownFile.FullName -o $htmlFile -V mainfont="SimSun" --citeproc --bibliography="D:\Zotero\m.bib" --csl 'D:\personal\apa-style\american-psychological-association-7th-edition(no doi & citation number).csl' --css=https://benjam.info/panam/styling.css -s
}

Move-Item D:\personal\wujackwill.github.io\blog\*.html -Destination "D:\personal\wujackwill.github.io\docs" -Force
}

G

参考资料

[1] GitPage如何对自定义域名开启强制https - Hexo建站(九)

[2] GitHub Pages HTTPS证书自动签发错误解决

[3] GitHub pages 配置自定义域名利用 Cloudflare 全球 CDN

[4] GitHub Pages 自定义域名开始支持 https

PS: 脚本是Chatgpt写的,而且是用的Powershell, 能用就行。

Prev
2024-03-16 22:57:58
Next