support loading per-route extra scripting
This commit is contained in:
parent
fb120750ab
commit
42e0ff64d3
5 changed files with 30 additions and 0 deletions
1
src/content-env.d.ts
vendored
1
src/content-env.d.ts
vendored
|
@ -26,6 +26,7 @@ declare module 'content/routes.js' {
|
||||||
*/
|
*/
|
||||||
type SharedRouteDefinition = {
|
type SharedRouteDefinition = {
|
||||||
id: string
|
id: string
|
||||||
|
scriptUrl?: string
|
||||||
stylesheetUrls: string[]
|
stylesheetUrls: string[]
|
||||||
template: Template
|
template: Template
|
||||||
title: string
|
title: string
|
||||||
|
|
14
src/main.vue
14
src/main.vue
|
@ -59,6 +59,15 @@ const determineGlobalStylesheets = () => {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const determineScript = async () => {
|
||||||
|
if (!!routeConfig.scriptUrl) {
|
||||||
|
const { init } = await import(/* @vite-ignore */ routeConfig.scriptUrl)
|
||||||
|
init()
|
||||||
|
}
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
const refresh = async () => {
|
const refresh = async () => {
|
||||||
ready.value = false
|
ready.value = false
|
||||||
acknowledged.value = false
|
acknowledged.value = false
|
||||||
|
@ -80,6 +89,10 @@ const onAcknowledgedWarning = () => {
|
||||||
routeStore.rememberRouteWarning(currentRoute.path)
|
routeStore.rememberRouteWarning(currentRoute.path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const onRouteLoaded = async () => {
|
||||||
|
await determineScript()
|
||||||
|
}
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
await refresh()
|
await refresh()
|
||||||
determineGlobalStylesheets()
|
determineGlobalStylesheets()
|
||||||
|
@ -108,6 +121,7 @@ onMounted(async () => {
|
||||||
)
|
)
|
||||||
router-view(
|
router-view(
|
||||||
v-slot='{ Component }'
|
v-slot='{ Component }'
|
||||||
|
@loaded='onRouteLoaded'
|
||||||
)
|
)
|
||||||
Transition
|
Transition
|
||||||
component(
|
component(
|
||||||
|
|
|
@ -14,6 +14,10 @@ const props = defineProps<{
|
||||||
variants: string[]
|
variants: string[]
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
|
const emits = defineEmits<{
|
||||||
|
(e: 'loaded'): void
|
||||||
|
}>()
|
||||||
|
|
||||||
const ready = ref(false)
|
const ready = ref(false)
|
||||||
const config = ref(null! as GalleryList)
|
const config = ref(null! as GalleryList)
|
||||||
const entry = ref(null! as GalleryEntry)
|
const entry = ref(null! as GalleryEntry)
|
||||||
|
@ -35,6 +39,7 @@ onMounted(async () => {
|
||||||
title.value = getTitleFromEntryOrId(entry.value, id.value)
|
title.value = getTitleFromEntryOrId(entry.value, id.value)
|
||||||
document.title = routeSubConfig.title.replace('$ENTRY', title.value)
|
document.title = routeSubConfig.title.replace('$ENTRY', title.value)
|
||||||
ready.value = true
|
ready.value = true
|
||||||
|
emits('loaded')
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,10 @@ import { fetchAndParseMarkdown } from 'src/utilities/fetch'
|
||||||
import { getCurrentRoute } from 'src/utilities/vuetils'
|
import { getCurrentRoute } from 'src/utilities/vuetils'
|
||||||
import { useRouteStore } from 'src/routes'
|
import { useRouteStore } from 'src/routes'
|
||||||
|
|
||||||
|
const emits = defineEmits<{
|
||||||
|
(e: 'loaded'): void
|
||||||
|
}>()
|
||||||
|
|
||||||
const content = ref('')
|
const content = ref('')
|
||||||
const currentRoute = getCurrentRoute()
|
const currentRoute = getCurrentRoute()
|
||||||
const routeStore = useRouteStore()
|
const routeStore = useRouteStore()
|
||||||
|
@ -16,6 +20,7 @@ const routeConfig = routeStore._routes[currentRoute.path] as MarkdownDefinition
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
content.value = await fetchAndParseMarkdown(routeConfig.content)
|
content.value = await fetchAndParseMarkdown(routeConfig.content)
|
||||||
document.title = routeConfig.title
|
document.title = routeConfig.title
|
||||||
|
emits('loaded')
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,10 @@ const props = defineProps<{
|
||||||
id: string,
|
id: string,
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
|
const emits = defineEmits<{
|
||||||
|
(e: 'loaded'): void
|
||||||
|
}>()
|
||||||
|
|
||||||
const ready = ref(false)
|
const ready = ref(false)
|
||||||
const info = ref(null! as ProjectListingInfo)
|
const info = ref(null! as ProjectListingInfo)
|
||||||
const content = ref('')
|
const content = ref('')
|
||||||
|
@ -30,6 +34,7 @@ onMounted(async () => {
|
||||||
document.title = routeSubConfig.title.replace('$PROJECT', info.value.title)
|
document.title = routeSubConfig.title.replace('$PROJECT', info.value.title)
|
||||||
|
|
||||||
ready.value = true
|
ready.value = true
|
||||||
|
emits('loaded')
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue