forked from langchain-ai/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_mdx.py
More file actions
35 lines (28 loc) · 1.15 KB
/
update_mdx.py
File metadata and controls
35 lines (28 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import glob
def update_mdx_files():
# Get all MDX files in the specified directories
mdx_files = []
for root in ["oss", "langsmith", "langgraph-platform"]:
mdx_files.extend(glob.glob(f"{root}/**/*.mdx", recursive=True))
for file_path in mdx_files:
try:
with open(file_path) as f:
content = f.read()
# Only add if the placeholder heading is not already present
if "## Placeholder heading" not in content:
# Add the placeholder heading and text after the first heading
if "# " in content:
parts = content.split("# ", 1)
new_content = (
parts[0]
+ "# "
+ parts[1]
+ "\n\n## Placeholder heading\n\nThis is an example"
)
with open(file_path, "w") as f:
f.write(new_content)
print(f"Updated {file_path}")
except Exception as e:
print(f"Error processing {file_path}: {e!s}")
if __name__ == "__main__":
update_mdx_files()