hexo 集成相册操作

原文博客地址

藤原拓鞋的博客

hexo 基本操作

创建一个新页面

hexo new "my new article"  (引号里为新建博客文章的名字)
执行完就会在source/_posts文件夹下创建对应的.md文件

编译文件

hexo g

启动服务器,执行文件

hexo server
简写 hexo s

部署文件到远端服务器

hexo deploy
简写 hexo d

上传文件到 Github

  1. 在 Github 上新建仓库
  2. 在需要上传的文件夹目录下,运行 git init 初始化 git
  3. 运行 git add 命令,将需要上传的内容放到暂存区
  4. 运行 git commit -m ‘first commit’ 将暂存区的内容放到仓储里面
  5. 运行 git remote add origin https://github.com/li-car-fei…git,将仓储与Github仓库联系起来
  6. 运行 git push origin master 将文件提交到 Github 仓库里面,这样就完成了文件的提交

hexo 相册设置

  1. 下载需要的脚本: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

没有管理权限就把文件复制重新创一个文件~ 再复制粘贴

总结

踩坑难受,希望能帮到大家哦

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值