mirror of
https://github.com/elk-zone/elk.git
synced 2024-11-23 18:05:25 +03:00
feat: add ability to redirect to source post when using default server
This commit is contained in:
parent
b9394c2fa5
commit
fa42d7f86a
1 changed files with 12 additions and 3 deletions
|
@ -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)
|
||||
}
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue