newtheme #4
|
@ -19,7 +19,7 @@ def cli():
|
|||
def fix_post_types(folder: str, old_type: str, new_type: str):
|
||||
"""Fix post type metadata"""
|
||||
|
||||
for root, dirs, files in os.walk(folder):
|
||||
for root, _, files in os.walk(folder):
|
||||
|
||||
for file in files:
|
||||
if file.endswith(".md"):
|
||||
|
@ -40,7 +40,27 @@ def fix_post_types(folder: str, old_type: str, new_type: str):
|
|||
frontmatter.dump(data, f)
|
||||
|
||||
|
||||
@cli.command()
|
||||
@click.option("--folder", type=click.Path(dir_okay=True, file_okay=False), required=True)
|
||||
@click.option("--page_meta", type=str, help="comma separated list of fields to include in page meta", required=True)
|
||||
def set_page_meta(folder: str, page_meta: str):
|
||||
|
||||
meta = page_meta.split(",")
|
||||
|
||||
for root, _, files in os.walk(folder):
|
||||
|
||||
for file in files:
|
||||
if file.endswith(".md"):
|
||||
full_path = os.path.join(root,file)
|
||||
data = frontmatter.load(full_path)
|
||||
|
||||
print(f"Update page_meta for {full_path}: {meta}")
|
||||
if 'page_meta' in data:
|
||||
del data['page_meta']
|
||||
data['post_meta'] = meta
|
||||
|
||||
with open(full_path,'wb') as f:
|
||||
frontmatter.dump(data, f)
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue