Skip to content

Commit

Permalink
feat: Include component
Browse files Browse the repository at this point in the history
  • Loading branch information
andrii-bodnar committed Jul 9, 2024
1 parent 9023e6c commit b8ea1ad
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
8 changes: 8 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ There are a couple of custom components in this project that you can use:
<FormatsBanner />
```

- `Include` - A component that allows you to include content from another file. It's useful when you want to reuse content across multiple pages.

```mdx
import Include from '~/components/Include.astro';

<Include file="file.mdx" />
```

## Icons

You can use Starlight's [`Icon`](https://starlight.astro.build/guides/components/#icon) component. It provides some basic set of icons.
Expand Down
22 changes: 22 additions & 0 deletions src/components/Include.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
interface Props {
file: string;
}
const { file } = Astro.props;
// Look up all the Markdown files in the includes folder.
// TODO: handle current locale
const includes = import.meta.glob('../content/includes/**/*.mdx');
// Find the file that matches the passed `file` prop.
const loader = includes[`../content/includes/${file}`];
if (!loader) {
throw new Error(`Could not find \`${file}\`.`)
}
const { Content } = await loader() as any;
---

<Content />
Empty file added src/content/includes/.gitkeep
Empty file.

0 comments on commit b8ea1ad

Please sign in to comment.