Skip to content

Commit 1d16a21

Browse files
committed
💄 Add icons to admonitions
- Make admonition types recognizable at a glance - Hide icons that fail to load
1 parent ca5ae75 commit 1d16a21

4 files changed

Lines changed: 58 additions & 2 deletions

File tree

‎src/app.html‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,20 @@
1111
rel="stylesheet"
1212
/>
1313
%sveltekit.head%
14+
<script>
15+
// Hide admonition icons that fail to load. Registered before the page renders, since
16+
// image errors don't bubble and can fire before hydration.
17+
document.addEventListener(
18+
'error',
19+
event => {
20+
const target = event.target
21+
if (target instanceof HTMLImageElement && target.matches('.admonition-icon')) {
22+
target.hidden = true
23+
}
24+
},
25+
true
26+
)
27+
</script>
1428
</head>
1529
<body data-sveltekit-preload-data="hover">
1630
<div style="display: contents">%sveltekit.body%</div>

‎src/lib/docs/remark-admonitions.ts‎

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,20 @@ import { visit } from 'unist-util-visit'
44

55
const ADMONITION_NAMES = new Set(['note', 'tip', 'warning', 'info', 'danger'])
66

7+
/** Paths in the MCDP icon set (github.com/FuncFusion/mc-dp-icons-assets) for each admonition. */
8+
const ADMONITION_ICONS: Record<string, string> = {
9+
note: 'misc/antbot/upscaled/pushpin.png',
10+
tip: 'misc/antbot/upscaled/check.png',
11+
info: 'icons/current/readme_file.svg',
12+
warning: 'misc/antbot/upscaled/exclamation_mark.png',
13+
danger: 'misc/antbot/upscaled/cross.png',
14+
}
15+
16+
export function getAdmonitionIconUrl(kind: string): string {
17+
const path = ADMONITION_ICONS[kind] ?? ADMONITION_ICONS.note
18+
return `https://github.com/FuncFusion/mc-dp-icons-assets/blob/main/${path}?raw=true`
19+
}
20+
721
function defaultTitle(name: string): string {
822
switch (name) {
923
case 'tip':
@@ -289,7 +303,19 @@ const remarkAdmonitions: Plugin<[], Root> = () => {
289303
properties: {
290304
className: ['admonition-title'],
291305
},
292-
children: [{ type: 'text', value: title }],
306+
children: [
307+
{
308+
type: 'element',
309+
tagName: 'img',
310+
properties: {
311+
className: ['admonition-icon'],
312+
src: getAdmonitionIconUrl(kind),
313+
alt: '',
314+
},
315+
children: [],
316+
},
317+
{ type: 'text', value: title },
318+
],
293319
},
294320
{
295321
type: 'element',

‎src/lib/styles/global.css‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,23 @@ code {
142142
}
143143

144144
.docs-content .admonition-title {
145+
display: flex;
146+
align-items: center;
147+
gap: 8px;
145148
margin: 0 0 8px;
146149
font-family: 'MinecraftFull', sans-serif;
147150
font-size: 16px;
148151
}
149152

153+
.docs-content .admonition-icon {
154+
width: 20px;
155+
height: 20px;
156+
margin: 0;
157+
background: none;
158+
box-shadow: none;
159+
image-rendering: pixelated;
160+
}
161+
150162
.docs-content .admonition-tip {
151163
border-left-color: #6add8f;
152164
background-color: #102d22;

‎src/routes/[[lang=lang]]/docs/[...path]/+page.svelte‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
<script lang="ts">
22
import { getLanguageName } from '$lib/docs/docs'
3+
import { getAdmonitionIconUrl } from '$lib/docs/remark-admonitions'
34
45
const { data } = $props()
56
</script>
67

78
{#if !data.translated}
89
<aside class="admonition admonition-info" lang="en">
9-
<p class="admonition-title">Not translated yet</p>
10+
<p class="admonition-title">
11+
<img class="admonition-icon" src={getAdmonitionIconUrl('info')} alt="" />
12+
Not translated yet
13+
</p>
1014
<div class="admonition-content">
1115
<p>
1216
This page isn't available in {getLanguageName(data.lang, 'en')} yet, so it's shown in

0 commit comments

Comments
 (0)