Skip to content

Commit

Permalink
[docs-beta] support path prefix for tutorial snippets (#26792)
Browse files Browse the repository at this point in the history
## 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]>
  • Loading branch information
cmpadden and dehume authored Jan 3, 2025
1 parent 867bceb commit e047b1e
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions docs/docs-beta/src/components/CodeExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ interface CodeExampleProps {
title?: string;
lineStart?: number;
lineEnd?: number;
pathPrefix?: string;
}


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

const CodeExample: React.FC<CodeExampleProps> = ({
filePath,
language,
title,
lineStart,
lineEnd,
language = 'python',
pathPrefix = 'docs_beta_snippets/docs_beta_snippets',
...props
}) => {
const [content, setContent] = React.useState<string>('');
const [error, setError] = React.useState<string | null>(null);

language = language || 'python';

React.useEffect(() => {
// Adjust the import path to start from the docs directory
import(`!!raw-loader!/../../examples/docs_beta_snippets/docs_beta_snippets/${filePath}`)
import(`!!raw-loader!/../../examples/${pathPrefix}/${filePath}`)
.then((module) => {
var lines = module.default.split('\n');

Expand Down

1 comment on commit e047b1e

@github-actions
Copy link

@github-actions github-actions bot commented on e047b1e Jan 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploy preview for dagster-docs-beta ready!

✅ Preview
https://dagster-docs-beta-n16l67jsj-elementl.vercel.app

Built with commit e047b1e.
This pull request is being automatically deployed with vercel-action

Please sign in to comment.