Article directory
Yesterday (March 25th) when I was writing notes, I suddenly found that the Gitee map bed was suddenly unusable, and all the Gitee icons were displayed. I was shocked, and then I checked it quickly, and finally I don’t know what happened. Open the picture directly in Gitee to see it, and then ask others in the group to find that many people are like this, but my notes and pictures are all on Gitee, this is not killing me, and then I can only quickly find a way, there are two Solution: Either buy Alibaba Cloud's oss server, or go to Github to continue prostitution. I decided to choose the latter because of tight pockets. The process of applying for a token on Github is similar to that of Gitee, so I will briefly explain it here.
Github import Gitee repository
First, import the Gitee map bed warehouse:
Then copy the image bed link from Gitee, set the new image bed name, then click Import and wait for the import to complete.
Apply for Token
Let's talk about how to apply for Token: 右上叫头像->Setting->进去后滑到最下面,左边Developer settings->Personal access tokens->Generate new token
, then set according to the figure below, and finally slide to the bottom and click Generate token to save the token (it will only be displayed once, if you lose it, you need to apply again next time)
Then open picGo and set it up as shown below
warehouse name:
The branch name can be set to master, the Token has just been applied, the storage path is the image storage path with the current warehouse as the relative path, and the custom domain name is for speeding up access. , https://cdn.jsdelivr.net/gh/你的仓库名
, and then click OK, select Set as default image bed
file path handling
After all the above are completed, you can synchronize your Gitee repository to the GitHub repository, and then process local files. I wrote a py script that can directly convert all the paths of all files in the folder, including subfiles folder, you only need to modify the file path of lines 36, 38, and 40 when using it.
Note that this is directly changed in the original file. If you are worried, you can manually back it up first. After the conversion is complete, if the conversion is complete, delete the backup. I have tried it myself and there is no problem.
import os
import os.path
def trans(files, path):
for file in files:
filepath = os.path.join(path, file)
if os.path.isdir(filepath):
# 如果是文件夹则递归处理
next_files = os.listdir(filepath)
trans(next_files, filepath)
continue
root, ext = os.path.splitext(filepath) # root为文件名,ext为后缀(包括.)
if(ext != ".md"):
# 只处理markdown文件
continue
print("正在处理:", filepath)
source_file_path = filepath
dest_file_path = filepath + ".bak"
# 读入文件修改后写入新文件,然后把原文件删除,把新文件重命名为原文件
with open(source_file_path, encoding='utf-8') as fr, open(dest_file_path, 'w', encoding='utf-8') as fw:
for line in fr:
new_line = line.replace(source_link, dest_link)
fw.write(new_line)
os.remove(source_file_path)
os.rename(dest_file_path, source_file_path)
if __name__ == "__main__":
# 待处理目录,注意这里需要是双反斜杠
basepath = "D:\\blogs"
# 原地址
source_link = "https://gitee.com/qlz-huo/drawing-bed/raw/master"
# 新地址
dest_link = "https://cdn.jsdelivr.net/gh/hQlz/draw-bed"
files = os.listdir(basepath)
# 处理文件
trans(files, basepath)