原文博客地址
hexo 基本操作
创建一个新页面
hexo new "my new article" (引号里为新建博客文章的名字)
执行完就会在source/_posts文件夹下创建对应的.md文件
编译文件
hexo g
启动服务器,执行文件
hexo server
简写 hexo s
部署文件到远端服务器
hexo deploy
简写 hexo d
上传文件到 Github
- 在 Github 上新建仓库
- 在需要上传的文件夹目录下,运行 git init 初始化 git
- 运行 git add 命令,将需要上传的内容放到暂存区
- 运行 git commit -m ‘first commit’ 将暂存区的内容放到仓储里面
- 运行 git remote add origin https://github.com/li-car-fei…git,将仓储与Github仓库联系起来
- 运行 git push origin master 将文件提交到 Github 仓库里面,这样就完成了文件的提交
hexo 相册设置
- 下载需要的脚本:https://github.com/Janche/Blog-Photo.git
建立 github 仓库,并按上方提示关联本地文件夹
在 hexo 项目同级目录下创建空文件夹子,并创建 photos 和 min_photos 文件夹将下载的脚本中的 python 文件复制过去
上传文件到 github 库
把 blog_photos_copy 文件夹里的四个文件复制到 source/photos 文件夹中。
修改 ins.js 文件
for (var i = 0, len = data.link.length; i < len; i++) {
var minSrc =
"https://raw.githubusercontent.com/li-car-fei/hexo-Picture/master/min_photos/" +
data.link[i];
var src =
"https://raw.githubusercontent.com/li-car-fei/hexo-Picture/master/photos/" +
data.link[i];
var type = data.type[i];
var target = src + (type === "video" ? ".mp4" : ".jpg");
src += "";
liTmpl +=
'<figure class="thumb" itemprop="associatedMedia" itemscope="" itemtype="http://schema.org/ImageObject">\
<a href="' +
src +
'" itemprop="contentUrl" data-size="1080x1080" data-type="' +
type +
'" data-target="' +
src +
'">\
<img class="reward-img" data-type="' +
type +
'" data-src="' +
minSrc +
'" src="/assets/img/empty.png" itemprop="thumbnail" οnlοad="lzld(this)">\
</a>\
<figcaption style="display:none" itemprop="caption description">' +
data.text[i] +
"</figcaption>\
</figure>";
}
修改先前存好的 tool.py 文件
with open("../Hexo/source/photos/data.json","w",encoding='utf-8') as fp:
json.dump(final_dict, fp,ensure_ascii=False)
执行 python 文件
目的是裁剪压缩照片,自动生成缩略图,并且在博客目录下的/source/photos/文件夹下生成 data.json 文件,同时利用 git 指令将文件夹里的东西上传到 github 仓库。每次修改图片都要执行一次。
最重要的是,保存在 photos 文件夹里面的图片需要遵循命名规则:2019-10-10_照片名称.jpg
修改 hosts 域名
由于域名访问限制,导致 github 上缓存的图片无法正常加载
我们需要打开路径 C:\Windows\System32\drivers\etc 下的 hosts 文件
在后面加上
# GitHub Start
192.30.253.112 github.com
192.30.253.119 gist.github.com
151.101.184.133 assets-cdn.github.com
151.101.184.133 raw.githubusercontent.com
151.101.184.133 gist.githubusercontent.com
151.101.184.133 cloud.githubusercontent.com
151.101.184.133 camo.githubusercontent.com
151.101.184.133 avatars0.githubusercontent.com
151.101.184.133 avatars1.githubusercontent.com
151.101.184.133 avatars2.githubusercontent.com
151.101.184.133 avatars3.githubusercontent.com
151.101.184.133 avatars4.githubusercontent.com
151.101.184.133 avatars5.githubusercontent.com
151.101.184.133 avatars6.githubusercontent.com
151.101.184.133 avatars7.githubusercontent.com
151.101.184.133 avatars8.githubusercontent.com
# GitHub End
没有管理权限就把文件复制重新创一个文件~ 再复制粘贴
总结
踩坑难受,希望能帮到大家哦