Skip to content

Commit 34da3fb

Browse files
committed
Support slot data in the ItemDescription & EnhancedMarkdown components
1 parent 5027468 commit 34da3fb

File tree

2 files changed

+31
-12
lines changed

2 files changed

+31
-12
lines changed

web/src/components/EnhancedMarkdown.astro

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,43 @@ import { Code } from '@astrojs/starlight/components';
33
import { marked } from 'marked';
44
55
interface Props {
6-
content: string;
6+
content?: string;
77
inline?: boolean;
88
}
99
1010
const { content, inline = false } = Astro.props;
1111
12+
let slotMarkdown = '';
13+
if (!content && Astro.slots.has('default')) {
14+
slotMarkdown = await Astro.slots.render('default');
15+
}
16+
17+
const rawContent = content ?? slotMarkdown;
18+
19+
if (!rawContent) {
20+
throw new Error('EnhancedMarkdown requires content prop or slot content.');
21+
}
1222
1323
// We shouldn't this as we're now organizing pages in folders
1424
// TODO let's move away from MediaWiki links in the future
1525
1626
function convertMediaWikiLinks(text: string): string {
1727
const redirects: Record<string, string> = {
18-
'ACL': 'acl',
28+
ACL: 'acl',
1929
};
2030
2131
return text.replace(
2232
/\[\[([^|\]#]+)(?:#([^\]]+))?(?:\|([^\]]+))?\]\]/g,
2333
(_, link, hash, text) => {
24-
const redirectedLink = redirects[link] ?? link;
25-
const url = `/reference/${redirectedLink}${hash ? `#${hash}` : ''}`;
34+
const redirected = redirects[link] ?? link;
35+
const url = `/reference/${redirected}${hash ? `#${hash}` : ''}`;
2636
return `[${text || link}](${url})`;
2737
}
2838
);
2939
}
3040
31-
const processedContent = convertMediaWikiLinks(content);
32-
const tokens = inline ? marked.Lexer.lexInline(processedContent) : marked.lexer(processedContent);
41+
const processed = convertMediaWikiLinks(rawContent);
42+
const tokens = inline ? marked.Lexer.lexInline(processed) : marked.lexer(processed);
3343
---
3444

3545
{

web/src/components/ItemDescription.astro

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,33 @@ import EnhancedMarkdown from './EnhancedMarkdown.astro';
33
import { SITE_CONTRIBUTING_URL } from '@src/content.constants';
44
55
interface Props {
6-
description: string;
6+
description?: string;
77
requiresReview?: boolean;
88
}
99
1010
const { description, requiresReview = false } = Astro.props;
1111
1212
let path = Astro.url.pathname;
13-
// Remove trailing slash if any
1413
path = path.endsWith('/') ? path.slice(0, -1) : path;
15-
// Also remove anything before the last slash, effectively removing folders
1614
path = path.substring(path.lastIndexOf('/'));
15+
16+
const hasSlot = Astro.slots.has('default');
1717
---
18+
1819
<div pagefind-weight="6">
1920
{requiresReview && (
21+
<>
2022
<p style="color: var(--sl-color-orange); font-size: 1.6rem;"><strong>Manual Review Required</strong></p>
2123
<p style="color: var(--sl-color-orange); font-size: 1.25rem;">Please finish this page using the <a target="_blank" href={"https://wiki.multitheftauto.com/wiki" + path}>corresponding Old Wiki article</a>. Go to <a target="_blank" href={SITE_CONTRIBUTING_URL}>Contribution guidelines</a> for more information.</p>
22-
<hr>
24+
<hr />
25+
</>
2326
)}
2427

25-
<EnhancedMarkdown content={description} />
26-
</div>
28+
{description ? (
29+
<EnhancedMarkdown content={description} />
30+
) : hasSlot ? (
31+
<EnhancedMarkdown>
32+
<slot />
33+
</EnhancedMarkdown>
34+
) : null}
35+
</div>

0 commit comments

Comments
 (0)