简书图床迁移至github
发现hexo博客的图片全部不能访问了,笔者当时使用的是简书的图床(直接在简书编辑完成拷贝过来就可以了),折腾了一下图床的迁移
获取所有原链接
1
2cd /dscoder/source/_posts # dscoder是笔者的hexo根目录
cat ./* |grep upload-images.jianshu.io > image.txt # 将所有的图片放到Image.txt目录中把image.txt文件从服务器上拿下来,大部分跟下面类似,我们对数据进行一个清洗
1 | ![](https://raw.githubusercontent.com/gengzongyuan/imagePackage/master/imagePackage/2572206-2c0492626bb40e4a.png) |
把图片下载下来,这里笔者借助python实现
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18import requests
def downloadImg(url,fileName):
requests.packages.urllib3.disable_warnings()
res = requests.get(url,verify=False)
with open('img/'+fileName,'wb') as fw:
fw.write(res.content)
s = set()
with open("image.txt") as fr :
for line in fr.readlines():
line = line.replace("\n","")
s.add(line)
print("不重复的数据量为:",len(s))
for url in s:
print(url.split("/")[4].split("?")[0])
downloadImg(url,url.split("/")[4].split("?")[0])讲下载的图片上传到Github任意一个项目中
1
2
3
4
5这里我们看一下github的图片url
https://github.com/gengzongyuan/imagePackage/blob/master/imagePackage/2572206-0269206dfb7f475f.png
简书的图片地址是
https://upload-images.jianshu.io/upload_images/2572206-0269206dfb7f475f.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240链接替换
1
2
3
4
5
6
7最后一步,我们直接把链接通过sed命令把所有的文件链接都替换掉就可以了
sed -i "s/https:\/\/upload-images.jianshu.io\/upload_images\//https:\/\/raw.githubusercontent.com\/gengzongyuan\/imagePackage\/master\/imagePackage\//" ./*
sed -i "s/http:\/\/upload-images.jianshu.io\/upload_images\//https:\/\/raw.githubusercontent.com\/gengzongyuan\/imagePackage\/master\/imagePackage\//" ./*
sed -i "s/\?imageMogr2\/auto-orient\/strip\%7CimageView2\/2\/w\/120//" ./*
sed -i "s/\?imageMogr2\/auto-orient\/strip\%7CimageView2\/2\/w\/180//" ./*
sed -i "s/\?imageMogr2\/auto-orient\/strip\%7CimageView2\/2\/w\/280//" ./*
sed -i "s/\?imageMogr2\/auto-orient\/strip\%7CimageView2\/2\/w\/1240//" ./*