jsdelivr加速Github文件

假设GitHub路径为https://github.com/username/repo-name/path/to/file ,用jsdelivr可以加速或者在html中引用,路径为https://cdn.jsdelivr.net/gh/username/repo-name/path/to/file

这里实现了一个简单的链接转换函数,可以将GitHub路径转换为jsdelivr路径

1
2
3
4
5
6
7
8
9
10
11
12
13
def find_first_occurrence(string, substring):
return string.find(substring)
def gh_path2jsdelivr(path):
if(find_first_occurrence(path,"/blob/") != -1):
path = path.replace("/blob/", "/")
if(find_first_occurrence(path,"/main/") != -1):
path = path.replace("/main/", "/")
if(find_first_occurrence(path,"/master/") != -1):
path = path.replace("/master/", "/")
return path.replace("github.com", "cdn.jsdelivr.net/gh", 1)

print(gh_path2jsdelivr(""))


jsdelivr加速Github文件
https://studyinglover.com/2023/01/20/jsdelivr加速Github文件/
作者
StudyingLover
发布于
2023年1月20日
许可协议