diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 46906f19..95f45f1a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -24,6 +24,14 @@ There are a couple of custom components in this project that you can use: ``` +- `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'; + + + ``` + ## Icons You can use Starlight's [`Icon`](https://starlight.astro.build/guides/components/#icon) component. It provides some basic set of icons. diff --git a/src/components/Include.astro b/src/components/Include.astro new file mode 100644 index 00000000..a54a3fa5 --- /dev/null +++ b/src/components/Include.astro @@ -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(); +--- + + diff --git a/src/content/includes/.gitkeep b/src/content/includes/.gitkeep new file mode 100644 index 00000000..e69de29b