Skip to content

Openverse is a search engine for openly-licensed media. This monorepo includes all application code.

Make VLink component that wraps around both external and internal links (#879)

Olga Bulat69e096f2cb3c
diff --git a/src/components/AudioDetails/VAudioDetails.vue b/src/components/AudioDetails/VAudioDetails.vue
index d4e84a57b..b3e7d5e36 100644
--- a/src/components/AudioDetails/VAudioDetails.vue
+++ b/src/components/AudioDetails/VAudioDetails.vue
@@ -22,7 +22,9 @@
<div v-if="audio.audio_set">
<dt>{{ $t('audio-details.table.album') }}</dt>
<dd>
- <a :href="audio.audio_set.url">{{ audio.audio_set.name }}</a>
+ <VLink :href="audio.audio_set.url">{{
+ audio.audio_set.name
+ }}</VLink>
</dd>
</div>
<div v-if="audio.category">
@@ -52,13 +54,9 @@
{{ $t('audio-details.table.provider') }}
</dt>
<dd>
- <a
- :href="audio.foreign_landing_url"
- target="blank"
- rel="noopener noreferrer"
- >
+ <VLink :href="audio.foreign_landing_url">
{{ providerName }}
- </a>
+ </VLink>
</dd>
</div>
<div v-if="audio.source && sourceName !== providerName">
@@ -87,13 +85,13 @@
import getProviderName from '~/utils/get-provider-name'
import { PROVIDER } from '~/constants/store-modules'
import { mapState } from 'vuex'
-
+import VLink from '~/components/VLink.vue'
import VAudioThumbnail from '~/components/VAudioThumbnail/VAudioThumbnail.vue'
import VMediaTag from '~/components/VMediaTag/VMediaTag.vue'
export default {
name: 'VAudioDetails',
- components: { VAudioThumbnail, VMediaTag },
+ components: { VAudioThumbnail, VLink, VMediaTag },
props: ['audio'],
computed: {
...mapState(PROVIDER, ['audioProviders']),
diff --git a/src/components/AudioDetails/VRelatedAudio.vue b/src/components/AudioDetails/VRelatedAudio.vue
index e4ad72ce8..bd093c51f 100644
--- a/src/components/AudioDetails/VRelatedAudio.vue
+++ b/src/components/AudioDetails/VRelatedAudio.vue
@@ -24,10 +24,13 @@ import { computed, ref } from '@nuxtjs/composition-api'
import { AUDIO } from '~/constants/media'
import useRelated from '~/composables/use-related'
-import { isMinScreen } from '@/composables/use-media-query'
+import { isMinScreen } from '~/composables/use-media-query'
+import VAudioTrack from '~/components/VAudioTrack/VAudioTrack.vue'
+import LoadingIcon from '~/components/LoadingIcon.vue'
export default {
name: 'VRelatedAudio',
+ components: { VAudioTrack, LoadingIcon },
props: {
audioId: {
type: String,
diff --git a/src/components/DownloadButton.vue b/src/components/DownloadButton.vue
index e303c3839..200245f23 100644
--- a/src/components/DownloadButton.vue
+++ b/src/components/DownloadButton.vue
@@ -6,7 +6,7 @@
:size="size"
>
<template #default="{ buttonProps }">
- <a
+ <VLink
v-bind="buttonProps"
class="whitespace-nowrap"
:href="selectedFormat.download_url"
@@ -19,7 +19,7 @@
<span class="ms-1 font-normal">{{
getFormatSize(selectedFormat.extension_name)
}}</span>
- </a>
+ </VLink>
</template>
<template
@@ -62,13 +62,14 @@
import filesize from 'filesize'
import axios from 'axios'
import local from '~/utils/local'
-import DropdownButton from '~/components/DropdownButton'
+import DropdownButton from '~/components/DropdownButton.vue'
+import VLink from '~/components/VLink.vue'
const LS_DOWNLOAD_FORMAT_EXTENSION_KEY = 'openverse:download-format-extension'
export default {
name: 'DownloadButton',
- components: { DropdownButton },
+ components: { DropdownButton, VLink },
props: {
formats: {
type: Array,
diff --git a/src/components/ExtensionBrowsers.vue b/src/components/ExtensionBrowsers.vue
index 09820b1b1..dc6c00c59 100644
--- a/src/components/ExtensionBrowsers.vue
+++ b/src/components/ExtensionBrowsers.vue
@@ -1,15 +1,13 @@
<template>
<ul class="buttons is-centered">
<li v-for="(browser, key) in browsers" :key="key">
- <a
- target="_blank"
- rel="nofollow noreferrer"
+ <VLink
:href="browser.extUrl"
class="browser-button button small me-2 is-opaque"
>
{{ $t(`browsers.${key}`) }}
<img class="ms-2" :src="browser.logo" :alt="$t(`browsers.${key}`)" />
- </a>
+ </VLink>
</li>
</ul>
</template>
diff --git a/src/components/ImageDetails/ReuseSurvey.vue b/src/components/ImageDetails/ReuseSurvey.vue
index 248b6042e..492e2f76f 100644
--- a/src/components/ImageDetails/ReuseSurvey.vue
+++ b/src/components/ImageDetails/ReuseSurvey.vue
@@ -1,15 +1,13 @@
<template>
<div class="reuse-survey caption mt-1">
{{ $t('photo-details.survey.content') }}
- <a
+ <VLink
:href="formLink"
- target="_blank"
- rel="noopener"
@click="onReuseSurveyClick"
@keyup.enter="onReuseSurveyClick"
>
{{ $t('photo-details.survey.link') }}
- </a>
+ </VLink>
{{ $t('photo-details.survey.answer') }}
</div>
</template>
@@ -20,6 +18,7 @@ import {
DETAIL_PAGE_EVENTS,
} from '~/constants/usage-data-analytics-types'
import { USAGE_DATA } from '~/constants/store-modules'
+import VLink from '~/components/VLink.vue'
const reuseForm =
'https://docs.google.com/forms/d/e/1FAIpQLSegPUDIUj_odzclJhhWRfPumSfbHtXDVDCHqRfFl7ZS8cMn2g/viewform'
@@ -27,6 +26,7 @@ const imageLinkEntry = '2039681354'
export default {
name: 'ReuseSurvey',
+ components: { VLink },
props: ['image'],
data: () => ({
location: '',
diff --git a/src/components/ImageGrid/ImageCell.vue b/src/components/ImageGrid/ImageCell.vue
index 3c79aa36a..132d63e9f 100644
--- a/src/components/ImageGrid/ImageCell.vue
+++ b/src/components/ImageGrid/ImageCell.vue
@@ -7,8 +7,8 @@
>
<figure class="search-grid_item">
<i :style="`padding-bottom:${iPadding}%`" />
- <NuxtLink
- :to="localePath('/image/' + image.id)"
+ <VLink
+ :href="'/image/' + image.id"
class="search-grid_image-ctr"
:style="`width: ${imageWidth}%; top: ${imageTop}%; left:${imageLeft}%;`"
@click="onGotoDetailPage($event, image)"
@@ -25,7 +25,7 @@
@load="getImgDimension"
@error="onImageLoadError($event, image)"
/>
- </NuxtLink>
+ </VLink>
<figcaption class="overlay overlay__top p-2">
<VLicense
:license="image.license"
@@ -42,6 +42,7 @@
<script>
import VLicense from '~/components/License/VLicense.vue'
+import VLink from '~/components/VLink.vue'
const errorImage = require('~/assets/image_not_available_placeholder.png')
@@ -59,7 +60,7 @@ const toAbsolutePath = (url, prefix = 'https://') => {
export default {
name: 'ImageCell',
- components: { VLicense },
+ components: { VLicense, VLink },
props: ['image', 'shouldContainImage'],
data() {
return {
diff --git a/src/components/VAllResultsGrid/VImageCell.vue b/src/components/VAllResultsGrid/VImageCell.vue
index 4ca4f8f12..4556905ff 100644
--- a/src/components/VAllResultsGrid/VImageCell.vue
+++ b/src/components/VAllResultsGrid/VImageCell.vue
@@ -1,10 +1,9 @@
<template>
- <NuxtLink
+ <VLink
itemprop="contentUrl"
:title="image.title"
- :to="localePath('/image/' + image.id)"
+ :href="'/image/' + image.id"
class="group block focus:bg-white focus:ring focus:ring-pink focus:outline-none focus:shadow-ring focus:text-black rounded-sm"
- @click="onGotoDetailPage($event, image)"
>
<figure
itemprop="image"
@@ -34,7 +33,7 @@
/>
</figcaption>
</figure>
- </NuxtLink>
+ </VLink>
</template>
<script>
diff --git a/src/components/VAudioTrack/layouts/VFullLayout.vue b/src/components/VAudioTrack/layouts/VFullLayout.vue
index 24166ca24..764364d91 100644
--- a/src/components/VAudioTrack/layouts/VFullLayout.vue
+++ b/src/components/VAudioTrack/layouts/VFullLayout.vue
@@ -41,12 +41,12 @@
class="font-semibold leading-snug"
>
<template #creator>
- <a
+ <VLink
class="p-px rounded-sm focus:outline-none focus:ring focus:ring-pink"
:href="audio.creator_url"
>
{{ audio.creator }}
- </a>
+ </VLink>
</template>
</i18n>
@@ -71,11 +71,13 @@
import { computed, defineComponent } from '@nuxtjs/composition-api'
import DownloadButton from '~/components/DownloadButton.vue'
+import VLink from '~/components/VLink.vue'
export default defineComponent({
name: 'VFullLayout',
components: {
DownloadButton,
+ VLink,
},
props: ['audio', 'size', 'status', 'currentTime'],
setup(props) {
diff --git a/src/components/VAudioTrack/layouts/VRowLayout.vue b/src/components/VAudioTrack/layouts/VRowLayout.vue
index fd1055466..4538b75ab 100644
--- a/src/components/VAudioTrack/layouts/VRowLayout.vue
+++ b/src/components/VAudioTrack/layouts/VRowLayout.vue
@@ -21,14 +21,14 @@
}"
>
<div class="flex-shrink-0" :class="{ 'w-70': isMedium }">
- <NuxtLink
- :to="localePath(`/audio/${audio.id}`)"
+ <VLink
+ :href="`/audio/${audio.id}`"
class="block font-heading font-semibold line-clamp-2 md:line-clamp-1 text-dark-charcoal hover:text-dark-charcoal p-px rounded-sm focus:outline-none focus:ring focus:ring-pink"
:class="{
'text-2xl': isMedium || isLarge,
'leading-snug': isSmall,
}"
- >{{ audio.title }}</NuxtLink
+ >{{ audio.title }}</VLink
>
<div
@@ -88,12 +88,14 @@ import { useBrowserIsBlink } from '~/composables/use-browser-detection'
import VAudioThumbnail from '~/components/VAudioThumbnail/VAudioThumbnail.vue'
import VLicense from '~/components/License/VLicense.vue'
+import VLink from '~/components/VLink.vue'
export default defineComponent({
name: 'VRowLayout',
components: {
VAudioThumbnail,
VLicense,
+ VLink,
},
props: ['audio', 'size'],
setup(props) {
diff --git a/src/components/VBackToSearchResultsLink.vue b/src/components/VBackToSearchResultsLink.vue
index 9b4bc3bba..5419f3c40 100644
--- a/src/components/VBackToSearchResultsLink.vue
+++ b/src/components/VBackToSearchResultsLink.vue
@@ -1,13 +1,13 @@
<template>
- <!-- @todo: Seperate the absolute container from the link itself. -->
- <NuxtLink
+ <!-- @todo: Separate the absolute container from the link itself. -->
+ <VLink
v-if="show"
class="px-2 pt-1 md:px-6 md:pt-4 md:pb-2 flex flex-row items-center font-semibold text-dark-charcoal text-xs md:text-sr"
- :to="path"
+ :href="path"
>
<Chevron class="-ms-2" />
{{ $t('single-result.back') }}
- </NuxtLink>
+ </VLink>
</template>
<script>
diff --git a/src/components/VButton.vue b/src/components/VButton.vue
index 34cf3cb6a..54ef93c5a 100644
--- a/src/components/VButton.vue
+++ b/src/components/VButton.vue
@@ -30,7 +30,8 @@ import {
toRefs,
computed,
} from '@nuxtjs/composition-api'
-import { warn } from '~/utils/warn'
+import VLink from '~/components/VLink.vue'
+import { warn } from '@/utils/warn'
/**
* A button component that behaves just like a regular HTML `button` element
@@ -46,26 +47,27 @@ import { warn } from '~/utils/warn'
*/
const VButton = defineComponent({
name: 'VButton',
+ components: { VLink },
props: {
/**
* Passed to `component :is` to allow the button to *appear* as a button but
* work like another element (like an `anchor`). May only be either `button` or `a`.
*
- * We do not support other elements because their use cases are marginal and they
+ * We do not support other elements because their use cases are marginal, and they
* add complexity that we can avoid otherwise.
*
- * We also don't allow any old Vue component because Vue does not have ref-forwarding
+ * We also don't allow any old Vue component because Vue does not have ref-forwarding,
* so we wouldn't be able to detect the type of the DOM node that is ultimately rendered
* by any Vue component passed.
*
* @default 'button'
*/
as: {
- type: /** @type {import('@nuxtjs/composition-api').PropType<'a' | 'button'>} */ (
+ type: /** @type {import('@nuxtjs/composition-api').PropType<'VLink' | 'button'>} */ (
String
),
default: 'button',
- validate: (v) => ['a', 'button', 'NuxtLink'].includes(v),
+ validate: (v) => ['VLink', 'button'].includes(v),
},
/**
* The variant of the button.
@@ -186,24 +188,13 @@ const VButton = defineComponent({
watch(
propsRef.as,
(as) => {
- if (['a', 'NuxtLink'].includes(as)) {
+ if (['VLink'].includes(as)) {
typeRef.value = undefined
supportsDisabledAttributeRef.value = false
- if (as === 'a') {
- // No need to declare `href` as an explicit prop as Vue preserves
- // the `attrs` object reference between renders and updates the properties
- // meaning we'll always have the latest values for the properties on the
- // attrs object
- if (!attrs.href || attrs.href === '#') {
- warn(
- 'Do not use anchor elements without a valid `href` attribute. Use a `button` instead.'
- )
- }
- } else {
- if (!attrs.to) {
- warn('NuxtLink needs a `to` attribute')
- }
- }
+ } else if (['a', 'NuxtLink'].includes(as)) {
+ warn(
+ `Please use \`VLink\` with an \`href\` prop instead of ${as} for the button component`
+ )
}
},
{ immediate: true }
diff --git a/src/components/VContentLink/VContentLink.vue b/src/components/VContentLink/VContentLink.vue
index 6cca93859..f3906378b 100644
--- a/src/components/VContentLink/VContentLink.vue
+++ b/src/components/VContentLink/VContentLink.vue
@@ -1,6 +1,6 @@
<template>
- <NuxtLink
- :to="to"
+ <VLink
+ :href="to"
class="text-dark-charcoal bg-white border border-dark-charcoal/20 rounded-sm flex flex-col md:flex-row md:justify-between items-start md:items-center hover:bg-dark-charcoal hover:text-white hover:no-underline focus:border-tx overflow-hidden py-4 ps-4 pe-12 w-full md:p-6"
>
<div class="flex flex-col items-start md:flex-row md:items-center">
@@ -13,7 +13,7 @@
</p>
</div>
<span class="text-sr">{{ resultsCountLabel }}</span>
- </NuxtLink>
+ </VLink>
</template>
<script>
diff --git a/src/components/VContentReport/VContentReportForm.vue b/src/components/VContentReport/VContentReportForm.vue
index d57438ee1..6038dbda1 100644
--- a/src/components/VContentReport/VContentReportForm.vue
+++ b/src/components/VContentReport/VContentReportForm.vue
@@ -10,13 +10,9 @@
tag="p"
>
<template #source>
- <a
- :href="media.url"
- class="text-pink hover:underline"
- target="_blank"
- rel="noopener"
- >{{ providerName }}</a
- >
+ <VLink :href="media.url" class="text-pink hover:underline">{{
+ providerName
+ }}</VLink>
</template>
</i18n>
</div>
@@ -81,7 +77,7 @@
<VButton
v-if="selectedReason === reasons.DMCA"
key="dmca"
- as="a"
+ as="VLink"
variant="secondary"
:href="DMCA_FORM_URL"
target="_blank"
@@ -114,6 +110,7 @@ import VIcon from '~/components/VIcon/VIcon.vue'
import VRadio from '~/components/VRadio/VRadio.vue'
import VDmcaNotice from '~/components/VContentReport/VDmcaNotice.vue'
import VReportDescForm from '~/components/VContentReport/VReportDescForm.vue'
+import VLink from '~/components/VLink.vue'
import ReportService from '~/data/report-service'
@@ -126,6 +123,7 @@ export default defineComponent({
components: {
VButton,
VIcon,
+ VLink,
VRadio,
VDmcaNotice,
VReportDescForm,
diff --git a/src/components/VContentReport/VDmcaNotice.vue b/src/components/VContentReport/VDmcaNotice.vue
index 009bcf07e..caf516c50 100644
--- a/src/components/VContentReport/VDmcaNotice.vue
+++ b/src/components/VContentReport/VDmcaNotice.vue
@@ -5,23 +5,17 @@
tag="p"
>
<template #form>
- <a
+ <VLink
:aria-label="$t('media-details.content-report.form.dmca.form')"
:href="DMCA_FORM_URL"
class="text-pink hover:underline"
- target="_blank"
- rel="noopener"
- >{{ $t('media-details.content-report.form.dmca.form') }}</a
+ >{{ $t('media-details.content-report.form.dmca.form') }}</VLink
>
</template>
<template #source>
- <a
- :href="foreignLandingUrl"
- class="text-pink hover:underline"
- target="_blank"
- rel="noopener noreferrer"
- >{{ provider }}</a
- >
+ <VLink :href="foreignLandingUrl" class="text-pink hover:underline">{{
+ provider
+ }}</VLink>
</template>
</i18n>
</template>
@@ -30,9 +24,11 @@
import { defineComponent } from '@nuxtjs/composition-api'
import { DMCA_FORM_URL } from '~/constants/content-report'
+import VLink from '~/components/VLink.vue'
export default defineComponent({
name: 'VDmcaNotice',
+ components: { VLink },
props: {
/**
* the foreign landing URL for the media item
diff --git a/src/components/VContentSwitcher/VMobileMenuModal.vue b/src/components/VContentSwitcher/VMobileMenuModal.vue
index 265c802b6..8e3e60c84 100644
--- a/src/components/VContentSwitcher/VMobileMenuModal.vue
+++ b/src/components/VContentSwitcher/VMobileMenuModal.vue
@@ -43,15 +43,11 @@ import { useBodyScrollLock } from '~/composables/use-body-scroll-lock'
import useContentType from '~/composables/use-content-type'
import usePages from '~/composables/use-pages'
-import externalLinkIcon from 'assets/icons/external-link.svg'
-
import VMobileModalContent from '~/components/VModal/VMobileModalContent.vue'
import VContentTypes from '~/components/VContentSwitcher/VContentTypes.vue'
import VPageList from '~/components/VHeader/VPageMenu/VPageList.vue'
import VContentSwitcherButton from '~/components/VContentSwitcher/VContentSwitcherButton'
-const externalLinkProps = { as: 'a', target: '_blank', rel: 'noopener' }
-
export default {
name: 'VMobileContentSwitcher',
components: {
@@ -121,16 +117,7 @@ export default {
emit('select', item)
}
- const isLinkExternal = (item) => !item.link.startsWith('/')
- const getLinkProps = (item) => {
- return isLinkExternal(item)
- ? { ...externalLinkProps, href: item.link }
- : { as: 'NuxtLink', to: item.link }
- }
return {
- getLinkProps,
- isLinkExternal,
- externalLinkIcon,
pages,
content,
close,
diff --git a/src/components/VFilters/VLicenseExplanationTooltip.vue b/src/components/VFilters/VLicenseExplanationTooltip.vue
index e1f0b7086..2166f1501 100644
--- a/src/components/VFilters/VLicenseExplanationTooltip.vue
+++ b/src/components/VFilters/VLicenseExplanationTooltip.vue
@@ -16,9 +16,9 @@
class="caption float-right m-2"
>
<template #link>
- <a target="_blank" :href="`${getLicenseDeedLink(license)}`">{{
+ <VLink :href="`${getLicenseDeedLink(license)}`">{{
$t('filters.license-explanation.link')
- }}</a>
+ }}</VLink>
</template>
</i18n>
<i18n
@@ -28,9 +28,9 @@
class="caption float-right m-2"
>
<template #link>
- <a target="_blank" :href="`${getLicenseDeedLink(license)}`">{{
+ <VLink :href="`${getLicenseDeedLink(license)}`">{{
$t('filters.license-explanation.link')
- }}</a>
+ }}</VLink>
</template>
</i18n>
</div>
@@ -38,10 +38,12 @@
<script>
import { isLicense } from '~/utils/license'
+import VLink from '~/components/VLink.vue'
+import LicenseElements from '~/components/LicenseElements.vue'
export default {
name: 'VLicenseExplanationTooltip',
-
+ components: { VLink, LicenseElements },
props: {
license: {
type: String,
diff --git a/src/components/VFourOhFour.vue b/src/components/VFourOhFour.vue
index 81958db4e..3743dd58c 100644
--- a/src/components/VFourOhFour.vue
+++ b/src/components/VFourOhFour.vue
@@ -1,6 +1,6 @@
<template>
<main class="bg-yellow h-screen relative page-404 overflow-x-hidden">
- <NuxtLink to="/" class="relative z-10 text-dark-charcoal">
+ <VLink href="/" class="relative z-10 text-dark-charcoal">
<span class="sr-only">{{ $t('404.link-title') }}</span>
<span
class="flex flex-row pt-6 lg:pt-8 ms-6 lg:ms-10 h-auto w-30 text-dark-charcoal"
@@ -9,7 +9,7 @@
<OpenverseLogo />
<OpenverseBrand class="ms-1" />
</span>
- </NuxtLink>
+ </VLink>
<Oops
aria-hidden="true"
class="absolute opacity-5 fill-dark-charcoal -mt-[10%] -ml-[20%] lg:mx-auto w-[140%] lg:w-full px-6 lg:px-16 z-0 pointer-events-none"
@@ -23,12 +23,11 @@
<p class="font-semibold">
<i18n path="404.main">
<template #link>
- <NuxtLink
+ <VLink
class="underline text-current hover:text-current active:text-current"
- to="/"
+ href="/"
+ >{{ $t('404.link-title') }}</VLink
>
- {{ $t('404.link-title') }}
- </NuxtLink>
</template>
</i18n>
</p>
diff --git a/src/components/VHeader/VLogoButton.vue b/src/components/VHeader/VLogoButton.vue
index 2e081d2cf..54c306079 100644
--- a/src/components/VHeader/VLogoButton.vue
+++ b/src/components/VHeader/VLogoButton.vue
@@ -1,7 +1,7 @@
<template>
<VButton
- as="NuxtLink"
- :to="localePath('/')"
+ as="VLink"
+ href="/"
variant="plain"
size="disabled"
class="max-w-min hover:bg-yellow text-dark-charcoal"
diff --git a/src/components/VHeader/VPageMenu/VPageList.vue b/src/components/VHeader/VPageMenu/VPageList.vue
index 2e0f76726..0dcff9407 100644
--- a/src/components/VHeader/VPageMenu/VPageList.vue
+++ b/src/components/VHeader/VPageMenu/VPageList.vue
@@ -34,8 +34,6 @@ import VIcon from '~/components/VIcon/VIcon.vue'
import VItem from '~/components/VItemGroup/VItem.vue'
import VItemGroup from '~/components/VItemGroup/VItemGroup.vue'
-const externalLinkProps = { as: 'a', target: '_blank', rel: 'noopener' }
-
export default {
name: 'VPageMenuPopover',
components: { VIcon, VItem, VItemGroup },
@@ -48,12 +46,10 @@ export default {
},
setup() {
const pages = usePages()
+
const isLinkExternal = (item) => !item.link.startsWith('/')
- const getLinkProps = (item) => {
- return isLinkExternal(item)
- ? { ...externalLinkProps, href: item.link }
- : { as: 'NuxtLink', to: item.link }
- }
+ const getLinkProps = (item) => ({ as: 'VLink', href: item.link })
+
return {
getLinkProps,
isLinkExternal,
diff --git a/src/components/VImageDetails/VImageDetails.vue b/src/components/VImageDetails/VImageDetails.vue
index 7266790c8..9a9e34edd 100644
--- a/src/components/VImageDetails/VImageDetails.vue
+++ b/src/components/VImageDetails/VImageDetails.vue
@@ -26,13 +26,9 @@
<div>
<dt>{{ $t('image-details.information.source') }}</dt>
<dd>
- <a
- :href="image.foreign_landing_url"
- target="blank"
- rel="noopener noreferrer"
- class="text-pink"
- >{{ sourceName }}</a
- >
+ <VLink :href="image.foreign_landing_url" class="text-pink">{{
+ sourceName
+ }}</VLink>
</dd>
</div>
<div>
diff --git a/src/components/VItemGroup/VItem.vue b/src/components/VItemGroup/VItem.vue
index d271e1259..79e13b0a2 100644
--- a/src/components/VItemGroup/VItem.vue
+++ b/src/components/VItemGroup/VItem.vue
@@ -92,12 +92,12 @@ export default defineComponent({
/**
* To change the underlying component for the VButton,
* pass `as` prop.
- * @variants 'button', 'a', 'NuxtLink'
+ * @variants 'button', 'VLink'
*/
as: {
type: String,
default: 'button',
- validator: (val) => ['button', 'a', 'NuxtLink'].includes(val),
+ validator: (val) => ['button', 'VLink'].includes(val),
},
},
/**
diff --git a/src/components/VLink.vue b/src/components/VLink.vue
new file mode 100644
index 000000000..01f22a5c7
--- /dev/null
+++ b/src/components/VLink.vue
@@ -0,0 +1,53 @@
+<template>
+ <Component :is="linkComponent" v-bind="linkProperties" v-on="$listeners"
+ ><slot
+ /></Component>
+</template>
+
+<script>
+/**
+ * This is a wrapper component for all links. If a link is dynamically generated and doesn't have
+ * an `href` prop (as the links for detail pages when the image detail hasn't loaded yet),
+ * it is rendered as a `span`.
+ * Links with `href` starting with `/` are treated as internal links.
+ *
+ * Internal links use `NuxtLink` component with `to` attribute set to `localePath(href)`
+ * External links use `a` element set to open in a new tab and not raise an error with the current iframe setup.
+ */
+import { computed, defineComponent, useContext } from '@nuxtjs/composition-api'
+
+const defaultProps = { target: '_blank', rel: 'noopener noreferrer' }
+
+export default defineComponent({
+ name: 'VLink',
+ props: {
+ href: {
+ type: String,
+ validator: (v) =>
+ (typeof v === 'string' && v.length > 0) || typeof v === 'undefined',
+ },
+ },
+ setup(props) {
+ const { app } = useContext()
+ const hasHref = computed(
+ () => typeof props.href === 'string' && !['', '#'].includes(props.href)
+ )
+ const isInternal = computed(
+ () => hasHref.value && props.href.startsWith('/')
+ )
+ const linkComponent = computed(() =>
+ hasHref.value ? (isInternal.value ? 'NuxtLink' : 'a') : 'span'
+ )
+
+ let linkProperties = computed(() =>
+ hasHref.value
+ ? isInternal.value
+ ? { to: app?.localePath(props.href) ?? props.href }
+ : { ...defaultProps, href: props.href }
+ : null
+ )
+
+ return { linkProperties, linkComponent }
+ },
+})
+</script>
diff --git a/src/components/VMediaInfo/VCopyLicense.vue b/src/components/VMediaInfo/VCopyLicense.vue
index 4b196debf..5359f07c2 100644
--- a/src/components/VMediaInfo/VCopyLicense.vue
+++ b/src/components/VMediaInfo/VCopyLicense.vue
@@ -42,13 +42,11 @@
tag="p"
>
<template #title>
- <a
+ <VLink
:href="media.foreign_landing_url"
- target="_blank"
- rel="noopener"
@click="onSourceLinkClicked"
@keyup.enter="onSourceLinkClicked"
- >{{ media.title }}</a
+ >{{ media.title }}</VLink
></template
>
<template #creator>
@@ -58,14 +56,12 @@
tag="span"
>
<template #creator-name>
- <a
+ <VLink
v-if="media.creator_url"
:href="media.creator_url"
- target="_blank"
- rel="noopener"
@click="onCreatorLinkClicked"
@keyup.enter="onCreatorLinkClicked"
- >{{ media.creator }}</a
+ >{{ media.creator }}</VLink
>
<span v-else>{{ media.creator }}</span>
</template>
@@ -79,12 +75,9 @@
}}
</template>
<template #license>
- <a
- class="uppercase"
- :href="licenseUrl"
- target="_blank"
- rel="noopener"
- >{{ fullLicenseName }}</a
+ <VLink class="uppercase" :href="licenseUrl">{{
+ fullLicenseName
+ }}</VLink
>{{ period }}
</template>
</i18n>
@@ -156,7 +149,6 @@ import {
ref,
useContext,
} from '@nuxtjs/composition-api'
-import CopyButton from '~/components/CopyButton.vue'
import { USAGE_DATA } from '~/constants/store-modules'
import {
SEND_DETAIL_PAGE_EVENT,
@@ -165,9 +157,11 @@ import {
import getAttributionHtml from '~/utils/attribution-html'
import { isPublicDomain } from '~/utils/license'
+import CopyButton from '~/components/CopyButton.vue'
+import VLink from '~/components/VLink.vue'
const VCopyLicense = defineComponent({
name: 'VCopyLicense',
- components: { CopyButton },
+ components: { CopyButton, VLink },
props: {
media: {
type: Object,
diff --git a/src/components/VMediaInfo/VMediaLicense.vue b/src/components/VMediaInfo/VMediaLicense.vue
index b353a593c..1b80e5cca 100644
--- a/src/components/VMediaInfo/VMediaLicense.vue
+++ b/src/components/VMediaInfo/VMediaLicense.vue
@@ -10,14 +10,9 @@
class="block text-sm md:text-base"
>
<template #link>
- <a
- class="uppercase text-pink"
- :href="licenseUrl"
- target="_blank"
- rel="noopener"
- >
+ <VLink class="uppercase text-pink" :href="licenseUrl">
{{ fullLicenseName }}
- </a>
+ </VLink>
</template>
</i18n>
<LicenseElements :license="license" class="md:py-4" />
@@ -28,13 +23,11 @@
class="caption font-semibold"
>
<template #link>
- <a
+ <VLink
:aria-label="$t('media-details.aria.attribution.license')"
:href="licenseUrl"
- target="_blank"
- rel="noopener"
class="text-pink"
- >{{ $t('media-details.reuse.license.link') }}</a
+ >{{ $t('media-details.reuse.license.link') }}</VLink
>
</template>
</i18n>
@@ -47,13 +40,11 @@
class="caption font-semibold"
>
<template #link>
- <a
+ <VLink
:aria-label="$t('media-details.aria.attribution.tool')"
:href="licenseUrl"
- target="_blank"
- rel="noopener"
class="text-pink"
- >{{ $t('media-details.reuse.tool.link') }}</a
+ >{{ $t('media-details.reuse.tool.link') }}</VLink
>
</template>
</i18n>
@@ -64,10 +55,11 @@
<script>
import { isLicense } from '~/utils/license'
import LicenseElements from '~/components/LicenseElements.vue'
+import VLink from '~/components/VLink.vue'
export default {
name: 'MediaLicense',
- components: { LicenseElements },
+ components: { LicenseElements, VLink },
props: {
fullLicenseName: String,
license: String,
diff --git a/src/components/VMediaTag/meta/VMediaTag.stories.mdx b/src/components/VMediaTag/meta/VMediaTag.stories.mdx
index 9fd97ef66..ed850ec67 100644
--- a/src/components/VMediaTag/meta/VMediaTag.stories.mdx
+++ b/src/components/VMediaTag/meta/VMediaTag.stories.mdx
@@ -29,7 +29,7 @@ By default, the component is a transparent wrapper over `<span>`.
</Canvas>
The root node of the tag can be overridden to a different HTML tag or a Vue
-component, e.g. `a` or `NuxtLink`. Any additional classes, such as for hover and
+component, e.g. `VLink`. Any additional classes, such as for hover and
focus states on interactive elements, can be applied to add to the base styles.
<Canvas>
diff --git a/src/components/VMetaSearch/VMetaSourceList.vue b/src/components/VMetaSearch/VMetaSourceList.vue
index b0d669e13..6aee9e516 100644
--- a/src/components/VMetaSearch/VMetaSourceList.vue
+++ b/src/components/VMetaSearch/VMetaSourceList.vue
@@ -2,17 +2,12 @@
<div class="mb-10">
<ul class="buttons is-centered mt-6">
<li v-for="source in sources" :key="source">
- <a
- target="_blank"
- rel="nofollow noreferrer"
- :href="getSourceUrl(source)"
- class="button small me-2 is-opaque"
- >
+ <VLink :href="getSourceUrl(source)" class="button small me-2 is-opaque">
{{ source }}
<sup class="top-0">
<i class="ms-2 icon external-link" />
</sup>
- </a>
+ </VLink>
</li>
</ul>
</div>
@@ -22,9 +17,11 @@
import getLegacySourceUrl, {
legacySourceMap,
} from '~/utils/get-legacy-source-url'
+import VLink from '~/components/VLink.vue'
export default {
name: 'MetaSourceList',
+ components: { VLink },
props: {
type: { type: String },
query: { type: Object },
diff --git a/src/components/VMigrationNotice.vue b/src/components/VMigrationNotice.vue
index 1f582ab7d..0aba6734f 100644
--- a/src/components/VMigrationNotice.vue
+++ b/src/components/VMigrationNotice.vue
@@ -3,11 +3,10 @@
{{ $t('migration-notice.intro') }}
<i18n tag="span" path="migration-notice.more">
<template #read-more>
- <a
+ <VLink
class="text-dark-blue hover:text-dark-blue underline"
href="https://wordpress.org/news/2021/05/welcome-to-openverse/"
- target="_blank"
- >{{ $t('migration-notice.read') }}</a
+ >{{ $t('migration-notice.read') }}</VLink
>
</template>
</i18n>
@@ -16,9 +15,10 @@
<script>
import VNoticeBar from '~/components/VNoticeBar/VNoticeBar.vue'
+import VLink from '~/components/VLink.vue'
export default {
name: 'VMigrationNotice',
- components: { VNoticeBar },
+ components: { VLink, VNoticeBar },
}
</script>
diff --git a/src/components/VTranslationStatusBanner.vue b/src/components/VTranslationStatusBanner.vue
index 257ed007f..ce3557641 100644
--- a/src/components/VTranslationStatusBanner.vue
+++ b/src/components/VTranslationStatusBanner.vue
@@ -6,9 +6,9 @@
}}
<i18n path="notification.translation.text">
<template #link>
- <a :href="translationLink" target="_blank" class="underline">{{
+ <VLink :href="translationLink" class="underline">{{
$t('notification.translation.link')
- }}</a>
+ }}</VLink>
</template>
<template #locale>
{{ bannerLocale.name }}
@@ -18,11 +18,13 @@
</template>
<script>
import useI18nSync from '~/composables/use-i18n-sync'
+import VLink from '~/components/VLink.vue'
import VNotificationBanner from '~/components/VNotificationBanner.vue'
export default {
name: 'VTranslationStatusBanner',
components: {
+ VLink,
VNotificationBanner,
},
setup() {
diff --git a/src/pages/about.vue b/src/pages/about.vue
index c7d2b6c61..166594fc5 100644
--- a/src/pages/about.vue
+++ b/src/pages/about.vue
@@ -10,82 +10,80 @@
<i18n path="about.collection.content" tag="p">
<template #common-crawl>
- <a
+ <VLink
:aria-label="$t('about.aria.common-crawl')"
href="http://commoncrawl.org/"
- >{{ $t('about.collection.common-crawl') }}</a
+ >{{ $t('about.collection.common-crawl') }}</VLink
>
</template>
</i18n>
<i18n path="about.planning.content" tag="p">
<template #meta>
- <NuxtLink
- :aria-label="$t('about.aria.meta')"
- :to="localePath('/meta-search')"
- >{{ $t('about.planning.meta') }}</NuxtLink
- >
+ <VLink :aria-label="$t('about.aria.meta')" href="/meta-search">{{
+ $t('about.planning.meta')
+ }}</VLink>
</template>
<template #search>
- <a
+ <VLink
:aria-label="$t('about.aria.search')"
href="https://github.com/wordpress/openverse-frontend/"
- >{{ $t('about.planning.search') }}</a
+ >{{ $t('about.planning.search') }}</VLink
>
</template>
<template #api>
- <a
+ <VLink
:aria-label="$t('about.aria.api')"
href="https://github.com/wordpress/openverse-api/"
- >{{ $t('about.planning.api') }}</a
+ >{{ $t('about.planning.api') }}</VLink
>
</template>
<template #catalog>
- <a
+ <VLink
:aria-label="$t('about.aria.catalog')"
href="https://github.com/wordpress/openverse-catalog/"
- >{{ $t('about.planning.catalog') }}</a
+ >{{ $t('about.planning.catalog') }}</VLink
>
</template>
<template #community>
- <a
+ <VLink
:aria-label="$t('about.aria.community')"
href="https://make.wordpress.org/openverse/"
- >{{ $t('about.planning.community') }}</a
+ >{{ $t('about.planning.community') }}</VLink
>
</template>
<template #working>
- <a
+ <VLink
:aria-label="$t('about.aria.projects')"
href="https://github.com/orgs/WordPress/projects/3"
- >{{ $t('about.planning.working') }}</a
+ >{{ $t('about.planning.working') }}</VLink
>
</template>
</i18n>
<i18n path="about.transfer.content" tag="p">
<template #creative-commons>
- <a
+ <VLink
:aria-label="$t('about.aria.creative-commons')"
href="https://creativecommons.org/2021/05/03/cc-search-to-join-wordpress/"
- >{{ $t('about.transfer.creative-commons') }}</a
+ >{{ $t('about.transfer.creative-commons') }}</VLink
>
</template>
<template #wordpress>
- <a
+ <VLink
:aria-label="$t('about.aria.wordpress')"
href="https://ma.tt/2021/04/cc-search-to-join-wordpress-org/"
- >{{ $t('about.transfer.wordpress') }}</a
+ >{{ $t('about.transfer.wordpress') }}</VLink
>
</template>
</i18n>
<i18n path="about.declaration.content" tag="p">
<template #terms>
- <a
+ <VLink
:aria-label="$t('about.aria.terms')"
href="https://creativecommons.org/terms/"
- >{{ $t('about.declaration.terms') }}</a
+ >{{ $t('about.declaration.terms') }}</VLink
>
</template>
</i18n>
@@ -96,14 +94,18 @@
</template>
<script>
-const AboutPage = {
- name: 'about-page',
+import VLink from '~/components/VLink.vue'
+import { defineComponent } from '@nuxtjs/composition-api'
+
+const AboutPage = defineComponent({
+ name: 'AboutPage',
+ components: { VLink },
head() {
return {
title: `${this.$t('about.title')} | ${this.$t('hero.brand')}`,
}
},
-}
+})
export default AboutPage
</script>
diff --git a/src/pages/feedback.vue b/src/pages/feedback.vue
index 0a514552e..257c9d16c 100644
--- a/src/pages/feedback.vue
+++ b/src/pages/feedback.vue
@@ -7,16 +7,13 @@
</h1>
<i18n path="feedback.description.content" tag="p" class="mb-6">
<template #openverse>
- <a
- href="https://wordpress.slack.com/messages/openverse/"
- target="_blank"
- >
- {{ $t('feedback.description.openverse') }}</a
+ <VLink href="https://wordpress.slack.com/messages/openverse/">
+ {{ $t('feedback.description.openverse') }}</VLink
>
</template>
<template #making-wordpress>
- <a href="https://make.wordpress.org/chat/" target="_blank">
- {{ $t('feedback.description.making-wordpress') }}</a
+ <VLink href="https://make.wordpress.org/chat/">
+ {{ $t('feedback.description.making-wordpress') }}</VLink
>
</template>
</i18n>
@@ -61,8 +58,7 @@
</template>
<script>
-import { mapState } from 'vuex'
-import { BUG_REPORT } from '~/constants/store-modules'
+import VLink from '~/components/VLink.vue'
const bugForm =
'https://docs.google.com/forms/d/e/1FAIpQLSenCn-3HoZlCz4vlL2621wjezfu1sPZDaWGe_FtQ1R5-5qR4Q/viewform'
@@ -71,6 +67,7 @@ const suggestionForm =
export const FeedbackPage = {
name: 'feedback-page',
+ components: { VLink },
data() {
return {
activeTab: 0,
@@ -97,19 +94,10 @@ export const FeedbackPage = {
this.activeTab = tabIdx
},
},
- computed: {
- ...mapState(BUG_REPORT, [
- 'isReportingBug',
- 'bugReported',
- 'bugReportFailed',
- ]),
- },
}
export default FeedbackPage
</script>
-
-<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="scss" scoped>
.form-iframe {
width: 100%;
diff --git a/src/pages/image/_id.vue b/src/pages/image/_id.vue
index 240a43f08..36879bf3c 100644
--- a/src/pages/image/_id.vue
+++ b/src/pages/image/_id.vue
@@ -29,7 +29,7 @@
class="flex flex-row md:flex-row-reverse flex-wrap justify-between md:mt-6"
>
<VButton
- as="a"
+ as="VLink"
:href="image.foreign_landing_url"
target="blank"
rel="noopener noreferrer"
@@ -50,7 +50,7 @@
class="font-semibold leading-[130%]"
>
<template #name>
- <a
+ <VLink
v-if="image.creator_url"
:aria-label="
$t('media-details.aria.creator-url', {
@@ -58,11 +58,9 @@
})
"
:href="image.creator_url"
- target="blank"
- rel="noopener noreferrer"
@click="onCreatorLinkClicked"
@keyup.enter="onCreatorLinkClicked"
- >{{ image.creator }}</a
+ >{{ image.creator }}</VLink
>
<span v-else>{{ image.creator }}</span>
</template>
@@ -93,6 +91,7 @@ import {
import VButton from '~/components/VButton.vue'
import VIcon from '~/components/VIcon/VIcon.vue'
+import VLink from '~/components/VLink.vue'
import VImageDetails from '~/components/VImageDetails/VImageDetails.vue'
import VMediaReuse from '~/components/VMediaInfo/VMediaReuse.vue'
import VRelatedImages from '~/components/VImageDetails/VRelatedImages.vue'
@@ -104,6 +103,7 @@ const VImageDetailsPage = {
components: {
VButton,
VIcon,
+ VLink,
VImageDetails,
VMediaReuse,
VRelatedImages,
diff --git a/src/pages/index.vue b/src/pages/index.vue
index a5f7b0522..9bc154480 100644
--- a/src/pages/index.vue
+++ b/src/pages/index.vue
@@ -13,8 +13,8 @@
/>
<div class="px-6 lg:ps-30 lg:pe-0 xl:px-40 mx-auto w-full lg:w-auto">
- <NuxtLink
- to="/"
+ <VLink
+ href="/"
class="relative z-10 hidden lg:block -left-[6.25rem] rtl:-right-[6.25rem]"
>
<h1>
@@ -28,7 +28,7 @@
<OpenverseBrand class="w-[315px] h-[60px]" />
</span>
</h1>
- </NuxtLink>
+ </VLink>
<h2 class="text-4xl lg:text-6xl mt-auto lg:mt-6">
{{ $t('hero.subtitle') }}
</h2>
@@ -66,12 +66,10 @@
class="hidden lg:block text-sr mt-4"
>
<template #license>
- <a
+ <VLink
href="https://creativecommons.org/licenses/"
- target="blank"
- rel="noopener noreferrer"
class="text-dark-charcoal hover:text-dark-charcoal underline"
- >{{ $t('hero.disclaimer.license') }}</a
+ >{{ $t('hero.disclaimer.license') }}</VLink
>
</template>
</i18n>
@@ -94,8 +92,8 @@
mode="out-in"
appear
>
- <NuxtLink
- :to="image.url"
+ <VLink
+ :href="image.url"
class="homepage-image block aspect-square h-30 w-30 lg:h-auto lg:w-auto lg:m-[2vh] rounded-full"
:style="{ '--transition-index': `${index * 0.05}s` }"
>
@@ -105,7 +103,7 @@
:alt="image.title"
:title="image.title"
/>
- </NuxtLink>
+ </VLink>
</Transition>
</ClientOnly>
</div>
@@ -118,12 +116,10 @@
class="lg:hidden text-sr p-6 mt-auto"
>
<template #license>
- <a
+ <VLink
href="https://creativecommons.org/licenses/"
- target="blank"
- rel="noopener noreferrer"
class="text-dark-charcoal hover:text-dark-charcoal underline"
- >{{ $t('hero.disclaimer.license') }}</a
+ >{{ $t('hero.disclaimer.license') }}</VLink
>
</template>
</i18n>
@@ -147,6 +143,7 @@ import VContentSwitcherPopover from '~/components/VContentSwitcher/VContentSwitc
import VContentTypeButton from '~/components/VContentSwitcher/VContentTypeButton.vue'
import VSearchBar from '~/components/VHeader/VSearchBar/VSearchBar.vue'
import VLogoButton from '~/components/VHeader/VLogoButton.vue'
+import VLink from '~/components/VLink.vue'
const HomePage = {
name: 'home-page',
@@ -157,6 +154,7 @@ const HomePage = {
VContentSwitcherPopover,
VContentTypeButton,
VSearchBar,
+ VLink,
VLogoButton,
},
head: {
diff --git a/src/pages/meta-search.vue b/src/pages/meta-search.vue
index d69bab5a4..4a94e114e 100644
--- a/src/pages/meta-search.vue
+++ b/src/pages/meta-search.vue
@@ -9,9 +9,9 @@
<i18n path="meta-search-page.intro" tag="p" class="mb-4">
<template #link>
- <a aria-label="sources" href="/sources">{{
+ <VLink :aria-label="$t('meta-search-page.sources')" href="/sources">{{
$t('meta-search-page.link')
- }}</a>
+ }}</VLink>
</template>
</i18n>
<p>{{ $t('meta-search-page.license') }}</p>
@@ -83,16 +83,16 @@
</h2>
<i18n path="meta-search-page.new.content" tag="p" class="mb-2">
<template #issue>
- <a
+ <VLink
aria-label="issue"
- href="https://github.com/creativecommons/cccatalog/issues/new?assignees=&labels=awaiting+triage%2C+ticket+work+required%2C+providers&template=new-source-suggestion.md&title=%5BSource+Suggestion%5D+Insert+source+name+here"
- >{{ $t('meta-search-page.new.issue') }}</a
+ href="https://github.com/WordPress/openverse-catalog/issues/new?assignees=&labels=%F0%9F%9A%A6+status%3A+awaiting+triage%2C%F0%9F%A7%B9+status%3A+ticket+work+required%2C%E2%98%81%EF%B8%8F+provider%3A+any&template=new_source_suggestion.yml&title=%3CSource+name+here%3E"
+ >{{ $t('meta-search-page.new.issue') }}</VLink
>
</template>
<template #email>
- <a aria-label="email" href="mailto:[email protected]">{{
+ <VLink aria-label="email" href="mailto:[email protected]">{{
$t('meta-search-page.new.email')
- }}</a>
+ }}</VLink>
</template>
</i18n>
<h2 class="mt-10 mb-4 text-2xl">
@@ -104,10 +104,10 @@
</p>
<i18n path="meta-search-page.why.feedback-suggestions" tag="p">
<template #feedback>
- <NuxtLink
+ <VLink
:aria-label="$t('meta-search-page.why.aria-label')"
- :to="localePath('/feedback')"
- >{{ $t('meta-search-page.why.feedback-link') }}</NuxtLink
+ href="/feedback"
+ >{{ $t('meta-search-page.why.feedback-link') }}</VLink
>
</template>
</i18n>
@@ -116,14 +116,18 @@
</template>
<script>
-export default {
+import { defineComponent } from '@nuxtjs/composition-api'
+import VLink from '~/components/VLink.vue'
+
+export default defineComponent({
name: 'MetaSearchPage',
+ components: { VLink },
head() {
return {
title: `${this.$t('meta-search-page.title')} | ${this.$t('hero.brand')}`,
}
},
-}
+})
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
diff --git a/src/pages/search-help.vue b/src/pages/search-help.vue
index 6351674b5..a19149272 100644
--- a/src/pages/search-help.vue
+++ b/src/pages/search-help.vue
@@ -15,12 +15,12 @@
<i18n path="search-guide.exact.content" tag="p">
<template #link>
<!-- eslint-disable -->
- <a
+ <VLink
:aria-label="$t('search-guide.exact.aria-label')"
href='https://search.creativecommons.org/search?q="Claude%20Monet"'
>
<em>{{ $t('search-guide.exact.claude-monet') }}</em>
- </a>
+ </VLink>
<!-- eslint-enable -->
</template>
</i18n>
@@ -105,12 +105,12 @@
<i18n path="search-guide.example.and.description" tag="p" class="my-4">
<template #link>
- <a
+ <VLink
:aria-label="$t('search-guide.example.and.aria-label')"
href="https://search.creativecommons.org/search?q=dog%2Bcat"
>
<em>{{ $t('search-guide.example.and.example') }}</em>
- </a>
+ </VLink>
</template>
<template #br>
<br />
@@ -119,12 +119,12 @@
<i18n path="search-guide.example.or" tag="p" class="my-4">
<template #link>
- <a
+ <VLink
:aria-label="$t('search-guide.example.or.aria-label')"
href="https://search.creativecommons.org/search?q=dog%7Ccat"
>
<em>{{ $t('search-guide.example.or.example') }}</em>
- </a>
+ </VLink>
</template>
<template #br>
<br />
@@ -148,12 +148,12 @@
<i18n path="search-guide.example.negate.content" tag="p" class="mb-4">
<template #link>
- <a
+ <VLink
:aria-label="$t('search-guide.example.negate.aria-label')"
href="https://search.creativecommons.org/search?q=dog%20-pug"
>
<em>{{ $t('search-guide.example.negate.example') }}</em>
- </a>
+ </VLink>
</template>
<template #br>
<br />
@@ -174,12 +174,12 @@
<i18n path="search-guide.example.prefix.content" tag="p" class="mb-4">
<template #link>
- <a
+ <VLink
:aria-label="$t('search-guide.example.prefix.aria-label')"
href="https://search.creativecommons.org/search?q=net%2a"
>
<em>{{ $t('search-guide.example.prefix.example') }}</em>
- </a>
+ </VLink>
</template>
<template #br>
<br />
@@ -202,12 +202,12 @@
class="mb-4"
>
<template #link>
- <a
+ <VLink
:aria-label="$t('search-guide.example.precedence.aria-label')"
href="https://search.creativecommons.org/search?q=dogs%20%2B%20%28corgis%20%7C%20labrador%29"
>
<em>{{ $t('search-guide.example.precedence.example') }}</em>
- </a>
+ </VLink>
</template>
<template #br>
<br />
@@ -223,9 +223,9 @@
<em aria-label="tilde N">~N</em>
</template>
<template #link>
- <a href="http://en.wikipedia.org/wiki/Levenshtein_distance">
+ <VLink href="http://en.wikipedia.org/wiki/Levenshtein_distance">
{{ $t('search-guide.example.fuzziness.link-text') }}
- </a>
+ </VLink>
</template>
</i18n>
@@ -235,12 +235,12 @@
class="mb-4"
>
<template #link>
- <a
+ <VLink
:aria-label="$t('search-guide.example.fuzziness.aria-label')"
href="https://search.creativecommons.org/search?q=theatre~1"
>
<em>{{ $t('search-guide.example.fuzziness.example') }}</em>
- </a>
+ </VLink>
</template>
<template #br>
<br />
@@ -253,8 +253,11 @@
</template>
<script>
+import VLink from '~/components/VLink.vue'
+
const SearchHelpPage = {
name: 'search-help-page',
+ components: { VLink },
methods: {
providerSearchLink(providerCode) {
return `https://search.creativecommons.org/search?q=provider%3A%20"${providerCode}"`
diff --git a/src/pages/sources.vue b/src/pages/sources.vue
index afe955e34..15cdd0549 100644
--- a/src/pages/sources.vue
+++ b/src/pages/sources.vue
@@ -14,27 +14,29 @@
</p>
<i18n path="sources.cc-content.provider" tag="p" class="my-4">
<template #flickr>
- <a aria-label="flickr" href="https://www.flickr.com/">{{
+ <VLink aria-label="flickr" href="https://www.flickr.com/">{{
$t('sources.cc-content.flickr')
- }}</a>
+ }}</VLink>
</template>
<template #smithsonian>
- <a aria-label="smithsonian" href="https://www.si.edu/">{{
+ <VLink aria-label="smithsonian" href="https://www.si.edu/">{{
$t('sources.cc-content.smithsonian')
- }}</a>
+ }}</VLink>
</template>
</i18n>
<i18n path="sources.cc-content.europeana" tag="p" class="my-4">
<template #link>
- <a aria-label="europeana" href="https://www.europeana.eu/en">{{
- $t('sources.cc-content.europeana-link')
- }}</a>
+ <VLink
+ aria-label="europeana"
+ href="https://www.europeana.eu/en"
+ >{{ $t('sources.cc-content.europeana-link') }}</VLink
+ >
</template>
<template #link-api>
- <a
+ <VLink
aria-label="europeana-api"
href="https://pro.europeana.eu/page/apis"
- >{{ $t('sources.cc-content.europeana-api') }}</a
+ >{{ $t('sources.cc-content.europeana-api') }}</VLink
>
</template>
</i18n>
@@ -64,15 +66,13 @@
<h3 class="text-2xl my-4">
{{ $t('sources.suggestions') }}
</h3>
- <a
+ <VLink
href="https://github.com/WordPress/openverse-catalog/issues/new?assignees=&labels=%F0%9F%9A%A6+status%3A+awaiting+triage%2C+%F0%9F%A7%B9+status%3A+ticket+work+required%2C+%E2%98%81%EF%B8%8F+provider%3A+any&template=new-source-suggestion.md&title=%5BSource+Suggestion%5D+Insert+source+name+here"
class="button is-primary py-8"
- target="_blank"
- rel="noopener noreferrer"
>
{{ $t('sources.issue-button') }}
<i class="icon external-link mx-2 mt-2" />
- </a>
+ </VLink>
</div>
<i18n path="sources.detail" tag="p">
<template #single-name>
@@ -123,14 +123,14 @@
<tbody>
<tr v-for="(imageProvider, index) in sortedProviders" :key="index">
<td class="font-semibold">
- <a :href="`/search?source=${imageProvider.source_name}`">
+ <VLink :href="`/search?source=${imageProvider.source_name}`">
{{ imageProvider.display_name }}
- </a>
+ </VLink>
</td>
<td class="font-semibold">
- <a :href="imageProvider.source_url">
+ <VLink :href="imageProvider.source_url">
{{ imageProvider.source_url }}
- </a>
+ </VLink>
</td>
<td class="number-cell font-semibold">
{{ getLocaleFormattedNumber(imageProvider.media_count || 0) }}
@@ -147,9 +147,11 @@ import sortBy from 'lodash.sortby'
import { mapState } from 'vuex'
import { PROVIDER } from '~/constants/store-modules'
import { useGetLocaleFormattedNumber } from '~/composables/use-get-locale-formatted-number'
+import VLink from '~/components/VLink.vue'
const SourcePage = {
name: 'source-page',
+ components: { VLink },
data() {
return {
sort: {
diff --git a/src/utils/attribution-html.js b/src/utils/attribution-html.js
index bcd0290df..d00cd12f8 100644
--- a/src/utils/attribution-html.js
+++ b/src/utils/attribution-html.js
@@ -1,20 +1,21 @@
+const linkProperties = 'target="_blank" rel="noopener noreferrer"'
function getAttributionHtml(media, licenseUrl, fullLicenseName) {
if (!media) {
return ''
}
const baseAssetsPath = 'https://search.creativecommons.org/static/img'
- const imgLink = `<a href="${media.foreign_landing_url}">"${media.title}"</a>`
+ const imgLink = `<a href="${media.foreign_landing_url}" ${linkProperties}>"${media.title}"</a>`
let creator = ''
let mediaTag = ''
if (media.url && media.title) {
mediaTag = `<img style="display: block;" src="${media.url}" alt="${media.title}">`
}
if (media.creator && media.creator_url) {
- creator = `<span> by <a href="${media.creator_url}">${media.creator}</a></span>`
+ creator = `<span> by <a href="${media.creator_url}" ${linkProperties}>${media.creator}</a></span>`
} else if (media.creator && !media.creator_url) {
creator = `<span> by <span>${media.creator}</span></span>`
}
- const licenseLink = ` is licensed under <a href="${licenseUrl}" style="margin-right: 5px;">${fullLicenseName.toUpperCase()}</a>`
+ const licenseLink = ` is licensed under <a href="${licenseUrl}" style="margin-right: 5px;" ${linkProperties}>${fullLicenseName.toUpperCase()}</a>`
let licenseIcons = `<img style="height: inherit;margin-right: 3px;display: inline-block;" src="${baseAssetsPath}/cc_icon.svg?media_id=${media.id}" />`
if (media.license) {
@@ -27,7 +28,7 @@ function getAttributionHtml(media, licenseUrl, fullLicenseName) {
.join('')
}
- const licenseImgLink = `<a href="${licenseUrl}" target="_blank" rel="noopener noreferrer" style="display: inline-block;white-space: none;margin-top: 2px;margin-left: 3px;height: 22px !important;">${licenseIcons}</a>`
+ const licenseImgLink = `<a href="${licenseUrl}" ${linkProperties} style="display: inline-block;white-space: none;margin-top: 2px;margin-left: 3px;height: 22px !important;">${licenseIcons}</a>`
return `<p style="font-size: 0.9rem;font-style: italic;">${mediaTag}${imgLink}${creator}${licenseLink}${licenseImgLink}</p>`
}
diff --git a/test/unit/setup.js b/test/unit/setup.js
index 485a2d66f..319341d03 100644
--- a/test/unit/setup.js
+++ b/test/unit/setup.js
@@ -8,7 +8,7 @@ for (const [key, value] of Object.entries(env)) {
process.env[key] = value
}
-// Make sure api analytics are enabled so we can test them!
+// Make sure api analytics are enabled, so we can test them!
process.env.enableInternalAnalytics = true
Vue.config.productionTip = false
diff --git a/test/unit/specs/components/ImageDetails/reuse-survey.spec.js b/test/unit/specs/components/ImageDetails/reuse-survey.spec.js
index 7efb11b19..17d1cf206 100644
--- a/test/unit/specs/components/ImageDetails/reuse-survey.spec.js
+++ b/test/unit/specs/components/ImageDetails/reuse-survey.spec.js
@@ -6,6 +6,7 @@ import {
import render from '../../../test-utils/render'
import i18n from '../../../test-utils/i18n'
import { USAGE_DATA } from '~/constants/store-modules'
+import { mount } from '@vue/test-utils'
describe('ImageAttribution', () => {
let options = null
@@ -31,7 +32,7 @@ describe('ImageAttribution', () => {
})
it('should dispatch REUSE_SURVEY on reuse link clicked', () => {
- const wrapper = render(ReuseSurvey, options)
+ const wrapper = render(ReuseSurvey, options, mount)
wrapper.find('a').trigger('click')
expect(dispatchMock).toHaveBeenCalledWith(
`${USAGE_DATA}/${SEND_DETAIL_PAGE_EVENT}`,
diff --git a/test/unit/specs/components/v-button.spec.js b/test/unit/specs/components/v-button.spec.js
index c1f04c14f..2d11723e9 100644
--- a/test/unit/specs/components/v-button.spec.js
+++ b/test/unit/specs/components/v-button.spec.js
@@ -6,7 +6,6 @@ import { warn } from '~/utils/warn'
jest.mock('~/utils/warn', () => ({ warn: jest.fn() }))
const nextTick = () => new Promise((r) => setTimeout(r, 0))
-
/**
* Throughout this suite we use the `screen.findBy*` functions to asynchronously
* wait for the component to re-render. There might be some kind of performance
@@ -43,7 +42,8 @@ describe('VButton', () => {
it('should render an anchor with no type attribute', async () => {
render(VButton, {
- props: { as: 'a' },
+ attrs: { href: 'http://localhost' },
+ props: { as: 'VLink' },
slots: { default: 'Code is Poetry' },
})
await nextTick()
@@ -81,7 +81,7 @@ describe('VButton', () => {
it('should not render the disabled attribute on elements that do not support it', async () => {
render(VButton, {
props: {
- as: 'a',
+ as: 'VLink',
disabled: true,
focusableWhenDisabled: true,
href: 'https://wordpress.org',
@@ -94,21 +94,4 @@ describe('VButton', () => {
expect(element).not.toHaveAttribute('disabled')
expect(element).toHaveAttribute('aria-disabled', 'true')
})
-
- it.each([undefined, '', null, '#'])(
- 'should warn if an anchor is used without a valid href: %s',
- async (href) => {
- render(VButton, {
- props: { as: 'a', href },
- slots: { default: 'Code is Poetry' },
- })
-
- await screen.findByText(/code is poetry/i)
-
- expect(warn).toHaveBeenCalledTimes(1)
- expect(warn).toHaveBeenCalledWith(
- 'Do not use anchor elements without a valid `href` attribute. Use a `button` instead.'
- )
- }
- )
})
diff --git a/test/unit/specs/components/v-link.spec.js b/test/unit/specs/components/v-link.spec.js
new file mode 100644
index 000000000..e8758114e
--- /dev/null
+++ b/test/unit/specs/components/v-link.spec.js
@@ -0,0 +1,74 @@
+// eslint-disable vue/one-component-per-file
+import { fireEvent, render, screen } from '@testing-library/vue'
+import VLink from '~/components/VLink.vue'
+import Vue from 'vue'
+
+const nuxtContextMock = {
+ $nuxt: { context: { app: { localePath: jest.fn((v) => v) } } },
+}
+/**
+ * Simplified mock of a NuxtLink component.
+ */
+// eslint-disable-next-line vue/one-component-per-file
+const NuxtLink = Vue.component('NuxtLink', {
+ props: ['to'],
+ template: '<a :href="to" v-on="$listeners"><slot /></a>',
+})
+
+describe('VLink', () => {
+ it.each`
+ href | target | rel
+ ${'/about'} | ${null} | ${null}
+ ${'http://localhost:8443/'} | ${'_blank'} | ${'noopener noreferrer'}
+ `(
+ 'Creates a correct link component based on href',
+ ({ href, target, rel }) => {
+ render(
+ VLink,
+ {
+ props: { href },
+ slots: { default: 'Code is Poetry' },
+ mocks: nuxtContextMock,
+ },
+ (localVue) => {
+ localVue.component('NuxtLink', NuxtLink)
+ }
+ )
+ const link = screen.getByRole('link')
+ const expectedHref = href.startsWith('/')
+ ? `http://localhost${href}`
+ : href
+ expect(link.href).toEqual(expectedHref)
+ expect(link.getAttribute('target')).toEqual(target)
+ expect(link.getAttribute('rel')).toEqual(rel)
+ }
+ )
+ it.each`
+ href | component
+ ${'/about'} | ${'NuxtLink'}
+ ${'http://localhost'} | ${'A'}
+ `('VLink as a $component handles click', async ({ href }) => {
+ const createVLinkWrapper = (href) =>
+ Vue.component('VLinkWrapper', {
+ data: () => ({ text: 'Link Text' }),
+ methods: {
+ handleClick(e) {
+ e.preventDefault()
+ this.text = 'Code is Poetry'
+ },
+ },
+ template: `<div><VLink href="${href}" @click="handleClick">{{ text }}</VLink></div>`,
+ })
+ const WrapperComponent = createVLinkWrapper(href)
+ render(WrapperComponent, { mocks: nuxtContextMock }, (localVue) => {
+ localVue.component('NuxtLink', NuxtLink)
+ localVue.component('VLink', VLink)
+ })
+ const linkBefore = await screen.getByRole('link')
+ expect(linkBefore.textContent).toEqual('Link Text')
+
+ await fireEvent.click(linkBefore)
+ const linkAfter = await screen.findByText('Code is Poetry')
+ expect(linkAfter.tagName).toBe('A')
+ })
+})