feat: add ability to redirect to source post when using default server

pull/2551/head
Joshix 2024-01-07 20:00:00 +00:00
rodzic b9394c2fa5
commit fa42d7f86a
1 zmienionych plików z 12 dodań i 3 usunięć

Wyświetl plik

@ -4,8 +4,17 @@ const BOT_RE = /bot\b|index|spider|facebookexternalhit|crawl|wget|slurp|mediapar
export default defineNuxtPlugin(async (nuxtApp) => {
const route = useRoute()
if (!('server' in route.params))
return
let routePath
if (!route.params['server']) {
const server = nuxtApp.$config.public.defaultServer
if (!server)
return
routePath = `/${server}${route.path}`
}
else {
routePath = route.path
}
const userAgent = useRequestHeaders()['user-agent']
if (!userAgent)
@ -14,6 +23,6 @@ export default defineNuxtPlugin(async (nuxtApp) => {
const isOpenGraphCrawler = BOT_RE.test(userAgent)
if (isOpenGraphCrawler) {
// Redirect bots to the original instance to respect their social sharing settings
await sendRedirect(nuxtApp.ssrContext!.event, `https:/${route.path}`, 301)
await sendRedirect(nuxtApp.ssrContext!.event, `https:/${routePath}`, 301)
}
})