detail page port

This commit is contained in:
nicwands
2026-05-29 11:22:56 -04:00
parent b85d28c142
commit e22d75c50a
65 changed files with 7006 additions and 4044 deletions

44
composables/prismic.js Normal file
View File

@@ -0,0 +1,44 @@
import * as prismic from '@prismicio/client'
// === Cached API of any pris method === //
const cache = {}
export const cacheResult = (method, ...args) => {
const key = method + JSON.stringify(args || [])
// If not in cache,
// fetch and store
if (!cache[key]) {
cache[key] = () => {
const client = prismic.createClient('swang')
return client[method](...args).catch((err) => {
console.log(`Error getting Prismic result ${key}:`, err)
throw err
})
}
}
return { key, execute: cache[key] }
}
// Get single doc
export const usePrisSingle = (type, options = {}) => {
const { key, execute } = cacheResult('getSingle', type, options)
return useAsyncData(key, execute, { deep: false })
}
// Get settings (assumed single doc)
export const usePrisSettings = () => {
return usePrisSingle('settings')
}
// Get all docs of a certain type
export const usePrisType = (type, options = {}) => {
const { key, execute } = cacheResult('getAllByType', type, options)
return useAsyncData(key, execute, { deep: false })
}
// Get doc by UID (and type)
export const usePrisUid = (uid, type = 'page', options = {}) => {
const { key, execute } = cacheResult('getByUID', type, uid, options)
return useAsyncData(key, execute, { deep: false })
}