-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
31 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
# Created Date: Monday, June 17th 2024 | ||
# Author: Zihan | ||
# ----- | ||
# Last Modified: Monday, 17th June 2024 7:59:27 pm | ||
# Last Modified: Friday, 21st June 2024 12:24:20 am | ||
# Modified By: the developer formerly known as Zihan at <[email protected]> | ||
# ----- | ||
# HISTORY: | ||
|
@@ -18,19 +18,34 @@ | |
md_files = glob.glob('**/*.md', recursive=True) | ||
|
||
# Comment to be added | ||
# comment = '''--- | ||
# toc: true | ||
# documentclass: "ctexart" | ||
# classoption: "UTF8" | ||
# --- | ||
# ''' | ||
comment = '''--- | ||
toc: true | ||
documentclass: "ctexart" | ||
classoption: "UTF8" | ||
--- | ||
''' | ||
|
||
comment_2 = '''--- | ||
toc: true | ||
documentclass: "ctexart" | ||
classoption: "UTF8" | ||
''' | ||
|
||
# Add the comment to each file | ||
# for file in md_files: | ||
# with open(file, 'r+') as f: | ||
# content = f.read() | ||
# f.seek(0, 0) | ||
# f.write(comment + content) | ||
for file in md_files: | ||
with open(file, 'r+') as f: | ||
content = f.read() | ||
# if already has ctexart comment, then skip | ||
if 'documentclass: "ctexart"' in content: | ||
continue | ||
f.seek(0, 0) | ||
# f.write(comment + content) | ||
# if the first line is '---', then remove the first line and add the comment_2 | ||
if content.startswith('---'): | ||
content = content[content.find('\n') + 1:] # remove the first line | ||
f.write(comment_2 + content) | ||
else: | ||
f.write(comment + content) | ||
|
||
# delete first blank lines | ||
# for file in md_files: | ||
|
@@ -43,10 +58,10 @@ | |
# f.truncate() | ||
|
||
# substitute all space in file name with '_' | ||
for file in md_files: | ||
new_file = file.replace(' ', '_') | ||
print(f'Renaming {file} to {new_file}') | ||
os.rename(file, new_file) | ||
# for file in md_files: | ||
# new_file = file.replace(' ', '_') | ||
# print(f'Renaming {file} to {new_file}') | ||
# os.rename(file, new_file) | ||
|
||
# also for foler name | ||
# folders = glob.glob('**/', recursive=True) | ||
|