Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
x1jumping committed Nov 2, 2023
1 parent 7fef5c9 commit 3a23dea
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ freecdn-js能提高网站稳定性,如果其中一个cdn链接不可用则启

只需要把放在github的图片的url(以.xxx结尾,如.png、.css、.js)放在`urls.txt`,每行放一个url,并在同一个文件夹内运行`import_to_db_with_urls_txt.py`,即可生成`custom.conf`(可以用`freecdn manifest --merge $path_to_custom.conf`合并到`freecdn-manifest.txt`),`custom.conf`由几个内置的cdn模板生成。

`url`的格式为`http(s)://cdn/user/repo@your_branch/xxx`。其中`cdn`可以是`cdn.jsdelivr.net/gh/`这种免费cdn。
`url`的格式为`http(s)://cdn/user/repo@your_branch/xxx`。其中`cdn`可以是`cdn.jsdelivr.net/gh/`,`cdn.jsdelivr.net/npm/`这种免费cdn。

`url`的格式也可以为`http(s)://raw.githubusercontent.com/user/repo/your_branch/xxx`。

Expand Down
2 changes: 2 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
blog_md_file_dir = './source/_posts'
blog_public_dir = './public'
blog_deploy_dir ='./.deploy_git'
path_of_url_txt = './urls.txt'
path_of_package_json = ''
#静态文件相对于repo的位置,开头不能有“/”,结尾必须有“/”。如果是在根目录则留空:''
path_of_static_resoure_relative_to_root_of_repo = 'static_source/'
#储存静态文件的GitHub repo信息
Expand Down
6 changes: 3 additions & 3 deletions import_to_db_with_hexo_blog.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def import_html_to_file(self,filename):
print(e, '↓\nurl: '+url)
else:
try:
res_url = f'{user}/{repo}@{branch}/static_source/{filename_encode}'
res_url = f'{user}/{repo}@{branch}/{path_of_static_resoure_relative_to_root_of_repo}{filename_encode}'
self.write_file(url,res_url=res_url,hash256=hash256)
except Exception as e:
print(e, '↓\n[error] in writing file - url: '+url)
Expand All @@ -53,8 +53,8 @@ def run(self):
self.pool.submit(self.get_urls_in_md_file_and_generate, md_file, [re_obj_for_link_tag, re_obj_for_image_tag, re_obj_for_headimg_tag, re_obj_for_pic_tag])
if is_import_html_to_conf:
for filename in os.listdir(f'{blog_public_dir}'):
if not filename in html_file_to_ignore:
if re.match(r'.*\.html', filename):
if re.match(r'.*\.html', filename):
if not filename in html_file_to_ignore:
self.pool.submit(self.import_html_to_file,filename)
self.pool.shutdown()
wait(self.thread_list)
Expand Down
6 changes: 3 additions & 3 deletions import_to_db_with_urls_txt.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def url_split(self, url: str):
param url 为url encode后的url
'''
re_obj = re.compile(
f'http.*?(?:(?<=/gh/)|(?=raw.githubusercontent.com/))(.*)\s*')
f'http.*?(?:(?<=/gh/)|(?=raw.githubusercontent.com/)|(?<=/npm/))(.*)\s*')
res = re_obj.search(url)
if res:
if not 'raw.githubusercontent.com' in res.group(1):
Expand All @@ -83,7 +83,7 @@ def get_latest_version_of_npm_hosting(self):

if npm_name_of_html_package:
try:
with open(os.path.join('./.deploy_git','package.json'),'r',encoding='utf8') as f:
with open(f'{path_of_package_json}','r',encoding='utf8') as f:
self.html_hosting_latest_ver = json.load(f)['version']
except:
r = requests.get(f'https://registry.npmjs.org/{npm_name_of_html_package}',proxies=proxies_dict)
Expand Down Expand Up @@ -189,7 +189,7 @@ def import_url_to_file(self, url):
sqlite3_conn.close()

def run(self):
with open('./urls.txt', 'r', encoding='utf8') as f:
with open(f'{path_of_url_txt}', 'r', encoding='utf8') as f:
try:
self.f_to_w = open(
f'./{self.name_of_conf_to_writ}', 'w', encoding='utf8')
Expand Down

0 comments on commit 3a23dea

Please sign in to comment.