Enable using page context for ad inline

This commit is contained in:
Sam Carlton 2022-07-27 12:45:34 -05:00
parent 12705f982e
commit 5b4e044125
2 changed files with 40 additions and 8 deletions

View file

@ -1,6 +1,6 @@
<template> <template>
<div <div
v-if="name !== 'default'" v-if="adName !== 'default'"
class="w-full" class="w-full"
> >
<a <a
@ -11,13 +11,14 @@
> >
<div class="flex flex-col text-center"> <div class="flex flex-col text-center">
<img <img
:src="ad.imageSrc" :src="imageSrc"
:alt="ad.imageAlt" :alt="ad.imageAlt"
class="w-32 h-full aspect-video object-cover" class="w-32 h-full aspect-video object-cover"
> >
</div> </div>
<div class="flex flex-col justify-center text-center opacity-50 p-4"> <div class="flex flex-col justify-center text-center opacity-50 p-4">
{{ ad.copy }} {{ ad.copy }}
{{ ad.imageSrc }}
</div> </div>
<div <div
class="absolute bottom-0 right-0 border-t border-l rounded-tl uppercase opacity-25 px-1" class="absolute bottom-0 right-0 border-t border-l rounded-tl uppercase opacity-25 px-1"
@ -38,6 +39,8 @@
/* Carbon ads */ /* Carbon ads */
import CarbonInline from './carbon-inline.vue' import CarbonInline from './carbon-inline.vue'
const transparentImage = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7'
const ads = { const ads = {
// Since Vue renders the ad on the server // Since Vue renders the ad on the server
// but destroys the ad when hydrating on // but destroys the ad when hydrating on
@ -46,7 +49,7 @@ const ads = {
// and so that our ad css still get's imported. // and so that our ad css still get's imported.
'placeholder': { 'placeholder': {
url: '/', url: '/',
imageSrc: 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7', imageSrc: transparentImage,
imageAlt: '', imageAlt: '',
copy: '', copy: '',
corner: '', corner: '',
@ -91,11 +94,39 @@ export default {
type: String, type: String,
default: 'default' default: 'default'
}, },
}, page: {
computed: { type: Object,
ad () { default: () => ({})
return ads[ this.name ]
} }
}, },
data () {
return {
// We store imageSrc in data
// so that vue knows to update attribute after hydration.
imageSrc: transparentImage,
}
},
computed: {
adName () {
// console.log( 'kindName', this.page?.kindName )
if ( this.name === 'placeholder' ) {
return 'placeholder'
}
if ( this.page?.kindName === 'developer-tools' ) return 'jotform-for-developers-1'
// Video and Motion Tools
if ( this.page?.kindName === 'video-and-motion-tools' ) return 'wondershare-arm-1'
return this.name
},
ad () {
return ads[ this.adName ]
}
},
mounted () {
this.imageSrc = this.ad.imageSrc
}
} }
</script> </script>

View file

@ -47,8 +47,9 @@
<div class="slot-wrapper"> <div class="slot-wrapper">
<slot name="ad-inline"> <slot name="ad-inline">
<AdInline <AdInline
:name="isSSR ? 'placeholder' : 'default'"
v-once v-once
:name="isSSR ? 'placeholder' : 'default'"
:page="kindPage"
/> />
</slot> </slot>
</div> </div>