quantii-adaptive-programming/.automate/diagram_create.py

37 lines
764 B
Python

import datetime
generate_hash = hash
def create_diagram(topic, diagram_code):
date = datetime.date.today().strftime("%Y-%m-%d")
hash = generate_hash(datetime.datetime.now().__str__())
filename = f"content/diagrams/{topic}-diagram-{date}-{hash}.md"
with open(filename, 'w') as f:
f.write(f"""---
title: {topic} Diagram
date: {date}
tags: [diagram, {topic}]
---
import DiagramViewer from '@site/src/components/DiagramViewer';
# {topic} Diagram
<DiagramViewer code={{`
{diagram_code}
`}} />
[Additional explanation or notes]
""")
print(f"Created new diagram page: {filename}")
# Usage
create_diagram("UserFlow", """
graph TD
A[Start] --> B{Login?}
B -->|Yes| C[Dashboard]
B -->|No| D[Registration]
D --> C
""")