Skip to content

Commit

Permalink
docs: frontmatter gen
Browse files Browse the repository at this point in the history
  • Loading branch information
efriis committed Dec 20, 2024
1 parent 6d81137 commit 98896bd
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions docs/scripts/notebook_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,16 +143,24 @@ def _modify_frontmatter(
edit_url = (
f"https://github.com/langchain-ai/langchain/edit/master/docs/docs/{rel_path}"
)
frontmatter = {
"custom_edit_url": edit_url,
}
if re.match(r"^[\s\n]*---\n", body):
# if custom_edit_url already exists, leave it
if re.match(r"custom_edit_url: ", body):
return body
else:
return re.sub(
r"^[\s\n]*---\n", f"---\ncustom_edit_url: {edit_url}\n", body, count=1
)
# frontmatter already present

for k, v in frontmatter.items():
# if key already exists, leave it
if re.match(f"{k}: ", body):
continue
else:
body = re.sub(
r"^[\s\n]*---\n", f"---\n{k}: {v}\n", body, count=1
)
return body
else:
return f"---\ncustom_edit_url: {edit_url}\n---\n{body}"
insert = "\n".join([f"{k}: {v}" for k, v in frontmatter.items()])
return f"---\n{insert}\n---\n{body}"


def _convert_notebook(
Expand Down

0 comments on commit 98896bd

Please sign in to comment.