前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >jsdelivr加速Github文件 - plus studio

jsdelivr加速Github文件 - plus studio

作者头像
plus sign
发布2024-02-28 21:25:23
920
发布2024-02-28 21:25:23
举报
文章被收录于专栏:个人博客个人博客

假设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路径

代码语言:text
复制
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(""))
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2023-1-20,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档