Skip to content

Commit 1805db6

Browse files
Create element type pages from .yaml
1 parent e9d55c8 commit 1805db6

File tree

9 files changed

+94
-3
lines changed

9 files changed

+94
-3
lines changed

elements/.gitkeep

Whitespace-only changes.

functions/.gitkeep

Whitespace-only changes.

web/astro.config.mjs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@
22
import { defineConfig } from 'astro/config';
33
import starlight from '@astrojs/starlight';
44
import mtasaStarlightThemePlugin from '@multitheftauto/starlight-theme-mtasa';
5+
import starlightLinksValidator from 'starlight-links-validator'
56

67
// https://astro.build/config
78
export default defineConfig({
89
integrations: [
910
starlight({
10-
plugins: [ mtasaStarlightThemePlugin() ],
11+
plugins: [
12+
mtasaStarlightThemePlugin(),
13+
starlightLinksValidator(),
14+
],
1115
favicon: 'favicon.ico',
1216
title: 'Multi Theft Auto: Wiki',
1317
logo: {

web/package-lock.json

Lines changed: 43 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

web/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"@astrojs/starlight": "^0.31.1",
1414
"@multitheftauto/starlight-theme-mtasa": "^1.2.0",
1515
"astro": "^5.1.5",
16-
"sharp": "^0.32.5"
16+
"sharp": "^0.32.5",
17+
"starlight-links-validator": "^0.14.2"
1718
}
1819
}

web/src/content.config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import { defineCollection } from 'astro:content';
22
import { docsLoader } from '@astrojs/starlight/loaders';
33
import { docsSchema } from '@astrojs/starlight/schema';
4+
import { glob } from 'astro/loaders';
45

56
export const collections = {
67
docs: defineCollection({ loader: docsLoader(), schema: docsSchema() }),
8+
elements: defineCollection({
9+
loader: glob({ pattern: "**/*.yaml", base: "../elements" }),
10+
}),
711
};

web/src/content/docs/404.mdx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
title: 'Page not found (404)'
3+
template: splash
4+
editUrl: false
5+
hero:
6+
title: 'Page not found'
7+
tagline: Error 404. Check the URL or try using the search bar.
8+
---

web/src/pages/Element/[id].astro

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
import StarlightPage from '@astrojs/starlight/components/StarlightPage.astro';
3+
import { getCollection, render } from 'astro:content';
4+
// 1. Generate a new path for every collection entry
5+
export async function getStaticPaths() {
6+
const elements = await getCollection('elements');
7+
return elements.map(element => ({
8+
params: { id: element.id },
9+
props: { element },
10+
}));
11+
}
12+
// 2. For your template, you can get the entry directly from the prop
13+
const { element } = Astro.props;
14+
const { Content } = await render(element);
15+
---
16+
<StarlightPage frontmatter={{ title: element.data.name }}>
17+
<p>TODO</p>
18+
<Content />
19+
</StarlightPage>

web/src/pages/Element/index.astro

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
import StarlightPage from '@astrojs/starlight/components/StarlightPage.astro';
3+
import { getCollection } from 'astro:content';
4+
const elements = await getCollection('elements');
5+
---
6+
<StarlightPage frontmatter={{ title: 'Element types' }}>
7+
<p>An <strong>element</strong> is a generic class that can represent almost all in-game entities. The built-in element types are:</p>
8+
<ul>
9+
{elements.map(element => (
10+
<li><a href={`/Element/${element.id}`}>{element.data.name}</a></li>
11+
))}
12+
</ul>
13+
</StarlightPage>

0 commit comments

Comments
 (0)