-
Notifications
You must be signed in to change notification settings - Fork 0
LangGraph migration #109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LangGraph migration #109
Changes from 1 commit
b6f7af0
7cb2833
096ebfc
886f31b
aa17c3e
6dec500
5d56b0b
0f14910
4edbd9e
a8a76fc
9d28a64
ee707bb
137e263
b0f824c
1497152
6a7039f
f264156
3b11d51
c688cd9
2885052
bacb682
eda3b54
437303e
2863e2f
08c1635
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
import json | ||
import logging | ||
import re | ||
import shutil | ||
from pathlib import Path | ||
|
||
|
@@ -52,6 +53,12 @@ def __init__(self, src_dir: Path, build_dir: Path) -> None: | |
".js", | ||
} | ||
|
||
# Mapping of language codes to full names for URLs | ||
self.language_url_names = { | ||
"python": "python", | ||
"js": "javascript", | ||
} | ||
|
||
def build_all(self) -> None: | ||
"""Build all documentation files from source to build directory. | ||
|
||
|
@@ -127,6 +134,39 @@ def _convert_yaml_to_json(self, yaml_file_path: Path, output_path: Path) -> None | |
logger.exception("Failed to convert %s to JSON", yaml_file_path) | ||
raise | ||
|
||
def _rewrite_oss_links(self, content: str, target_language: str | None) -> str: | ||
"""Rewrite /oss/ links to include the target language. | ||
|
||
Args: | ||
content: The markdown content to process. | ||
target_language: Target language ("python" or "js") or None to skip rewriting. | ||
|
||
Returns: | ||
Content with rewritten links. | ||
""" | ||
if not target_language: | ||
return content | ||
|
||
def rewrite_link(match: re.Match) -> str: | ||
"""Rewrite a single link match.""" | ||
pre = match.group(1) # Everything before the URL | ||
url = match.group(2) # The URL | ||
post = match.group(3) # Everything after the URL | ||
|
||
# Only rewrite absolute /oss/ paths | ||
if url.startswith("/oss/"): | ||
parts = url.split("/") | ||
# Insert full language name after "oss" | ||
parts.insert(2, self.language_url_names[target_language]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this deducing the target language from the fenching? what if a link is outside of a fence? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Links work inside and outside of the fencing. I think we kind of pre-set the languages and just swap them out depending on which version of the docs we're building at the time. |
||
url = "/".join(parts) | ||
|
||
return f"{pre}{url}{post}" | ||
|
||
# Match markdown links and HTML links/anchors | ||
# This handles both [text](/oss/path) and <a href="/oss/path"> | ||
pattern = r'(\[.*?\]\(|\bhref="|")(/oss/[^")\s]+)([")\s])' | ||
return re.sub(pattern, rewrite_link, content) | ||
|
||
def _process_markdown_content( | ||
self, content: str, file_path: Path, target_language: str | None = None | ||
) -> str: | ||
|
@@ -144,10 +184,15 @@ def _process_markdown_content( | |
The processed markdown content. | ||
""" | ||
try: | ||
# Apply markdown preprocessing | ||
return preprocess_markdown( | ||
# First apply standard markdown preprocessing | ||
content = preprocess_markdown( | ||
content, file_path, target_language=target_language | ||
) | ||
|
||
# Then rewrite /oss/ links to include language | ||
content = self._rewrite_oss_links(content, target_language) | ||
|
||
return content | ||
except Exception: | ||
logger.exception("Failed to process markdown content from %s", file_path) | ||
raise | ||
|
@@ -577,4 +622,4 @@ def _copy_shared_files(self) -> None: | |
shutil.copy2(file_path, output_path) | ||
copied_count += 1 | ||
|
||
logger.info("✅ Shared files copied: %d files", copied_count) | ||
logger.info("✅ Shared files copied: %d files", copied_count) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noticed that this is also rewriting image paths, which it should ignore
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for flagging this, pushing a fix now!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated preview: https://langchain-5e9cc07a-preview-migrat-1755112825-437303e.mintlify.app/oss/python/overview