Skip to content

Commit d2d6aa7

Browse files
committed
refactor: cherry-pick social icons rework from Adventure PR
1 parent d4a83c7 commit d2d6aa7

File tree

3 files changed

+35
-28
lines changed

3 files changed

+35
-28
lines changed

astro.config.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ import starlightSidebarTopics from "starlight-sidebar-topics";
77
import codeConstantsPlugin from "./src/utils/remark/code_const";
88
import javadocPlugin from "./src/utils/remark/javadoc";
99
import {
10+
LATEST_FOLIA_RELEASE,
1011
LATEST_MC_RELEASE,
1112
LATEST_PAPER_RELEASE,
1213
LATEST_USERDEV_RELEASE,
1314
LATEST_VELOCITY_RELEASE,
15+
LATEST_WATERFALL_RELEASE,
1416
} from "./src/utils/versions";
1517

1618
const prod = process.env.NODE_ENV === "production";
@@ -32,9 +34,29 @@ export default defineConfig({
3234
starlight({
3335
title: "PaperMC Docs",
3436
social: [
37+
{ icon: "github", label: "paper:GitHub", href: "https://github.com/PaperMC/Paper" },
38+
{ icon: "seti:java", label: "paper:Javadoc", href: `https://jd.papermc.io/paper/${LATEST_PAPER_RELEASE}` },
39+
40+
{ icon: "github", label: "velocity:GitHub", href: "https://github.com/PaperMC/Velocity" },
41+
{
42+
icon: "seti:java",
43+
label: "velocity:Javadoc",
44+
href: `https://jd.papermc.io/velocity/${LATEST_VELOCITY_RELEASE.substring(0, LATEST_VELOCITY_RELEASE.lastIndexOf("."))}.0`,
45+
},
46+
47+
{ icon: "github", label: "folia:GitHub", href: "https://github.com/PaperMC/Folia" },
48+
{ icon: "seti:java", label: "folia:Javadoc", href: `https://jd.papermc.io/folia/${LATEST_FOLIA_RELEASE}` },
49+
50+
{ icon: "github", label: "waterfall:GitHub", href: "https://github.com/PaperMC/Waterfall" },
51+
{
52+
icon: "seti:java",
53+
label: "waterfall:Javadoc",
54+
href: `https://jd.papermc.io/waterfall/${LATEST_WATERFALL_RELEASE}`,
55+
},
56+
3557
{ icon: "github", label: "GitHub", href: "https://github.com/PaperMC" },
36-
{ icon: "discord", label: "Discord", href: "https://discord.gg/PaperMC" },
3758
{ icon: "seti:java", label: "Javadoc", href: "https://jd.papermc.io" },
59+
{ icon: "discord", label: "Discord", href: "https://discord.gg/PaperMC" },
3860
],
3961
lastUpdated: true,
4062
editLink: {
@@ -433,6 +455,8 @@ export default defineConfig({
433455
LATEST_MC_RELEASE,
434456
LATEST_PAPER_RELEASE,
435457
LATEST_VELOCITY_RELEASE,
458+
LATEST_FOLIA_RELEASE,
459+
LATEST_WATERFALL_RELEASE,
436460
LATEST_USERDEV_RELEASE,
437461
},
438462
},

src/components/overrides/SocialIcons.astro

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,21 @@
11
---
22
import config from "virtual:starlight/user-config";
33
import { Icon } from "@astrojs/starlight/components";
4-
import { LATEST_RELEASES } from "../../utils/versions";
54
65
const { isPageWithTopic, topics } = Astro.locals.starlightSidebarTopics;
76
const currentTopic = isPageWithTopic ? topics.find((t) => t.isCurrent) : null;
87
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-
}
8+
const project = currentTopic?.label?.toLowerCase();
199
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-
});
10+
const links = (config.social || [])
11+
.filter((l) => !l.label.includes(":") || (project && l.label.startsWith(`${project}:`)))
12+
.map((link) => {
13+
// strip project IDs
14+
const index = link.label.indexOf(":");
15+
return index !== -1 ? { ...link, label: link.label.substring(index + 1) } : link;
16+
})
17+
// deduplicate links with the same label
18+
.filter((l, pos, self) => self.findIndex((e) => e.label === l.label) === pos);
2819
---
2920

3021
{

src/utils/versions.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,3 @@ const userdevVersions: string[] = await fetch("https://api.github.com/repos/Pape
5555
.then((tags: Tag[]) => tags.map((t) => t.name.substring(1)));
5656

5757
export const LATEST_USERDEV_RELEASE = userdevVersions[0];
58-
59-
export const LATEST_RELEASES: Record<string, string> = {
60-
paper: LATEST_PAPER_RELEASE,
61-
velocity: LATEST_VELOCITY_RELEASE,
62-
folia: LATEST_FOLIA_RELEASE,
63-
waterfall: LATEST_WATERFALL_RELEASE,
64-
userdev: LATEST_USERDEV_RELEASE,
65-
};

0 commit comments

Comments
 (0)