-
Notifications
You must be signed in to change notification settings - Fork 5k
feat: add carbon ads #724
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
feat: add carbon ads #724
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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)" /> | ||
|
|
@@ -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> | ||
|
|
@@ -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 { | ||
|
|
@@ -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) { | ||
|
|
@@ -77,7 +97,7 @@ export default { | |
| ) | ||
| }, | ||
|
|
||
| shouldShowSidebar () { | ||
| shouldShowSidebar() { | ||
| const { frontmatter } = this.$page | ||
| return ( | ||
| !frontmatter.home && | ||
|
|
@@ -86,7 +106,7 @@ export default { | |
| ) | ||
| }, | ||
|
|
||
| sidebarItems () { | ||
| sidebarItems() { | ||
| return resolveSidebarItems( | ||
| this.$page, | ||
| this.$page.regularPath, | ||
|
|
@@ -95,7 +115,7 @@ export default { | |
| ) | ||
| }, | ||
|
|
||
| pageClasses () { | ||
| pageClasses() { | ||
| const userPageClass = this.$page.frontmatter.pageClass | ||
| return [ | ||
| { | ||
|
|
@@ -107,10 +127,14 @@ export default { | |
| }, | ||
| userPageClass | ||
| ] | ||
| }, | ||
|
|
||
| adsConfig() { | ||
| return this.$site.themeConfig.carbonAds | ||
| } | ||
| }, | ||
|
|
||
| mounted () { | ||
| mounted() { | ||
| this.$router.afterEach(() => { | ||
| this.isSidebarOpen = false | ||
| }) | ||
|
|
@@ -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) { | ||
|
|
@@ -161,7 +185,7 @@ export default { | |
| this.isMenuFixed = this.isUnderBanner() | ||
| }, | ||
|
|
||
| closeBanner (e) { | ||
| closeBanner(e) { | ||
| // Remove events | ||
| this.toggleBannerEvents(false) | ||
| // Hide the banner | ||
|
|
@@ -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 { | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| content: ''; | ||
| position: relative; | ||
| display: block; | ||
| float: right; | ||
| height: 221px; | ||
| padding: 0 0 20px 30px; | ||
| margin-top: 20px; | ||
| margin-right: -24px; | ||
| } | ||
| } | ||
| </style> | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.



There was a problem hiding this comment.
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