github+picGo 搭建免费图床

101 阅读1分钟

1.新建一个github仓库

2.获取token

3.[下载安装picGo] (github.com/Molunerfinn…)

4.配置picGo

  1. 在github中自定义域名要写成这样,才可以直接导入其他博客平台 然后才显示图片

    raw.githubusercontent.com/用户名/仓库名/分支

6.配置Typora

7.使用方法

在Typora中 右键图片直接上传,或者直接拉到picGo中上传就行

实战用法之直接导入到博客展示

会可能出现图片不显示问题,外链转存失败
解决方案 将外链url 转成 <img src ="外链">的形式即可
解决工具:python脚本

​
import re
​
old_path = "./old_file.md" //本地路径的写法,这是准备转化的文件路径
new_path = "./new_file.md" //生成的文件
old_file = open(old_path, 'r', encoding='utf-8')
new_file = open(new_path, 'w', encoding='utf-8')
​
old_line = old_file.readline()
count = 0
​
while old_line:
    if "![" in old_line:
        url = re.findall('https://.*png|https://.*jpeg|https://.*jpg', old_line)
        img = '<img src="' + url[0] + '"/>'
        new_line = re.sub('![.*)', img, old_line)
        new_file.write(new_line)
        print(old_line + '   ===>   ' + new_line)
        count += 1
    else:
        new_file.write(old_line)
    old_line = old_file.readline()
​
old_file.close()
new_file.close()
​