Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

versioning, picker component #178

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions docs/src/.vitepress/config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@ import mathjax3 from "markdown-it-mathjax3";
import footnote from "markdown-it-footnote";
import { transformerMetaWordHighlight } from '@shikijs/transformers';


const baseTemp = {
base: 'REPLACE_ME_DOCUMENTER_VITEPRESS',// TODO: replace this in makedocs!
Copy link
Contributor

@jkrumbiegel jkrumbiegel Sep 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@asinghvi17 by the way, the way these strings are replaced makes the code unnecessarily ugly. Couldn't you give every bit its own name like REPLACE_ME_DOCUMENTER_VITEPRESS_FAVICON? Then one could it splice in directly wherever needed without relying on the base: thing being present.

Copy link
Collaborator

@asinghvi17 asinghvi17 Sep 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could, it's not super complicated to do either. Will look into it today.

}

const navTemp = {
nav: 'REPLACE_ME_DOCUMENTER_VITEPRESS',
}

const nav = [
...navTemp.nav,
{
component: 'VersionPicker'
}
]
// https://vitepress.dev/reference/site-config
export default defineConfig({
base: 'REPLACE_ME_DOCUMENTER_VITEPRESS', // TODO: replace this in makedocs!
Expand All @@ -12,7 +27,11 @@ export default defineConfig({
lastUpdated: true,
cleanUrls: true,
outDir: 'REPLACE_ME_DOCUMENTER_VITEPRESS', // This is required for MarkdownVitepress to work correctly...
head: [['link', { rel: 'icon', href: '/DocumenterVitepress.jl/dev/favicon.ico' }]],
head: [
['link', { rel: 'icon', href: '/DocumenterVitepress.jl/dev/favicon.ico' }],
['script', {src: '/versions.js'}],
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@asinghvi17 not here? I think I just need to add base here, isn't?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that should also work!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't base also contain dev or stable? If so that would not be correct

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, that doesn't work. It populates the menu, but the links are wrong.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mmm, not sure how to propagate base to the Vue component. If I'm not too tired, I will check again later. It will be good to have this finally in the next release, which will be breaking either way. So, a big bump will also be needed. Someone that knows more about it, please commit the appropriate bump.

['script', {src: `${baseTemp.base}siteinfo.js`}]
],
vite: {
build: {
assetsInlineLimit: 0, // so we can tell whether we have created inlined images or not, we don't let vite inline them
Expand Down Expand Up @@ -43,7 +62,7 @@ export default defineConfig({
detailedView: true
}
},
nav: 'REPLACE_ME_DOCUMENTER_VITEPRESS',
nav,
sidebar: 'REPLACE_ME_DOCUMENTER_VITEPRESS',
editLink: 'REPLACE_ME_DOCUMENTER_VITEPRESS',
socialLinks: [
Expand Down
64 changes: 64 additions & 0 deletions docs/src/.vitepress/theme/VersionPicker.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<!-- From https://github.com/MakieOrg/Makie.jl/blob/master/docs/src/.vitepress/theme/VersionPicker.vue -->

<script setup lang="ts">
import { computed, ref, onMounted } from 'vue'
import { useRoute } from 'vitepress'
import VPNavBarMenuGroup from 'vitepress/dist/client/theme-default/components/VPNavBarMenuGroup.vue'
import VPNavScreenMenuGroup from 'vitepress/dist/client/theme-default/components/VPNavScreenMenuGroup.vue'

const props = defineProps<{
screenMenu?: boolean
}>()

const route = useRoute()

const versions = ref([]);
const currentVersion = ref('Versions');

const waitForGlobalDocumenterVars = () => {
return new Promise((resolve) => {
const checkInterval = setInterval(() => {
if (window.DOC_VERSIONS && window.DOCUMENTER_CURRENT_VERSION) {
clearInterval(checkInterval);
resolve({
versions: window.DOC_VERSIONS,
currentVersion: window.DOCUMENTER_CURRENT_VERSION
});
}
}, 100); // Check every 100ms
});
};

onMounted(async () => {
const globalvars = await waitForGlobalDocumenterVars();
versions.value = globalvars.versions.map((v) => {
return {text: v, link: `${window.location.origin}/${v}/`}
});
currentVersion.value = globalvars.currentVersion;
});

</script>

<template>
<VPNavBarMenuGroup
v-if="!screenMenu"
:item="{ text: currentVersion, items: versions }"
class="VPVersionPicker"
/>
<VPNavScreenMenuGroup
v-else
:text="currentVersion"
:items="versions"
class="VPVersionPicker"
/>
</template>

<style scoped>
.VPVersionPicker :deep(button .text) {
color: var(--vp-c-text-1) !important;
}

.VPVersionPicker:hover :deep(button .text) {
color: var(--vp-c-text-2) !important;
}
</style>
4 changes: 3 additions & 1 deletion docs/src/.vitepress/theme/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { h } from 'vue'
import type { Theme } from 'vitepress'
import DefaultTheme from 'vitepress/theme'
import AsideTrustees from '../../components/AsideTrustees.vue'
import VersionPicker from "./VersionPicker.vue"

import { enhanceAppWithTabs } from 'vitepress-plugin-tabs/client'
import './style.css'
Expand All @@ -16,6 +17,7 @@ export default {
})
},
enhanceApp({ app, router, siteData }) {
enhanceAppWithTabs(app)
enhanceAppWithTabs(app);
app.component('VersionPicker', VersionPicker);
}
} satisfies Theme
Loading