updates?
This commit is contained in:
@@ -16,7 +16,8 @@ import json
|
||||
from pathlib import Path
|
||||
import re
|
||||
|
||||
root_dir=Path.joinpath(Path(os.path.dirname(os.path.abspath(__file__))).parent, 'content')
|
||||
cwd = Path(os.path.dirname(os.path.abspath(__file__)))
|
||||
root_dir=Path.joinpath(cwd.parent, 'content')
|
||||
# consider each subdirectory as a course
|
||||
sub_dirs=os.listdir(root_dir)
|
||||
# exclude .md and _meta.js
|
||||
@@ -33,14 +34,16 @@ course_parse=r":\1\n theme:{\n timestamp: true,\n }\n \2"
|
||||
|
||||
# copy new _meta.js
|
||||
for sub_dir in sub_dirs:
|
||||
sub_meta_file=os.path.join(root_dir, sub_dir, '_meta.js')
|
||||
sub_meta_file=os.path.join(cwd, sub_dir, '_meta.js')
|
||||
full_text=Path(meta_file).read_text()
|
||||
matches=re.findall(course_match, full_text)
|
||||
new_text=re.sub(course_match, link_parse, full_text)
|
||||
print(f'parsed link file: {new_text}')
|
||||
cur_link_match=repr(sub_dir+link_match)
|
||||
cur_course_match=repr(sub_dir+course_parse)
|
||||
cur_link_match=r'{}{}'.format(sub_dir,link_match)
|
||||
cur_course_match=r'{}{}'.format(sub_dir,course_parse)
|
||||
print(f'new reg: {cur_link_match}, {cur_course_match}')
|
||||
new_text=re.sub(link_match, cur_link_match, new_text)
|
||||
new_text=re.sub(cur_link_match, cur_course_match, new_text)
|
||||
print (f'parsed course file: {new_text}')
|
||||
# Path(sub_meta_file).write_text(new_text)
|
||||
# create directory if not exist
|
||||
Path(sub_meta_file).parent.mkdir(parents=True, exist_ok=True)
|
||||
Path(sub_meta_file).write_text(new_text)
|
||||
|
||||
Reference in New Issue
Block a user