feat(docs): preview page jumps to github with pr number (#15854)

* feat(docs): preview page jumps to github with pr number

* feat: remove return

* chore: update

* chore: update

* chore: use globalThis

* feat: update
This commit is contained in:
btea
2024-02-18 15:55:19 +08:00
committed by GitHub
parent 66fc9a483f
commit 725f1e08cd

View File

@@ -1,16 +1,28 @@
<script setup lang="ts">
import { onMounted, ref } from 'vue'
import type { Component } from 'vue'
defineProps<{
const props = defineProps<{
icon: Component
link: string
text: string
}>()
const targetLink = ref(props.link)
onMounted(() => {
if (props.text === 'GitHub') {
const isPreview = globalThis.location?.host.startsWith('preview')
if (isPreview) {
const pr = globalThis.location.host.split('-', 2)[1]
targetLink.value = `${targetLink.value}/pull/${pr}`
}
}
})
</script>
<template>
<a
:href="link"
:href="targetLink"
:title="text"
target="_blank"
rel="noreferrer noopener"