Skip to content

Commit

Permalink
refactor: keep carbon ads async
Browse files Browse the repository at this point in the history
  • Loading branch information
posva committed Dec 5, 2020
1 parent 026896a commit 178d76e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 20 deletions.
50 changes: 43 additions & 7 deletions src/client/theme-default/Layout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,16 @@
<Page v-else>
<template #top>
<slot name="page-top-ads">
<CarbonAds
<div
id="ads-container"
v-if="theme.carbonAds && theme.carbonAds.carbon"
:key="'carbon' + page.relativePath"
:code="theme.carbonAds.carbon"
:placement="theme.carbonAds.placement"
/>
>
<CarbonAds
:key="'carbon' + page.relativePath"
:code="theme.carbonAds.carbon"
:placement="theme.carbonAds.placement"
/>
</div>
</slot>
<slot name="page-top" />
</template>
Expand Down Expand Up @@ -75,8 +79,9 @@ import NavBar from './components/NavBar.vue'
import Home from './components/Home.vue'
import SideBar from './components/SideBar.vue'
import Page from './components/Page.vue'
// could be async but that would cause layout shifts
import CarbonAds from './components/CarbonAds.vue'
const CarbonAds = defineAsyncComponent(
() => import('./components/CarbonAds.vue')
)
const BuySellAds = defineAsyncComponent(
() => import('./components/BuySellAds.vue')
)
Expand Down Expand Up @@ -145,3 +150,34 @@ const pageClasses = computed(() => {
]
})
</script>

<style>
#ads-container {
margin: 0 auto;
}
@media (min-width: 420px) {
#ads-container {
position: relative;
right: 0;
float: right;
margin: -8px -8px 24px 24px;
width: 146px;
}
}
@media (max-width: 420px) {
#ads-container {
/* Avoid layout shift */
height: 105px;
}
}
@media (min-width: 1400px) {
#ads-container {
position: fixed;
right: 8px;
bottom: 8px;
}
}
</style>
13 changes: 0 additions & 13 deletions src/client/theme-default/components/CarbonAds.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,30 +38,17 @@ onMounted(() => {
@media (min-width: 420px) {
.carbon-ads {
position: relative;
right: -8px;
z-index: 1;
float: right;
margin: -8px -8px 24px 24px;
padding: 8px;
width: 146px;
max-width: 100%;
}
}
@media (max-width: 420px) {
.carbon-ads {
/* Avoid layout shift */
height: 105px;
}
}
@media (min-width: 1400px) {
.carbon-ads {
position: fixed;
top: auto;
right: 8px;
bottom: 8px;
float: none;
margin: 0;
}
Expand Down

0 comments on commit 178d76e

Please sign in to comment.