Skip to content

Commit a6e4513

Browse files
authored
Housekeeping (FabricMC#534)
1 parent b447102 commit a6e4513

17 files changed

Lines changed: 187 additions & 139 deletions

.vitepress/bump.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import * as fs from "node:fs";
33
import * as path from "node:path";
44
import * as process from "node:process";
55
import * as tinyglobby from "tinyglobby";
6-
76
import { getLocaleNames, getResolver, getSidebar } from "./config/i18n";
87

98
const git = (...args: string[]) => {
@@ -78,6 +77,14 @@ for (const file of tinyglobby.globSync("**/*.md", {
7877
}
7978
const locales = getLocaleNames(`./versions/${oldVersion}/translated`);
8079

80+
if (fs.existsSync(`./${newVersion}/`)) {
81+
console.log(`Moving in files from '${newVersion}/'...`);
82+
for (const file of tinyglobby.globSync("**/*", { cwd: `./${newVersion}`, onlyFiles: true })) {
83+
fs.cpSync(`./${newVersion}/${file}`, `./${file}`);
84+
}
85+
fs.rmSync(`./${newVersion}`, { recursive: true });
86+
}
87+
8188
console.log(`Creating sidebars at '.vitepress/sidebars/versioned/${oldVersion}.json'...`);
8289
for (const locale of locales) {
8390
fs.writeFileSync(

.vitepress/config/i18n.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import * as fs from "node:fs";
22
import * as path from "node:path";
33
import * as tinyglobby from "tinyglobby";
4-
54
import Develop from "../sidebars/develop";
65
import Players from "../sidebars/players";
7-
import { Fabric } from "../types";
6+
import { Fabric } from "../types.d";
87

98
export const getLocaleNames = (translatedDir: string) => [
109
"en_us",
@@ -265,7 +264,8 @@ export const getLocales = () => {
265264
version: {
266265
reminder: {
267266
latestVersion: resolver("version.reminder.latest_version"),
268-
oldVersionMojang: resolver("version.reminder.old_version_mojang"),
267+
oldVersion: resolver("version.reminder.old_version"),
268+
newVersion: resolver("version.reminder.new_version"),
269269
},
270270

271271
switcher: {

.vitepress/config/index.ts

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import snippetPlugin from "markdown-it-vuepress-code-snippet-enhanced";
2-
import * as fs from "node:fs";
32
import * as path from "node:path";
43
import * as process from "node:process";
54
import { tabsMarkdownPlugin } from "vitepress-plugin-tabs";
65
import defineVersionedConfig from "vitepress-versioning-plugin";
7-
8-
import { Fabric } from "../types";
6+
import latestVersionPlugin from "../plugins/latestVersion";
7+
import { Fabric } from "../types.d";
98
import { getLocales } from "./i18n";
109
import { transformHead, transformItems } from "./transform";
1110

@@ -26,14 +25,7 @@ const hostname =
2625
? "http://fabric-docs.localhost:4173/"
2726
: env === "dev"
2827
? "http://fabric-docs.localhost:5173/"
29-
: process.env.DEPLOY_PRIME_URL!;
30-
31-
const latestVersion = fs
32-
.readFileSync(
33-
path.resolve(import.meta.dirname, "..", "..", "reference", "latest", "build.gradle"),
34-
"utf-8"
35-
)
36-
.match(/def minecraftVersion = "([^"]+)"/)![1];
28+
: `${process.env.DEPLOY_PRIME_URL!}/`;
3729

3830
// https://vitepress.dev/reference/site-config
3931
// https://www.npmjs.com/package/vitepress-versioning-plugin
@@ -78,15 +70,16 @@ export default defineVersionedConfig(
7870
image: { lazyLoading: true },
7971
languageAlias: { gradle: "groovy" },
8072
languages: [
81-
async () =>
82-
await import("syntax-mcfunction/mcfunction.tmLanguage.json", {
83-
with: { type: "json" },
84-
}).then((lang) => ({ ...(lang.default as any), name: "mcfunction" })),
85-
async () =>
86-
await import("syntax-java-bytecode/java-bytecode.tmLanguage.json", {
87-
with: { type: "json" },
88-
}).then((lang) => ({ ...(lang.default as any), name: "bytecode" })),
89-
],
73+
["mcfunction", "syntax-mcfunction/mcfunction.tmLanguage.json"],
74+
["bytecode", "syntax-java-bytecode/java-bytecode.tmLanguage.json"],
75+
].map(
76+
([name, path]) =>
77+
async () =>
78+
await import(path, { with: { type: "json" } }).then((lang) => ({
79+
...lang.default,
80+
name,
81+
}))
82+
),
9083
lineNumbers: true,
9184
shikiSetup: async (shiki) => {
9285
await shiki.loadTheme("github-light", "github-dark");
@@ -125,7 +118,6 @@ export default defineVersionedConfig(
125118

126119
// Versioning plugin configuration.
127120
versioning: {
128-
latestVersion,
129121
rewrites: { localePrefix: "translated" },
130122
sidebars: {
131123
sidebarContentProcessor: (s) =>
@@ -143,6 +135,10 @@ export default defineVersionedConfig(
143135
url.startsWith("/") ? `/${version}${/^[/].._..[/]/.test(url) ? url.slice(6) : url}` : url,
144136
},
145137
},
138+
139+
vite: {
140+
plugins: [latestVersionPlugin()],
141+
},
146142
},
147143
path.resolve(import.meta.dirname, "..")
148144
);

.vitepress/plugins/index.d.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
declare module "markdown-it-vuepress-code-snippet-enhanced" {
2+
const snippetPlugin: (md: any) => void;
3+
export default snippetPlugin;
4+
}
5+
6+
declare module "virtual:fabric-docs:latest-version" {
7+
const latestVersion: string;
8+
export default latestVersion;
9+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import * as fs from "node:fs";
2+
import * as path from "node:path";
3+
import { Plugin } from "vitepress";
4+
5+
export default (): Plugin => {
6+
const name = "fabric-docs:latest-version";
7+
const id = `virtual:${name}`;
8+
const resolvedId = `\0${id}`;
9+
10+
const file = path.resolve(import.meta.dirname, "..", "..", "reference", "latest", "build.gradle");
11+
12+
return {
13+
name,
14+
enforce: "pre",
15+
16+
resolveId: {
17+
filter: { id: new RegExp(`^${id}$`) },
18+
handler() {
19+
return resolvedId;
20+
},
21+
},
22+
23+
load: {
24+
filter: { id: new RegExp(`^${resolvedId}$`) },
25+
handler() {
26+
this.addWatchFile(file);
27+
28+
const latestVersion = fs
29+
.readFileSync(file, "utf-8")
30+
.match(/def minecraftVersion = "([^"]+)"/)![1];
31+
32+
return `export default ${JSON.stringify(latestVersion)};`;
33+
},
34+
},
35+
};
36+
};

.vitepress/sidebars/develop.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Fabric } from "../types";
1+
import { Fabric } from "../types.d";
22

33
export default [
44
{
@@ -417,4 +417,4 @@ export default [
417417
},
418418
],
419419
},
420-
] as Fabric.SidebarItem[];
420+
] satisfies Fabric.SidebarItem[];

.vitepress/sidebars/players.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Fabric } from "../types";
1+
import { Fabric } from "../types.d";
22

33
export default [
44
{
@@ -44,4 +44,4 @@ export default [
4444
},
4545
],
4646
},
47-
] as Fabric.SidebarItem[];
47+
] satisfies Fabric.SidebarItem[];

.vitepress/theme/components/AuthorsComponent.vue

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<script setup lang="ts">
2+
import { useBrowserLocation } from "@vueuse/core";
23
import { useData } from "vitepress";
4+
import VPLink from "vitepress/dist/client/theme-default/components/VPLink.vue";
35
import { computed } from "vue";
4-
5-
import { useBrowserLocation } from "@vueuse/core";
6-
import { Fabric } from "../../types";
6+
import { Fabric } from "../../types.d";
77
88
type Author = { name: string; noGitHub?: true };
99
@@ -36,32 +36,31 @@ const getImageSrc = (author: Author) =>
3636
<template>
3737
<h2 v-if="authors.length">{{ options.heading }}</h2>
3838
<div>
39-
<component
39+
<VPLink
4040
v-for="author in authors"
4141
:key="author.noGitHub ? `${author.name}!` : author.name"
42-
:is="author.noGitHub ? 'span' : 'a'"
43-
:href="`https://github.com/${author.name}`"
44-
target="_blank"
42+
:href="author.noGitHub ? undefined : `https://github.com/${author.name}`"
4543
>
4644
<img
4745
:title="author.noGitHub ? options.noGitHub.replace('%s', author.name) : author.name"
4846
:src="getImageSrc(author)"
4947
:alt="author.name"
5048
loading="lazy"
5149
/>
52-
</component>
50+
</VPLink>
5351
</div>
5452
</template>
5553

5654
<style scoped>
5755
h2 {
56+
margin-top: 20px;
57+
padding-top: 16px;
58+
border-top: 1px solid var(--vp-c-divider);
59+
font-size: 12px;
5860
font-weight: bold;
59-
font-size: large;
60-
margin-top: 16px;
61-
}
62-
63-
.content-container > h2 {
64-
display: none;
61+
color: var(--vp-c-text-2);
62+
letter-spacing: 0.06em;
63+
text-transform: uppercase;
6564
}
6665
6766
div {
@@ -87,6 +86,16 @@ div {
8786
}
8887
}
8988
89+
.content-container {
90+
h2 {
91+
display: none;
92+
}
93+
94+
div {
95+
margin-bottom: 16px;
96+
}
97+
}
98+
9099
@media (min-width: 1280px) {
91100
.content-container > div {
92101
display: none;

.vitepress/theme/components/BannerComponent.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import { useElementSize } from "@vueuse/core";
33
import { useData } from "vitepress";
44
import VPLink from "vitepress/dist/client/theme-default/components/VPLink.vue";
55
import { computed, ref, watch } from "vue";
6-
7-
import { Fabric } from "../../types";
6+
import { Fabric } from "../../types.d";
87
98
const data = useData();
109
const banner = ref<HTMLElement>();

.vitepress/theme/components/DownloadEntry.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
import { useData } from "vitepress";
33
import VPButton from "vitepress/dist/client/theme-default/components/VPButton.vue";
44
import { computed, useSlots } from "vue";
5-
6-
import { Fabric } from "../../types";
5+
import { Fabric } from "../../types.d";
76
87
defineProps<{
98
downloadURL: string;

0 commit comments

Comments
 (0)