修改了首页
This commit is contained in:
37
app/composables/usePageSeo.ts
Normal file
37
app/composables/usePageSeo.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import { useHead, useRequestURL, useSeoMeta } from '#app'
|
||||
|
||||
type SeoInput = {
|
||||
title: string
|
||||
description: string
|
||||
path?: string
|
||||
}
|
||||
|
||||
function getSiteOrigin() {
|
||||
if (import.meta.client) return window.location.origin
|
||||
try {
|
||||
return useRequestURL().origin
|
||||
} catch {
|
||||
return ''
|
||||
}
|
||||
}
|
||||
|
||||
export function usePageSeo(input: SeoInput) {
|
||||
const origin = getSiteOrigin()
|
||||
const url = input.path && origin ? new URL(input.path, origin).toString() : undefined
|
||||
|
||||
useSeoMeta({
|
||||
title: input.title,
|
||||
description: input.description,
|
||||
ogTitle: input.title,
|
||||
ogDescription: input.description,
|
||||
ogType: 'website',
|
||||
...(url ? { ogUrl: url } : {}),
|
||||
twitterCard: 'summary_large_image'
|
||||
})
|
||||
|
||||
if (url) {
|
||||
useHead({
|
||||
link: [{ rel: 'canonical', href: url }]
|
||||
})
|
||||
}
|
||||
}
|
||||
8
app/composables/useSiteInfo.ts
Normal file
8
app/composables/useSiteInfo.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import type { ApiEnvelope } from '~/types/api'
|
||||
import { useFetch } from '#imports'
|
||||
|
||||
export function useSiteInfo() {
|
||||
return useFetch<ApiEnvelope>('/api/cms/cms-website/getSiteInfo', {
|
||||
key: 'cms-website-getSiteInfo'
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user