-
Notifications
You must be signed in to change notification settings - Fork 12
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
2a49f32
picker component, is this enough?
lazarusA 8da1304
update v comp and nav
lazarusA 8685cc8
just because why not, type the name's repo
lazarusA ad24a25
fix errors for local build
lazarusA dcf271d
do base, get baserepo function
lazarusA 90d89e8
type repo
lazarusA 1c61302
build local
lazarusA da4fd3e
reduce overhead
lazarusA a30f7af
only client
lazarusA 18ccaf7
custom domains
lazarusA dcc8919
cp vpicker to template
lazarusA 1e5da9d
fixes
lazarusA 9fc3570
orga and rm shikijs call, not needed
lazarusA 8c7c4ed
again
lazarusA File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
<!-- Adapted from https://github.com/MakieOrg/Makie.jl/blob/master/docs/src/.vitepress/theme/VersionPicker.vue --> | ||
|
||
<script setup lang="ts"> | ||
import { ref, onMounted, computed } from 'vue' | ||
import { useData } from 'vitepress' | ||
import VPNavBarMenuGroup from 'vitepress/dist/client/theme-default/components/VPNavBarMenuGroup.vue' | ||
import VPNavScreenMenuGroup from 'vitepress/dist/client/theme-default/components/VPNavScreenMenuGroup.vue' | ||
|
||
// Extend the global Window interface to include DOC_VERSIONS and DOCUMENTER_CURRENT_VERSION | ||
declare global { | ||
interface Window { | ||
DOC_VERSIONS?: string[]; | ||
DOCUMENTER_CURRENT_VERSION?: string; | ||
} | ||
} | ||
|
||
const props = defineProps<{ | ||
screenMenu?: boolean | ||
}>() | ||
|
||
const versions = ref<Array<{ text: string, link: string }>>([]); | ||
const currentVersion = ref('Versions'); | ||
const isClient = ref(false); | ||
const { site } = useData() | ||
|
||
const isLocalBuild = () => { | ||
return typeof window !== 'undefined' && (window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1'); | ||
} | ||
|
||
const getBaseRepository = () => { | ||
if (typeof window === 'undefined') return ''; // Handle server-side rendering (SSR) | ||
const { origin, pathname } = window.location; | ||
// Check if it's a GitHub Pages (or similar) setup | ||
if (origin.includes('github.io')) { | ||
// Extract the first part of the path as the repository name | ||
const pathParts = pathname.split('/').filter(Boolean); | ||
const baseRepo = pathParts.length > 0 ? `/${pathParts[0]}` : ''; | ||
return `${origin}${baseRepo}`; | ||
} else { | ||
// For custom domains, use just the origin (e.g., https://docs.makie.org) | ||
return origin; | ||
} | ||
}; | ||
|
||
const waitForScriptsToLoad = () => { | ||
return new Promise<boolean>((resolve) => { | ||
if (isLocalBuild()) { | ||
resolve(false); | ||
return; | ||
} | ||
const checkInterval = setInterval(() => { | ||
if (window.DOC_VERSIONS && window.DOCUMENTER_CURRENT_VERSION) { | ||
clearInterval(checkInterval); | ||
resolve(true); | ||
} | ||
}, 100); | ||
// Timeout after 5 seconds | ||
setTimeout(() => { | ||
clearInterval(checkInterval); | ||
resolve(false); | ||
}, 5000); | ||
}); | ||
}; | ||
|
||
const loadVersions = async () => { | ||
if (typeof window === 'undefined') return; // Guard for SSR | ||
|
||
try { | ||
if (isLocalBuild()) { | ||
// Handle the local build scenario directly | ||
const fallbackVersions = ['dev']; | ||
versions.value = fallbackVersions.map(v => ({ | ||
text: v, | ||
link: '/' | ||
})); | ||
currentVersion.value = 'dev'; | ||
} else { | ||
// For non-local builds, wait for scripts to load | ||
const scriptsLoaded = await waitForScriptsToLoad(); | ||
const getBaseRepositoryPath = computed(() => { | ||
return getBaseRepository(); | ||
}); | ||
|
||
if (scriptsLoaded && window.DOC_VERSIONS && window.DOCUMENTER_CURRENT_VERSION) { | ||
versions.value = window.DOC_VERSIONS.map((v: string) => ({ | ||
text: v, | ||
link: `${getBaseRepositoryPath.value}/${v}/` | ||
})); | ||
currentVersion.value = window.DOCUMENTER_CURRENT_VERSION; | ||
} else { | ||
// Fallback logic if scripts fail to load or are not available | ||
const fallbackVersions = ['dev']; | ||
versions.value = fallbackVersions.map(v => ({ | ||
text: v, | ||
link: `${getBaseRepositoryPath.value}/${v}/` | ||
})); | ||
currentVersion.value = 'dev'; | ||
} | ||
} | ||
} catch (error) { | ||
console.warn('Error loading versions:', error); | ||
// Use fallback logic in case of an error | ||
const fallbackVersions = ['dev']; | ||
const getBaseRepositoryPath = computed(() => { | ||
return getBaseRepository(); | ||
}); | ||
versions.value = fallbackVersions.map(v => ({ | ||
text: v, | ||
link: `${getBaseRepositoryPath.value}/${v}/` | ||
})); | ||
currentVersion.value = 'dev'; | ||
} | ||
isClient.value = true; | ||
}; | ||
|
||
onMounted(loadVersions); | ||
</script> | ||
|
||
<template> | ||
<template v-if="isClient"> | ||
<VPNavBarMenuGroup | ||
v-if="!screenMenu && versions.length > 0" | ||
:item="{ text: currentVersion, items: versions }" | ||
class="VPVersionPicker" | ||
/> | ||
<VPNavScreenMenuGroup | ||
v-else-if="screenMenu && versions.length > 0" | ||
:text="currentVersion" | ||
:items="versions" | ||
class="VPVersionPicker" | ||
/> | ||
</template> | ||
</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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 thebase:
thing being present.There was a problem hiding this comment.
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.