diff --git a/utils/genIndex.py b/utils/genIndex.py index 1c30d2c..544aade 100644 --- a/utils/genIndex.py +++ b/utils/genIndex.py @@ -1,19 +1,19 @@ #coding: utf-8 import os import re +from functools import partial import markdown import shutil from getSize import getSize from config import PATH, HTML, WALKDIR, TARDIR, IGNORE, NAME, DOWNLOAD URL = 'https://github.com/USTC-Resource/USTC-Course/tree/master/' -ImagePre = '' ImagePT = re.compile(r'\!\[(.*?)\]\(([a-zA-Z\d\.].*?)\)') -def subFunc(match): +def subFunc(match,pre): name, suf = match.groups() - return f'![{name}]({ImagePre+"/"+suf})' + return f'![{name}]({pre+"/"+suf})' hasPinyin = False try: @@ -130,8 +130,7 @@ def genIndex(path, dirs, files, htmlTemp=HTML): readme=md2html(md)) filename = os.path.join(tar, NAME) with open(filename, 'w') as f: - ImagePre = URL + path - f.write(re.sub(ImagePT,subFunc,cont)) + f.write(re.sub(ImagePT,partial(subFunc,pre = URL+path),cont)) def getPath(path):