Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/.vuepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,11 @@ module.exports = {
indexName: 'vuejs-v3',
appId: 'BH4D9OD16A',
apiKey: 'bc6e8acb44ed4179c30d0a45d6140d3f'
},
carbonAds: {
carbon: 'CEBDT27Y',
custom: 'CKYD62QM',
placement: 'vuejsorg'
}
},
plugins: [
Expand Down
115 changes: 115 additions & 0 deletions src/.vuepress/theme/components/BuySellAds.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
<template>
<div class="bsa-cpc-wrapper">
<div class="bsa-cpc"></div>
</div>
</template>

<script>
/* global _bsa */
const ID = 'bsa-cpc-script'

export default {
name: 'BuySellAds',
props: {
code: {
type: String,
required: true
},
placement: {
type: String,
required: true
}
},

methods: {
load() {
if (typeof _bsa !== 'undefined' && _bsa) {
_bsa.init('default', this.code, `placement:${this.placement}`, {
target: '.bsa-cpc',
align: 'horizontal',
disable_css: 'true'
})
}
}
},

mounted() {
if (!document.getElementById(ID)) {
const s = document.createElement('script')
s.id = ID
s.src = `//m.servedby-buysellads.com/monetization.js`
document.head.appendChild(s)
s.onload = () => {
this.load()
}
} else {
this.load()
}
}
}
</script>

<style>
.bsa-cpc-wrapper {
font-size: 0.95rem;
/* from Page.vue */
max-width: 50rem;
margin: 0px auto;
padding: 1rem 2rem 0;
margin-bottom: -1rem;
}
@media (max-width: 419px) {
.bsa-cpc-wrapper {
padding: 0 1.5rem;
}
}
.bsa-cpc {
font-size: 0.9em;
background-color: #f8f8f8;
border-radius: 6px;
}

.bsa-cpc .default-text {
display: inline;
}

.bsa-cpc a._default_ {
text-align: left;
display: block;
text-decoration: none;
padding: 10px 15px 12px;
margin-bottom: 20px;
color: #666;
font-weight: 400;
line-height: 18px;
}
.bsa-cpc a._default_ .default-image img {
height: 20px;
border-radius: 3px;
vertical-align: middle;
position: relative;
top: -1px;
}
.bsa-cpc a._default_ .default-title {
font-weight: 600;
}
.bsa-cpc a._default_ .default-description:after {
font-size: 0.85em;
content: 'Sponsored';
color: #1c90f3;
border: 1px solid #1c90f3;
border-radius: 3px;
padding: 0 4px 1px;
margin-left: 6px;
}
.bsa-cpc .default-ad {
display: none;
}
.bsa-cpc a._default_ .default-image,
.bsa-cpc a._default_ .default-title,
.bsa-cpc a._default_ .default-description {
display: inline;
vertical-align: middle;
margin-right: 6px;
}
</style>
85 changes: 85 additions & 0 deletions src/.vuepress/theme/components/CarbonAds.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<template>
<div class="carbon-ads"></div>
</template>

<script>
export default {
name: 'CarbonAds',
props: {
code: {
type: String,
required: true
},
placement: {
type: String,
required: true
}
},

mounted() {
const s = document.createElement('script')
s.id = '_carbonads_js'
s.src = `//cdn.carbonads.com/carbon.js?serve=${this.code}&placement=${this.placement}`
this.$el.appendChild(s)
}
}
</script>

<style>
.carbon-ads {
min-height: 102px;
padding: 1.5rem 1.5rem 0;
margin-bottom: -0.5rem;
font-size: 0.75rem;

width: 125px;
position: fixed;
z-index: 1;
bottom: 22px;
right: 14px;
padding: 10px;
border-radius: 4px;
background-color: rgba(255, 255, 255, 0.8);
/* background-color: #fff; */
/* font-size: 13px; */
}

@media screen and (max-width: 1300px) {
.carbon-ads {
position: relative;
top: 87px;
right: 12px;
float: right;
padding: 0 0 20px 30px;
}
}

.carbon-ads a {
color: #444;
font-weight: normal;
display: inline;
}

.carbon-ads .carbon-img {
float: left;
margin-right: 1rem;
border: 1px solid var(--border-color);
}

.carbon-ads .carbon-img img {
display: block;
}

.carbon-ads .carbon-poweredby {
color: #999;
display: block;
margin-top: 0.5em;
}

@media (max-width: 719px) {
.carbon-ads .carbon-img img {
width: 100px;
height: 77px;
}
}
</style>
72 changes: 56 additions & 16 deletions src/.vuepress/theme/layouts/Layout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
@touchstart="onTouchStart"
@touchend="onTouchEnd"
>
<VueMasteryBanner v-if="isBannerOpen" @close-banner="closeBanner" ref='vueMasteryBanner'/>
<VueMasteryBanner
v-if="isBannerOpen"
@close-banner="closeBanner"
ref="vueMasteryBanner"
/>
<Navbar v-if="shouldShowNavbar" @toggle-sidebar="toggleSidebar" />

<div class="sidebar-mask" @click="toggleSidebar(false)" />
Expand All @@ -23,9 +27,21 @@

<Page v-else :sidebar-items="sidebarItems">
<template #top>
<CarbonAds
v-if="adsConfig"
:key="'ca:' + $page.path"
:code="adsConfig.carbon"
:placement="adsConfig.placement"
/>
<slot name="page-top" />
</template>
<template #bottom>
<BuySellAds
v-if="adsConfig"
:key="'bsa:' + $page.path"
:code="adsConfig.custom"
:placement="adsConfig.placement"
/>
<slot name="page-bottom" />
</template>
</Page>
Expand All @@ -38,6 +54,8 @@ import Navbar from '@theme/components/Navbar.vue'
import Page from '@theme/components/Page.vue'
import Sidebar from '@theme/components/Sidebar.vue'
import VueMasteryBanner from '@theme/components/sponsors/VueMasteryBanner.vue'
import BuySellAds from '@theme/components/BuySellAds.vue'
import CarbonAds from '@theme/components/CarbonAds.vue'
import { resolveSidebarItems } from '../util'

export default {
Expand All @@ -48,21 +66,23 @@ export default {
Page,
Sidebar,
Navbar,
VueMasteryBanner
VueMasteryBanner,
BuySellAds,
CarbonAds
},

data () {
data() {
return {
isSidebarOpen: false,
isBannerOpen: true,
isBannerOpen: true,
isMenuFixed: false,
nameStorage: 'vuemastery-black-firday-2020-banner',
menuPosition: 0
}
},

computed: {
shouldShowNavbar () {
shouldShowNavbar() {
const { themeConfig } = this.$site
const { frontmatter } = this.$page
if (frontmatter.navbar === false || themeConfig.navbar === false) {
Expand All @@ -77,7 +97,7 @@ export default {
)
},

shouldShowSidebar () {
shouldShowSidebar() {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently other functions are also following this convention. I simply forgot to turn off auto format when saving but I can revert these changes

const { frontmatter } = this.$page
return (
!frontmatter.home &&
Expand All @@ -86,7 +106,7 @@ export default {
)
},

sidebarItems () {
sidebarItems() {
return resolveSidebarItems(
this.$page,
this.$page.regularPath,
Expand All @@ -95,7 +115,7 @@ export default {
)
},

pageClasses () {
pageClasses() {
const userPageClass = this.$page.frontmatter.pageClass
return [
{
Expand All @@ -107,10 +127,14 @@ export default {
},
userPageClass
]
},

adsConfig() {
return this.$site.themeConfig.carbonAds
}
},

mounted () {
mounted() {
this.$router.afterEach(() => {
this.isSidebarOpen = false
})
Expand All @@ -124,20 +148,20 @@ export default {
},

methods: {
toggleSidebar (to) {
toggleSidebar(to) {
this.isSidebarOpen = typeof to === 'boolean' ? to : !this.isSidebarOpen
this.$emit('toggle-sidebar', this.isSidebarOpen)
},

// side swipe
onTouchStart (e) {
onTouchStart(e) {
this.touchStart = {
x: e.changedTouches[0].clientX,
y: e.changedTouches[0].clientY
}
},

onTouchEnd (e) {
onTouchEnd(e) {
const dx = e.changedTouches[0].clientX - this.touchStart.x
const dy = e.changedTouches[0].clientY - this.touchStart.y
if (Math.abs(dx) > Math.abs(dy) && Math.abs(dx) > 40) {
Expand All @@ -161,7 +185,7 @@ export default {
this.isMenuFixed = this.isUnderBanner()
},

closeBanner (e) {
closeBanner(e) {
// Remove events
this.toggleBannerEvents(false)
// Hide the banner
Expand Down Expand Up @@ -192,10 +216,26 @@ export default {

toggleBannerEvents(on) {
// Add or remove event listerners attached to the DOM
let method = on ? "addEventListener" : "removeEventListener"
window[method]("resize", this.getMenuPosition)
window[method]("scroll", this.fixMenuAfterBanner)
let method = on ? 'addEventListener' : 'removeEventListener'
window[method]('resize', this.getMenuPosition)
window[method]('scroll', this.fixMenuAfterBanner)
}
}
}
</script>

<style>
/* add a placeholder to give space to ads so they don't overlap with content */
@media screen and (max-width: 1376px) {
.content__default::before {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This to make the ad take some space

vuejs.org, ad inside content

Screen Shot 2020-12-02 at 13 25 04

vuepress doesn't:

Screen Shot 2020-12-02 at 13 25 11

But it creates overlap for tip containers unless we add overflow-x: auto but that breaks the icon display:

Screen Shot 2020-12-02 at 13 20 02

Which is the reason I added the background

content: '';
position: relative;
display: block;
float: right;
height: 221px;
padding: 0 0 20px 30px;
margin-top: 20px;
margin-right: -24px;
}
}
</style>