Skip to content

Commit d01f3b8

Browse files
committed
URI-encode permalinks
1 parent 1a79450 commit d01f3b8

File tree

1 file changed

+24
-18
lines changed

1 file changed

+24
-18
lines changed

Tekst-Web/src/components/browse/LocationAliasesWidget.vue

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,47 @@
11
<script setup lang="ts">
22
import CopyToClipboardButton from '@/components/generic/CopyToClipboardButton.vue';
33
import env from '@/env';
4+
import { $t } from '@/i18n';
45
import { NFlex } from 'naive-ui';
6+
import { computed } from 'vue';
57
6-
defineProps<{
8+
const props = defineProps<{
79
locationId: string;
810
textSlug?: string;
911
aliases?: string[];
1012
}>();
1113
1214
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+
);
1331
</script>
1432

1533
<template>
1634
<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>
3035
<copy-to-clipboard-button
31-
v-else
36+
v-for="(alias, index) in data"
37+
:key="`alias_${index}`"
3238
tertiary
3339
size="tiny"
34-
:text="`${baseUrl}/bookmark/${locationId}/${textSlug || 'unknown'}`"
35-
:title="$t('browse.location.genericPermalinkTip')"
40+
:text="alias.url"
41+
:title="alias.tip"
3642
show-msg
3743
>
38-
{{ $t('browse.location.shareLocUrl') }}
44+
{{ alias.text }}
3945
</copy-to-clipboard-button>
4046
</n-flex>
4147
</template>

0 commit comments

Comments
 (0)