Skip to content

Commit

Permalink
docs: add custom theme for ads
Browse files Browse the repository at this point in the history
  • Loading branch information
posva committed Sep 15, 2020
1 parent e52d648 commit b8a6d60
Show file tree
Hide file tree
Showing 5 changed files with 218 additions and 1 deletion.
6 changes: 5 additions & 1 deletion docs/.vuepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ module.exports = ctx => ({
}
]
],
theme: '@vuepress/vue',
// theme: '@vuepress/vue',
plugins: [
[
'@vuepress/pwa',
Expand All @@ -70,6 +70,10 @@ module.exports = ctx => ({
indexName: 'vue-router'
}
: null,
carbonAds: {
serve: 'CEBICK3I',
placement: 'routervuejsorg'
},
repo: 'vuejs/vue-router',
docsDir: 'docs',
smoothScroll: true,
Expand Down
36 changes: 36 additions & 0 deletions docs/.vuepress/theme/Layout.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<template>
<ParentLayout>
<template #sidebar-top>
<CarbonAds
v-if="$site.themeConfig.carbonAds"
:key="$page.path"
:serve="$site.themeConfig.carbonAds.serve"
:placement="$site.themeConfig.carbonAds.placement"
/>
</template>
<template #page-bottom>
<BuySellAds
v-if="$site.themeConfig.carbonAds"
:key="$page.path"
:serve="$site.themeConfig.carbonAds.serve"
:placement="$site.themeConfig.carbonAds.placement"
/>
</template>
</ParentLayout>
</template>

<script>
import ParentLayout from '@parent-theme/layouts/Layout.vue'
import CarbonAds from './components/CarbonAds.vue'
import BuySellAds from './components/BuySellAds.vue'
export default {
name: 'Layout',
components: {
ParentLayout,
CarbonAds,
BuySellAds
}
}
</script>
110 changes: 110 additions & 0 deletions docs/.vuepress/theme/components/BuySellAds.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<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: {
serve: {
type: String,
required: true
},
placement: {
type: String,
required: true
}
},
methods: {
load() {
if (typeof _bsa !== 'undefined' && _bsa) {
_bsa.init('default', this.serve, `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 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>
64 changes: 64 additions & 0 deletions docs/.vuepress/theme/components/CarbonAds.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<template>
<div class="carbon-ads"></div>
</template>

<script>
export default {
name: 'CarbonAds',
props: {
serve: {
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.serve}&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;
}
.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>
3 changes: 3 additions & 0 deletions docs/.vuepress/theme/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
extend: '@vuepress/theme-default'
}

0 comments on commit b8a6d60

Please sign in to comment.