|
| 1 | +import os |
| 2 | + |
| 3 | +topics_dir = r"c:\Users\santa\Desktop\uet_harness\research_uet\topics" |
| 4 | + |
| 5 | +def update_front_matter(): |
| 6 | + for topic in os.listdir(topics_dir): |
| 7 | + topic_path = os.path.join(topics_dir, topic) |
| 8 | + if os.path.isdir(topic_path): |
| 9 | + readme_path = os.path.join(topic_path, "README.md") |
| 10 | + if os.path.exists(readme_path): |
| 11 | + with open(readme_path, "r", encoding="utf-8") as f: |
| 12 | + content = f.read() |
| 13 | + |
| 14 | + # Check for existing YAML front matter |
| 15 | + if content.startswith("---"): |
| 16 | + # Already has front matter, we need to ensure 'layout: article' is present |
| 17 | + parts = content.split("---", 2) |
| 18 | + if len(parts) >= 3: |
| 19 | + yaml_block = parts[1] |
| 20 | + if "layout:" not in yaml_block: |
| 21 | + yaml_block = "layout: article\n" + yaml_block |
| 22 | + elif "layout: default" in yaml_block: |
| 23 | + yaml_block = yaml_block.replace("layout: default", "layout: article") |
| 24 | + |
| 25 | + new_content = "---" + yaml_block + "---" + parts[2] |
| 26 | + with open(readme_path, "w", encoding="utf-8") as f: |
| 27 | + f.write(new_content) |
| 28 | + print(f"Updated [EXISTING]: {topic}") |
| 29 | + else: |
| 30 | + # No front matter, add it |
| 31 | + title = topic.split("_", 1)[1].replace("_", " ") if "_" in topic else topic |
| 32 | + header = f"---\nlayout: article\ntitle: \"UET Topic {topic.split('_')[0]}: {title}\"\ndescription: \"Research module for {title} within the Unity Equilibrium Theory framework.\"\n---\n\n" |
| 33 | + new_content = header + content |
| 34 | + with open(readme_path, "w", encoding="utf-8") as f: |
| 35 | + f.write(new_content) |
| 36 | + print(f"Added [NEW]: {topic}") |
| 37 | + |
| 38 | +if __name__ == "__main__": |
| 39 | + update_front_matter() |
0 commit comments