Skip to content

Commit

Permalink
Merge branch 'main' into commands-refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
IMB11 authored Aug 12, 2024
2 parents f01ede7 + d0602b4 commit b9ace44
Show file tree
Hide file tree
Showing 374 changed files with 3,614 additions and 476 deletions.
25 changes: 17 additions & 8 deletions .vitepress/config.mts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import snippetPlugin from "markdown-it-vuepress-code-snippet-enhanced";
import defineVersionedConfig from "vitepress-versioning-plugin";

import { getLocalisedSidebar, loadLocales, processExistingEntries } from "./i18n";
import { loadLocales, processExistingEntries } from "./i18n";
import { transformItems, transformPageData } from "./transform";
import { DefaultTheme } from "vitepress";
import { readdirSync } from "node:fs";
import { resolve } from "node:path";

// https://vitepress.dev/reference/site-config
// https://www.npmjs.com/package/vitepress-versioning-plugin
Expand All @@ -26,10 +24,21 @@ export default defineVersionedConfig(
config(md) {
md.use(snippetPlugin);
},
// TODO: load `mcfunction`
// - https://vitepress.dev/guide/markdown#syntax-highlighting-in-code-blocks
// - https://shiki.style/guide/load-lang
// - https://github.com/MinecraftCommands/syntax-mcfunction/blob/main/mcfunction.tmLanguage.json
languages: [
(async () => {
const mcfunctionLanguage = (await import("syntax-mcfunction/mcfunction.tmLanguage.json", {
with: {
type: "json"
}
}) as any).default

mcfunctionLanguage.name = 'mcfunction';
return mcfunctionLanguage;
}),
],
async shikiSetup(shiki) {
await shiki.loadTheme('github-light', 'github-dark');
},
lineNumbers: true,
math: true,
},
Expand All @@ -47,7 +56,7 @@ export default defineVersionedConfig(

themeConfig: {
search: {
provider: "local",
provider: "local"
},
},

Expand Down
8 changes: 5 additions & 3 deletions .vitepress/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,10 @@ function generateTranslatedThemeConfig(localeCode: string): Fabric.ThemeConfig {
},
],
},
{
// TODO: Allow custom component to have i18n translations for mobile navigation bar.
component: "VersionSwitcher"
}
],

notFound: {
Expand Down Expand Up @@ -304,9 +308,7 @@ function generateTranslatedThemeConfig(localeCode: string): Fabric.ThemeConfig {
},
],

versionSwitcher: {
text: websiteResolver("version_switcher"),
},
versionSwitcher: false,
};
}

Expand Down
228 changes: 228 additions & 0 deletions .vitepress/theme/components/VersionSwitcher.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,228 @@
<script setup lang="ts">
import { useRouter, useData } from "vitepress"
import { onBeforeMount, ref } from 'vue'
import VPLink from 'vitepress/dist/client/theme-default/components/VPLink.vue'
import VPFlyout from 'vitepress/dist/client/theme-default/components/VPFlyout.vue'
const props = defineProps<{
versioningPlugin: { versions: string[], latestVersion: string }
screenMenu?: boolean
}>();
const router = useRouter();
const data = useData();
const currentVersion = ref(props.versioningPlugin.latestVersion);
router.onBeforeRouteChange = (to: string) => {
if(to === '/') {
currentVersion.value = props.versioningPlugin.latestVersion;
return true;
}
for (const v of props.versioningPlugin.versions) {
if (to.includes(`/${v}/`)) {
currentVersion.value = v;
break;
}
}
return true;
}
onBeforeMount(() => {
for (const v of props.versioningPlugin.versions) {
if (router.route.path.includes(`/${v}/`)) {
currentVersion.value = v;
break;
}
}
});
const isOpen = ref(false);
const toggle = () => {
isOpen.value = !isOpen.value;
};
function visitVersion(version) {
const localeKeys = Object.keys(data.site.value.locales);
// Check if the current path is localized
const isLocalized = localeKeys.some((key) => router.route.path.startsWith(`/${key}/`));
let route;
const isOnLatest = currentVersion.value === props.versioningPlugin.latestVersion;
if(isLocalized) {
// Get locale from the current path
const locale = localeKeys.find((key) => router.route.path.startsWith(`/${key}/`));
if(!isOnLatest) {
if(version === props.versioningPlugin.latestVersion) {
route = router.route.path.replace(`/${locale}/${currentVersion.value}/`, `/${locale}/`);
} else {
route = router.route.path.replace(`/${locale}/${currentVersion}/`, `/${locale}/${version}/`);
}
} else {
route = router.route.path.replace(`/${locale}/`, `/${locale}/${version}/`);
}
} else {
if(!isOnLatest) {
if(version === props.versioningPlugin.latestVersion) {
route = router.route.path.replace(`/${currentVersion.value}/`, '/');
} else {
route = router.route.path.replace(`/${currentVersion.value}/`, `/${version}/`);
}
} else {
route = router.route.path.replace('/', `/${version}/`);
}
}
router.go(route);
currentVersion.value = version;
}
</script>

<template>
<VPFlyout v-if="!screenMenu" class="VPVersionSwitcher" icon="vpi-versioning" :button="currentVersion"
:label="'Switch Version'">
<div class="items">
<VPLink href="#" v-if="currentVersion != versioningPlugin.latestVersion" @click="visitVersion(versioningPlugin.latestVersion)">
{{ versioningPlugin.latestVersion }}
</VPLink>
<template v-for="version in versioningPlugin.versions" :key="version">
<VPLink href="#" :tag="'a'" v-if="currentVersion != version" @click="visitVersion(version)">
{{ version }}
</VPLink>
</template>
</div>
</VPFlyout>
<div v-else class="VPScreenVersionSwitcher" :class="{ open: isOpen }">
<button class="button" aria-controls="navbar-group-version" :aria-expanded="isOpen" @click="toggle">
<span class="button-text"><span class="vpi-versioning icon" />Switch Version</span>
<span class="vpi-plus button-icon" />
</button>

<div id="navbar-group-version" class="items">
<VPLink href="#" @click="visitVersion(versioningPlugin.latestVersion)">
{{ versioningPlugin.latestVersion}}
</VPLink>
<template v-for="version in versioningPlugin.versions" :key="version">
<VPLink href="#" @click="visitVersion(version)">
{{ version }}
</VPLink>
</template>
</div>
</div>
</template>

<style>
.vpi-versioning.option-icon {
margin-right: 2px !important;
}
.vpi-versioning {
--icon: url("data:image/svg+xml;charset=utf-8;base64,PHN2ZyB3aWR0aD0iNjRweCIgaGVpZ2h0PSI2NHB4IiB2aWV3Qm94PSIwIDAgMjQgMjQiIHN0cm9rZS13aWR0aD0iMi4yIiBmaWxsPSJub25lIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGNvbG9yPSIjMDAwMDAwIj48cGF0aCBkPSJNMTcgN0MxOC4xMDQ2IDcgMTkgNi4xMDQ1NyAxOSA1QzE5IDMuODk1NDMgMTguMTA0NiAzIDE3IDNDMTUuODk1NCAzIDE1IDMuODk1NDMgMTUgNUMxNSA2LjEwNDU3IDE1Ljg5NTQgNyAxNyA3W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6px;
padding: 0 12px;
line-height: 32px;
font-size: 14px;
font-weight: 500;
color: var(--vp-c-text-1);
white-space: nowrap;
transition: background-color 0.25s, color 0.25s;
}
.link:hover {
color: var(--vp-c-brand-1);
background-color: var(--vp-c-default-soft);
}
.link.active {
color: var(--vp-c-brand-1);
}
.VPVersionSwitcher {
display: flex;
align-items: center;
}
.icon {
padding: 8px;
}
.title {
padding: 0 24px 0 12px;
line-height: 32px;
font-size: 14px;
font-weight: 700;
color: var(--vp-c-text-1);
}
.VPScreenVersionSwitcher {
border-bottom: 1px solid var(--vp-c-divider);
height: 48px;
overflow: hidden;
transition: border-color 0.5s;
}
.VPScreenVersionSwitcher .items {
visibility: hidden;
}
.VPScreenVersionSwitcher.open .items {
visibility: visible;
}
.VPScreenVersionSwitcher.open {
padding-bottom: 10px;
height: auto;
}
.VPScreenVersionSwitcher.open .button {
padding-bottom: 6px;
color: var(--vp-c-brand-1);
}
.VPScreenVersionSwitcher.open .button-icon {
/*rtl:ignore*/
transform: rotate(45deg);
}
.VPScreenVersionSwitcher button .icon {
margin-right: 8px;
}
.button {
display: flex;
justify-content: space-between;
align-items: center;
padding: 12px 4px 11px 0;
width: 100%;
line-height: 24px;
font-size: 14px;
font-weight: 500;
color: var(--vp-c-text-1);
transition: color 0.25s;
}
.button:hover {
color: var(--vp-c-brand-1);
}
.button-icon {
transition: transform 0.25s;
}
.group:first-child {
padding-top: 0px;
}
.group+.group,
.group+.item {
padding-top: 4px;
}
</style>
8 changes: 7 additions & 1 deletion .vitepress/theme/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,23 @@ import ColorSwatch from './components/ColorSwatch.vue';
import VersionReminder from './components/VersionReminder.vue';
import VideoPlayer from './components/VideoPlayer.vue';

import VersionSwitcher from "./components/VersionSwitcher.vue";

import "./style.css";

export default {
extends: DefaultTheme,
enhanceApp({ app }) {
// Vidstack Videoplayer Component
app.config.compilerOptions.isCustomElement = (tag) => tag.startsWith('media-');
app.component('VideoPlayer', VideoPlayer);

// Custom Components for Pages
app.component('DownloadEntry', DownloadEntry);
app.component('ColorSwatch', ColorSwatch);
app.component('VideoPlayer', VideoPlayer);

// Versioning Plugin Components
app.component('VersionSwitcher', VersionSwitcher);
},
Layout() {
const children = {
Expand Down
Loading

0 comments on commit b9ace44

Please sign in to comment.