Skip to content

Commit e047b1e

Browse files
cmpaddendehume
andauthored
[docs-beta] support path prefix for tutorial snippets (#26792)
## Summary & Motivation - Adds support for `pathPrefix` in `CodeExample` component This allows us to use examples that are outside of the `docs_beta_snippets` folder, for example, `examples/tutorial_pinecone`. Tutorial was updated to demonstrate how this can be used: ``` <CodeExample pathPrefix="tutorial_pinecone/tutorial_pinecone" filePath="assets.py" lineStart="22" lineEnd ="60" /> ``` ## How I Tested These Changes ``` yarn dev ``` ## Changelog NOCHANGELOG --------- Co-authored-by: Dennis Hume <[email protected]>
1 parent 867bceb commit e047b1e

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

docs/docs-beta/src/components/CodeExample.tsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ interface CodeExampleProps {
77
title?: string;
88
lineStart?: number;
99
lineEnd?: number;
10+
pathPrefix?: string;
1011
}
1112

13+
1214
/**
1315
* Removes content below the `if __name__` block for the given `lines`.
1416
*/
@@ -28,20 +30,18 @@ function filterNoqaComments(lines: string[]): string[] {
2830

2931
const CodeExample: React.FC<CodeExampleProps> = ({
3032
filePath,
31-
language,
3233
title,
3334
lineStart,
3435
lineEnd,
36+
language = 'python',
37+
pathPrefix = 'docs_beta_snippets/docs_beta_snippets',
3538
...props
3639
}) => {
3740
const [content, setContent] = React.useState<string>('');
3841
const [error, setError] = React.useState<string | null>(null);
3942

40-
language = language || 'python';
41-
4243
React.useEffect(() => {
43-
// Adjust the import path to start from the docs directory
44-
import(`!!raw-loader!/../../examples/docs_beta_snippets/docs_beta_snippets/${filePath}`)
44+
import(`!!raw-loader!/../../examples/${pathPrefix}/${filePath}`)
4545
.then((module) => {
4646
var lines = module.default.split('\n');
4747

0 commit comments

Comments
 (0)