forked from Mirrors/elk
feat: implement social previews by redirecting to origin server (#1144)
This commit is contained in:
parent
a8e1cb86f3
commit
d46ddbe2b4
1 changed files with 16 additions and 0 deletions
16
plugins/social.server.ts
Normal file
16
plugins/social.server.ts
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
import { sendRedirect } from 'h3'
|
||||||
|
|
||||||
|
export default defineNuxtPlugin(async (nuxtApp) => {
|
||||||
|
const route = useRoute()
|
||||||
|
if (!route.params.server)
|
||||||
|
return
|
||||||
|
|
||||||
|
const req = nuxtApp.ssrContext!.event.node.req
|
||||||
|
const userAgent = req.headers['user-agent']!
|
||||||
|
if (!userAgent)
|
||||||
|
return
|
||||||
|
|
||||||
|
const isOpenGraphCrawler = /twitterbot|discordbot|facebookexternalhit|googlebot|msnbot|baidu|ahrefsbot|duckduckgo/i.test(userAgent)
|
||||||
|
if (isOpenGraphCrawler)
|
||||||
|
await sendRedirect(nuxtApp.ssrContext!.event, `https:/${route.path}`, 301)
|
||||||
|
})
|
Loading…
Reference in a new issue