From 98896bd67d798747fa3f9b6a8a9902c1daf78051 Mon Sep 17 00:00:00 2001 From: Erick Friis Date: Fri, 20 Dec 2024 13:03:10 -0500 Subject: [PATCH 1/3] docs: frontmatter gen --- docs/scripts/notebook_convert.py | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/docs/scripts/notebook_convert.py b/docs/scripts/notebook_convert.py index 429734f115817..f93a1dd0b60a1 100644 --- a/docs/scripts/notebook_convert.py +++ b/docs/scripts/notebook_convert.py @@ -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( From ff3ff8a1029a8936c75c9e2db9e6e1a887ff38b7 Mon Sep 17 00:00:00 2001 From: Erick Friis Date: Sat, 21 Dec 2024 12:11:52 -0500 Subject: [PATCH 2/3] x --- docs/src/theme/DocItem/Layout/index.js | 85 +++++++++++++++++++ .../theme/DocItem/Layout/styles.module.css | 10 +++ 2 files changed, 95 insertions(+) create mode 100644 docs/src/theme/DocItem/Layout/index.js create mode 100644 docs/src/theme/DocItem/Layout/styles.module.css diff --git a/docs/src/theme/DocItem/Layout/index.js b/docs/src/theme/DocItem/Layout/index.js new file mode 100644 index 0000000000000..768e65112d284 --- /dev/null +++ b/docs/src/theme/DocItem/Layout/index.js @@ -0,0 +1,85 @@ +import React from 'react'; +import clsx from 'clsx'; +import {useWindowSize} from '@docusaurus/theme-common'; +import {useDoc} from '@docusaurus/plugin-content-docs/client'; +import DocItemPaginator from '@theme/DocItem/Paginator'; +import DocVersionBanner from '@theme/DocVersionBanner'; +import DocVersionBadge from '@theme/DocVersionBadge'; +import DocItemFooter from '@theme/DocItem/Footer'; +import DocItemTOCMobile from '@theme/DocItem/TOC/Mobile'; +import DocItemTOCDesktop from '@theme/DocItem/TOC/Desktop'; +import DocItemContent from '@theme/DocItem/Content'; +import DocBreadcrumbs from '@theme/DocBreadcrumbs'; +import ContentVisibility from '@theme/ContentVisibility'; +import styles from './styles.module.css'; +/** + * Decide if the toc should be rendered, on mobile or desktop viewports + */ +function useDocTOC() { + const {frontMatter, toc} = useDoc(); + const windowSize = useWindowSize(); + const hidden = frontMatter.hide_table_of_contents; + const canRender = !hidden && toc.length > 0; + const mobile = canRender ? : undefined; + const desktop = + canRender && (windowSize === 'desktop' || windowSize === 'ssr') ? ( + + ) : undefined; + return { + hidden, + mobile, + desktop, + }; +} +export default function DocItemLayout({children}) { + const docTOC = useDocTOC(); + const {metadata, frontMatter} = useDoc(); + + "https://github.com/langchain-ai/langchain/blob/master/docs/docs/introduction.ipynb" + "https://colab.research.google.com/github/langchain-ai/langchain/blob/master/docs/docs/introduction.ipynb" + + console.log({metadata, frontMatter}) + + const linkColab = frontMatter.link_colab || ( + metadata.editUrl?.endsWith(".ipynb") + ? metadata.editUrl?.replace("https://github.com/langchain-ai/langchain/edit/", "https://colab.research.google.com/github/langchain-ai/langchain/blob/") + : null + ); + const linkGithub = frontMatter.link_github || metadata.editUrl?.replace("/edit/", "/blob/"); + + console.log({linkColab, linkGithub}) + + return ( +
+
+ + +
+
+ + + {docTOC.mobile} +
+ {linkColab && ( + Open In Colab + )} + {linkGithub && ( + Open on GitHub + )} +
+ {children} + +
+ +
+
+ {docTOC.desktop &&
{docTOC.desktop}
} +
+ ); +} diff --git a/docs/src/theme/DocItem/Layout/styles.module.css b/docs/src/theme/DocItem/Layout/styles.module.css new file mode 100644 index 0000000000000..d5aaec1322c92 --- /dev/null +++ b/docs/src/theme/DocItem/Layout/styles.module.css @@ -0,0 +1,10 @@ +.docItemContainer header + *, +.docItemContainer article > *:first-child { + margin-top: 0; +} + +@media (min-width: 997px) { + .docItemCol { + max-width: 75% !important; + } +} From 488c45517963b1e3e0e81db528e6cd49f93d3fda Mon Sep 17 00:00:00 2001 From: Erick Friis Date: Sat, 21 Dec 2024 12:29:34 -0500 Subject: [PATCH 3/3] x --- docs/scripts/notebook_convert.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/docs/scripts/notebook_convert.py b/docs/scripts/notebook_convert.py index f93a1dd0b60a1..fb0e3c807561d 100644 --- a/docs/scripts/notebook_convert.py +++ b/docs/scripts/notebook_convert.py @@ -154,9 +154,7 @@ def _modify_frontmatter( if re.match(f"{k}: ", body): continue else: - body = re.sub( - r"^[\s\n]*---\n", f"---\n{k}: {v}\n", body, count=1 - ) + body = re.sub(r"^[\s\n]*---\n", f"---\n{k}: {v}\n", body, count=1) return body else: insert = "\n".join([f"{k}: {v}" for k, v in frontmatter.items()])