Skip to content

Commit

Permalink
specifying what qualifies as an external link for EDU theme (#652)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephiescastle authored Oct 7, 2024
1 parent 848bde5 commit d1fbddc
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
23 changes: 22 additions & 1 deletion packages/vue/src/components/BaseLink/BaseLink.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<script lang="ts">
import { defineComponent } from 'vue'
import { mapStores } from 'pinia'
import { useThemeStore } from '../../store/theme'
import { eventBus } from './../../utils/eventBus'
import MixinAnimationCaret from './../MixinAnimationCaret/MixinAnimationCaret.vue'
import { isEduExternalLink } from './../../utils/isEduExternalLink'
interface Variants {
[key: string]: string
Expand Down Expand Up @@ -111,6 +114,7 @@ export default defineComponent({
},
emits: ['linkClicked', 'specificLinkClicked'],
computed: {
...mapStores(useThemeStore),
computedVariants(): Variants {
if (this.usePrimaryColor) {
return primaryColorVariants
Expand All @@ -127,10 +131,27 @@ export default defineComponent({
}
return classes
},
isEduExternal(): boolean | string {
if (this.href) {
return isEduExternalLink(this.href)
}
return ''
},
isExternal(): boolean {
if (this.href) {
if (this.themeStore.isEdu && isEduExternalLink(this.href)) {
return true
} else if (!this.themeStore.isEdu) {
return true
}
return false
}
return false
},
theTarget(): string | undefined {
if (this.target) {
return this.target
} else if (this.href && this.externalTargetBlank) {
} else if (this.isExternal && this.externalTargetBlank) {
return '_blank'
}
return undefined
Expand Down
14 changes: 13 additions & 1 deletion packages/vue/src/components/BlockLinkCard/BlockLinkCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,13 @@
</span>
<span class="sr-only">.</span>
</p>
<template v-if="theItem.externalLink && themeStore.isEdu">
<template
v-if="
theItem.externalLink &&
themeStore.isEdu &&
isEduExternalLink(theItem.externalLink)
"
>
<IconExternal
class="text-primary ml-2"
:class="{ 'text-sm mt-1px': small, '-mt-1px': medium, '-mt-.5': large }"
Expand Down Expand Up @@ -188,6 +194,7 @@ import { defineComponent } from 'vue'
import { mapStores } from 'pinia'
import { useThemeStore } from '../../store/theme'
import { mixinFormatEventDates } from './../../utils/mixins'
import { isEduExternalLink } from './../../utils/isEduExternalLink'
import type { HeadingLevel } from './../BaseHeading/BaseHeading.vue'
import IconArrow from './../Icons/IconArrow.vue'
import IconExternal from './../Icons/IconExternal.vue'
Expand Down Expand Up @@ -389,6 +396,11 @@ export default defineComponent({
)
: undefined
}
},
methods: {
isEduExternalLink(url: string): boolean {
return isEduExternalLink(url)
}
}
})
</script>
Expand Down
12 changes: 12 additions & 0 deletions packages/vue/src/utils/isEduExternalLink.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export const isEduExternalLink = (url: string): boolean => {
if (
url &&
(url.startsWith('/edu/') ||
url.startsWith('/edubeta/') ||
url.startsWith('https://www.jpl.nasa.gov/edu/') ||
url.startsWith('https://jpl.nasa.gov/edu/'))
) {
return false
}
return true
}

0 comments on commit d1fbddc

Please sign in to comment.