Skip to content

Commit d94169d

Browse files
committed
feat: contextual social icons
1 parent 8120bf5 commit d94169d

File tree

4 files changed

+71
-1
lines changed

4 files changed

+71
-1
lines changed

CONTRIBUTING.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,13 @@ There are quite a few constants you may want to use in your pages, such as the l
128128
These constants can be imported and used in MDX, like so:
129129

130130
```mdxjs
131-
import { LATEST_MC_RELEASE, LATEST_PAPER_RELEASE, LATEST_VELOCITY_RELEASE } from "/src/utils/versions";
131+
import { LATEST_MC_RELEASE, LATEST_PAPER_RELEASE, LATEST_VELOCITY_RELEASE, LATEST_FOLIA_RELEASE, LATEST_WATERFALL_RELEASE } from "/src/utils/versions";
132132
133133
Latest Paper version is {LATEST_PAPER_RELEASE}.
134134
Latest Velocity version is {LATEST_VELOCITY_RELEASE}.
135135
Latest Minecraft version is {LATEST_MC_RELEASE}.
136+
Latest Folia version is {LATEST_FOLIA_RELEASE}.
137+
Latest Waterfall version is {LATEST_WATERFALL_RELEASE}.
136138
```
137139

138140
If you want to perform these replacements in code blocks, you need to use a special `replace` meta property.

astro.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export default defineConfig({
4141
Banner: "./src/components/overrides/Banner.astro",
4242
TableOfContents: "./src/components/overrides/TableOfContents.astro",
4343
MobileTableOfContents: "./src/components/overrides/MobileTableOfContents.astro",
44+
SocialIcons: "./src/components/overrides/SocialIcons.astro",
4445
},
4546
plugins: [
4647
starlightLinksValidator({
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
---
2+
import config from "virtual:starlight/user-config";
3+
import { Icon } from "@astrojs/starlight/components";
4+
import { LATEST_RELEASES } from "../../utils/versions";
5+
6+
const { isPageWithTopic, topics } = Astro.locals.starlightSidebarTopics;
7+
const currentTopic = isPageWithTopic ? topics.find((t) => t.isCurrent) : null;
8+
9+
const links = (config.social || []).map((link) => {
10+
const project = currentTopic?.label?.toLowerCase();
11+
if (!project) {
12+
return link;
13+
}
14+
15+
const version = LATEST_RELEASES[project];
16+
if (!version) {
17+
return link;
18+
}
19+
20+
switch (link.label) {
21+
case "Javadoc":
22+
return { ...link, href: `${link.href}/${project}/${version}` };
23+
case "GitHub":
24+
return { ...link, href: `${link.href}/${project}` };
25+
}
26+
return link;
27+
});
28+
---
29+
30+
{
31+
links.length > 0 && (
32+
<>
33+
{links.map(({ label, href, icon }) => (
34+
<a {href} rel="me" class="sl-flex">
35+
<span class="sr-only">{label}</span>
36+
<Icon name={icon} />
37+
</a>
38+
))}
39+
</>
40+
)
41+
}
42+
43+
<style>
44+
a {
45+
color: var(--sl-color-text-accent);
46+
padding: 0.5em;
47+
margin: -0.5em;
48+
}
49+
a:hover {
50+
opacity: 0.66;
51+
}
52+
</style>

src/utils/versions.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,18 @@ export const LATEST_PAPER_RELEASE = paperProject.versions[paperProject.versions.
3535
const velocityProject: Project = await fetch("https://api.papermc.io/v2/projects/velocity").then((r) => r.json());
3636

3737
export const LATEST_VELOCITY_RELEASE = velocityProject.versions[velocityProject.versions.length - 1];
38+
39+
const foliaProject: Project = await fetch("https://api.papermc.io/v2/projects/folia").then((r) => r.json());
40+
41+
export const LATEST_FOLIA_RELEASE = foliaProject.versions[foliaProject.versions.length - 1];
42+
43+
const waterfallProject: Project = await fetch("https://api.papermc.io/v2/projects/waterfall").then((r) => r.json());
44+
45+
export const LATEST_WATERFALL_RELEASE = waterfallProject.versions[waterfallProject.versions.length - 1];
46+
47+
export const LATEST_RELEASES: Record<string, string> = {
48+
paper: LATEST_PAPER_RELEASE,
49+
velocity: LATEST_VELOCITY_RELEASE,
50+
folia: LATEST_FOLIA_RELEASE,
51+
waterfall: LATEST_WATERFALL_RELEASE,
52+
};

0 commit comments

Comments
 (0)