|
1 | 1 | <script setup lang="ts"> |
2 | 2 | import CopyToClipboardButton from '@/components/generic/CopyToClipboardButton.vue'; |
3 | 3 | import env from '@/env'; |
| 4 | +import { $t } from '@/i18n'; |
4 | 5 | import { NFlex } from 'naive-ui'; |
| 6 | +import { computed } from 'vue'; |
5 | 7 |
|
6 | | -defineProps<{ |
| 8 | +const props = defineProps<{ |
7 | 9 | locationId: string; |
8 | 10 | textSlug?: string; |
9 | 11 | aliases?: string[]; |
10 | 12 | }>(); |
11 | 13 |
|
12 | 14 | const baseUrl = `${origin}/${env.WEB_PATH_STRIPPED}`.replace(/\/+$/, ''); |
| 15 | +const data = computed( |
| 16 | + () => |
| 17 | + props.aliases?.map((alias) => ({ |
| 18 | + text: alias, |
| 19 | + tip: $t('browse.location.aliasesTip'), |
| 20 | + url: encodeURI( |
| 21 | + `${baseUrl}/bookmark/${props.locationId}/${props.textSlug || 'unknown'}/${alias}` |
| 22 | + ), |
| 23 | + })) || [ |
| 24 | + { |
| 25 | + text: $t('browse.location.shareLocUrl'), |
| 26 | + tip: $t('browse.location.genericPermalinkTip'), |
| 27 | + url: encodeURI(`${baseUrl}/bookmark/${props.locationId}/${props.textSlug || 'unknown'}`), |
| 28 | + }, |
| 29 | + ] |
| 30 | +); |
13 | 31 | </script> |
14 | 32 |
|
15 | 33 | <template> |
16 | 34 | <n-flex align="center" class="my-lg"> |
17 | | - <template v-if="!!aliases?.length"> |
18 | | - <copy-to-clipboard-button |
19 | | - v-for="alias in aliases" |
20 | | - :key="alias" |
21 | | - tertiary |
22 | | - size="tiny" |
23 | | - :text="`${baseUrl}/bookmark/${locationId}/${textSlug || 'unknown'}/${alias}`" |
24 | | - :title="$t('browse.location.aliasesTip')" |
25 | | - show-msg |
26 | | - > |
27 | | - {{ alias }} |
28 | | - </copy-to-clipboard-button> |
29 | | - </template> |
30 | 35 | <copy-to-clipboard-button |
31 | | - v-else |
| 36 | + v-for="(alias, index) in data" |
| 37 | + :key="`alias_${index}`" |
32 | 38 | tertiary |
33 | 39 | size="tiny" |
34 | | - :text="`${baseUrl}/bookmark/${locationId}/${textSlug || 'unknown'}`" |
35 | | - :title="$t('browse.location.genericPermalinkTip')" |
| 40 | + :text="alias.url" |
| 41 | + :title="alias.tip" |
36 | 42 | show-msg |
37 | 43 | > |
38 | | - {{ $t('browse.location.shareLocUrl') }} |
| 44 | + {{ alias.text }} |
39 | 45 | </copy-to-clipboard-button> |
40 | 46 | </n-flex> |
41 | 47 | </template> |
|
0 commit comments