21 lines
840 B
Python
21 lines
840 B
Python
|
import os
|
||
|
|
||
|
def fix_frontmatter(directory):
|
||
|
for root, _, files in os.walk(directory):
|
||
|
for file in files:
|
||
|
if file.endswith('.md'):
|
||
|
file_path = os.path.join(root, file)
|
||
|
with open(file_path, 'r+', encoding='utf-8') as f:
|
||
|
content = f.read()
|
||
|
# 检查文件开头是否缺少 '---'
|
||
|
if not content.startswith('---'):
|
||
|
# 在开头添加 '---'
|
||
|
fixed_content = '---\n' + content
|
||
|
f.seek(0)
|
||
|
f.write(fixed_content)
|
||
|
print(f"Fixed frontmatter in: {file_path}")
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
hexo_posts_dir = '/home/songtianlun/Sync/Develop/frytea/source/_posts' # Hexo 文章目录
|
||
|
fix_frontmatter(hexo_posts_dir)
|