diff --git a/docs/components/AppHeader.vue b/docs/components/AppHeader.vue new file mode 100644 index 0000000..eca2172 --- /dev/null +++ b/docs/components/AppHeader.vue @@ -0,0 +1,103 @@ + + + diff --git a/docs/components/AppHeaderLogo.vue b/docs/components/AppHeaderLogo.vue new file mode 100644 index 0000000..1309885 --- /dev/null +++ b/docs/components/AppHeaderLogo.vue @@ -0,0 +1,16 @@ + + + diff --git a/docs/components/AppVersionSwitcher.vue b/docs/components/AppVersionSwitcher.vue new file mode 100644 index 0000000..ee6e3aa --- /dev/null +++ b/docs/components/AppVersionSwitcher.vue @@ -0,0 +1,38 @@ + + + diff --git a/docs/composables/useVersions.ts b/docs/composables/useVersions.ts new file mode 100644 index 0000000..116805a --- /dev/null +++ b/docs/composables/useVersions.ts @@ -0,0 +1,60 @@ +interface Version { + version: string + title: string + path: string + branch: string + isLatest: boolean +} + +const versions = ref([]) +const isLoaded = ref(false) +const isLoading = ref(false) + +export function useVersions() { + const config = useRuntimeConfig() + const currentVersion = config.public.docsVersion || '1.x' + + async function loadVersions() { + if (isLoaded.value || isLoading.value) return + isLoading.value = true + + try { + const res = await fetch('/comments/versions.json') + if (res.ok) { + versions.value = await res.json() + } + } catch (e) { + console.warn('Failed to load versions.json:', e) + } finally { + isLoaded.value = true + isLoading.value = false + } + } + + const latestVersion = computed(() => + versions.value.find(v => v.isLatest) + ) + + const currentVersionInfo = computed(() => + versions.value.find(v => v.version === currentVersion) + ) + + const isOldVersion = computed(() => { + if (!isLoaded.value) return false + return currentVersionInfo.value?.isLatest === false + }) + + const currentTitle = computed(() => + currentVersionInfo.value?.title || currentVersion + ) + + return { + versions, + currentVersion, + currentTitle, + latestVersion, + isOldVersion, + isLoaded, + loadVersions, + } +}