mirror of
				https://github.com/hwchase17/langchain.git
				synced 2025-10-30 23:29:54 +00:00 
			
		
		
		
	docs: frontmatter gen, colab/github links (#28852)
This commit is contained in:
		| @@ -143,16 +143,22 @@ def _modify_frontmatter( | |||||||
|     edit_url = ( |     edit_url = ( | ||||||
|         f"https://github.com/langchain-ai/langchain/edit/master/docs/docs/{rel_path}" |         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 re.match(r"^[\s\n]*---\n", body): | ||||||
|         # if custom_edit_url already exists, leave it |         # frontmatter already present | ||||||
|         if re.match(r"custom_edit_url: ", body): |  | ||||||
|             return body |         for k, v in frontmatter.items(): | ||||||
|         else: |             # if key already exists, leave it | ||||||
|             return re.sub( |             if re.match(f"{k}: ", body): | ||||||
|                 r"^[\s\n]*---\n", f"---\ncustom_edit_url: {edit_url}\n", body, count=1 |                 continue | ||||||
|             ) |             else: | ||||||
|  |                 body = re.sub(r"^[\s\n]*---\n", f"---\n{k}: {v}\n", body, count=1) | ||||||
|  |         return body | ||||||
|     else: |     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( | def _convert_notebook( | ||||||
|   | |||||||
							
								
								
									
										85
									
								
								docs/src/theme/DocItem/Layout/index.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										85
									
								
								docs/src/theme/DocItem/Layout/index.js
									
									
									
									
									
										Normal file
									
								
							| @@ -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 ? <DocItemTOCMobile /> : undefined; | ||||||
|  |   const desktop = | ||||||
|  |     canRender && (windowSize === 'desktop' || windowSize === 'ssr') ? ( | ||||||
|  |       <DocItemTOCDesktop /> | ||||||
|  |     ) : 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 ( | ||||||
|  |     <div className="row"> | ||||||
|  |       <div className={clsx('col', !docTOC.hidden && styles.docItemCol)}> | ||||||
|  |         <ContentVisibility metadata={metadata} /> | ||||||
|  |         <DocVersionBanner /> | ||||||
|  |         <div className={styles.docItemContainer}> | ||||||
|  |           <article> | ||||||
|  |             <DocBreadcrumbs /> | ||||||
|  |             <DocVersionBadge /> | ||||||
|  |             {docTOC.mobile} | ||||||
|  |             <div style={{  | ||||||
|  |               display: "flex",  | ||||||
|  |               flexDirection: "column", | ||||||
|  |               alignItems: "flex-end", | ||||||
|  |               float: "right", | ||||||
|  |             }}> | ||||||
|  |               {linkColab && (<a target="_blank" href={linkColab}> | ||||||
|  |                 <img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/> | ||||||
|  |               </a>)} | ||||||
|  |               {linkGithub && (<a href={linkGithub} target="_blank"> | ||||||
|  |                 <img src="https://img.shields.io/badge/Open%20on%20GitHub-grey?logo=github&logoColor=white"  | ||||||
|  |                     alt="Open on GitHub" /> | ||||||
|  |               </a>)} | ||||||
|  |             </div> | ||||||
|  |             <DocItemContent>{children}</DocItemContent> | ||||||
|  |             <DocItemFooter /> | ||||||
|  |           </article> | ||||||
|  |           <DocItemPaginator /> | ||||||
|  |         </div> | ||||||
|  |       </div> | ||||||
|  |       {docTOC.desktop && <div className="col col--3">{docTOC.desktop}</div>} | ||||||
|  |     </div> | ||||||
|  |   ); | ||||||
|  | } | ||||||
							
								
								
									
										10
									
								
								docs/src/theme/DocItem/Layout/styles.module.css
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								docs/src/theme/DocItem/Layout/styles.module.css
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,10 @@ | |||||||
|  | .docItemContainer header + *, | ||||||
|  | .docItemContainer article > *:first-child { | ||||||
|  |   margin-top: 0; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | @media (min-width: 997px) { | ||||||
|  |   .docItemCol { | ||||||
|  |     max-width: 75% !important; | ||||||
|  |   } | ||||||
|  | } | ||||||
		Reference in New Issue
	
	Block a user