Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
x1jumping committed Oct 13, 2023
1 parent f5b9c1b commit 7fef5c9
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
8 changes: 5 additions & 3 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'
#静态文件相对于repo的位置,开头不能有“/”,结尾必须有“/”。如果是在根目录则留空:''
path_of_static_resoure_relative_to_root_of_repo = 'static_source/'
#储存静态文件的GitHub repo信息
user = ''
repo = ''
Expand All @@ -18,15 +20,15 @@
'github': ['https://jsd.cdn.zzko.cn/gh/', 'https://cdn.jsdelivr.us/gh/',
'https://cdn.jsdelivr.ren/gh/', 'https://cdn.jsdelivr.net/gh/'],
'raw': ['https://raw.githubusercontent.com/'],
"npm": ['https://npm.onmicrosoft.cn/','https://jsd.onmicrosoft.cn/npm/','https://cdn.jsdelivr.net/npm/','https://unpkg.com/']
"npm": ['https://npm.onmicrosoft.cn/','https://jsd.cdn.zzko.cn/npm/','https://jsd.onmicrosoft.cn/npm/','https://cdn.jsdelivr.net/npm/']
}

is_output_to_txt = False #输出md文件中的url到txt文件urls_in_md.txt

is_import_html_to_conf = True #导入“blog_public_dir”中的html到pic.conf
is_import_html_to_conf = False #导入“blog_public_dir”中的html到pic.conf
html_file_to_ignore = ['']

is_use_proxy = True
is_use_proxy = False
if is_use_proxy:
proxies_dict = {'http': 'socks5://127.0.0.1:10808',
'https': 'socks5://127.0.0.1:10808'}
Expand Down
10 changes: 5 additions & 5 deletions generate_external_manifest_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,21 +93,21 @@ def CalcFileSha256_with_base64(filname):

def main():
os.chdir(sys.path[0]) # os.chdir(sys.path[0])把当前py文件所在路径设置为当前运行路径.
with open(os.path.join(f'.\{blog_deploy_dir}', 'freecdn-manifest.txt'), 'w', encoding='utf8') as f:
with open(os.path.join(f'{blog_deploy_dir}/{path_of_static_resoure_relative_to_root_of_repo}', 'freecdn-manifest.txt'), 'w', encoding='utf8') as f:
hash256 = CalcFileSha256_with_base64(
os.path.join(f'.\{blog_deploy_dir}', 'manifest-full.txt'))
os.path.join(f'{blog_deploy_dir}/{path_of_static_resoure_relative_to_root_of_repo}', 'manifest-full.txt'))
f.write('/manifest-full.txt')
if is_refresh_tag:
post_new_release()
for k,v in cdn_list.items():
for cdn in v:
if k == 'github':
if is_refresh_tag:
f.write(f'\n\t{cdn}{user}/{repo}@{branch_sha}/manifest-full.txt')
f.write(f'\n\t{cdn}{user}/{repo}@{branch_sha}/{path_of_static_resoure_relative_to_root_of_repo}manifest-full.txt')
else:
f.write(f'\n\t{cdn}{user}/{repo}@{branch}/manifest-full.txt')
f.write(f'\n\t{cdn}{user}/{repo}@{branch}/{path_of_static_resoure_relative_to_root_of_repo}manifest-full.txt')
elif k == 'raw':
f.write(f'\n\t{cdn}{user}/{repo}/{branch}/manifest-full.txt')
f.write(f'\n\t{cdn}{user}/{repo}/{branch}/{path_of_static_resoure_relative_to_root_of_repo}manifest-full.txt')
f.write(f'\n\thash={hash256}')
f.write('\n@include\n\t/manifest-full.txt\n@global\n\topen_timeout=0s')
print('[success] manifest_file generaeted.')
Expand Down
2 changes: 1 addition & 1 deletion 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}/{filename_encode}'
res_url = f'{user}/{repo}@{branch}/static_source/{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 Down
12 changes: 8 additions & 4 deletions import_to_db_with_urls_txt.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import requests
import hashlib
import base64
import sqlite3
import sqlite3,json
from config import *
os.chdir(sys.path[0]) # os.chdir(sys.path[0])把当前py文件所在路径设置为当前运行路径.

Expand Down Expand Up @@ -82,9 +82,13 @@ def get_latest_version_of_npm_hosting(self):
self.pic_bed_hosting_latest_ver = r.json()["dist-tags"]["latest"]

if npm_name_of_html_package:
r = requests.get(f'https://registry.npmjs.org/{npm_name_of_html_package}',proxies=proxies_dict)
if r.status_code == 200:
self.html_hosting_latest_ver = r.json()["dist-tags"]["latest"]
try:
with open(os.path.join('./.deploy_git','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)
if r.status_code == 200:
self.html_hosting_latest_ver = r.json()["dist-tags"]["latest"]

def CalcFileSha256_with_base64(self, filname):
''' calculate file sha256 '''
Expand Down

0 comments on commit 7fef5c9

Please sign in to comment.