21 lines
830 B
TypeScript
21 lines
830 B
TypeScript
// Universal Nuxt plugin syncing `app.config.ts` (`journal.embeds`) into the
|
|
// active Journal embed registry on both SSR and client before page components
|
|
// render, so `htmlGate.ts`, `embeds.ts`, and `useJournalEmbedHydration.ts`
|
|
// agree on the exact same provider set.
|
|
import { defineJournalEmbedProviders, type JournalEmbedProvider } from '../utils/embedRegistry.ts'
|
|
|
|
const syncedEmbedMaps = new WeakSet<object>()
|
|
|
|
export default defineNuxtPlugin({
|
|
name: 'journal-embeds',
|
|
enforce: 'pre',
|
|
setup() {
|
|
const appConfig = useAppConfig() as { journal?: { embeds?: Record<string, JournalEmbedProvider> } }
|
|
const embeds = appConfig?.journal?.embeds
|
|
if (embeds && typeof embeds === 'object' && !syncedEmbedMaps.has(embeds)) {
|
|
defineJournalEmbedProviders(embeds)
|
|
syncedEmbedMaps.add(embeds)
|
|
}
|
|
},
|
|
})
|