From 99bf3044d6cecd9d2d51e53bef04b1d8f72f02e1 Mon Sep 17 00:00:00 2001 From: tangjinzhou <415800467@qq.com> Date: Thu, 17 Jan 2019 11:59:21 +0800 Subject: [PATCH] docs: update ad --- site/components/CarbonAds.vue | 79 +++++++++++++++++++++++++++++++++++ site/components/layout.vue | 21 +--------- site/index.html | 57 ------------------------- site/index.js | 4 +- 4 files changed, 84 insertions(+), 77 deletions(-) create mode 100644 site/components/CarbonAds.vue diff --git a/site/components/CarbonAds.vue b/site/components/CarbonAds.vue new file mode 100644 index 000000000..0e05c2d39 --- /dev/null +++ b/site/components/CarbonAds.vue @@ -0,0 +1,79 @@ +<script> +const carbonUrls = { + 'vuecomponent.github.io':'//cdn.carbonads.com/carbon.js?serve=CK7DL2JW&placement=vuecomponentgithubio', + 'tangjinzhou.gitee.io':'//cdn.carbonads.com/carbon.js?serve=CK7DL2JN&placement=tangjinzhougiteeio', +}; +const carbonUrl = carbonUrls[location.host]; +export default { + mounted() { + this.load(); + }, + watch: { + $route(e, t) { + if(e.path !== t.path && this.$el.querySelector("#carbonads")){ + this.$el.innerHTML = ""; + this.load(); + } + }, + }, + methods: { + load() { + if(carbonUrl) { + const e = document.createElement("script"); + e.id = "_carbonads_js"; + e.src = carbonUrl; + this.$el.appendChild(e); + } + }, + }, + render () { + return ( + <div id="carbon-ads"/> + ); + }, +}; +</script> +<style> + #carbon-ads { + width: 145px; + position: fixed; + bottom: 10px; + right: 10px; + padding: 10px; + background-color: #fff; + border-radius: 3px; + font-size: 13px; + font-family: "Source Sans Pro", "Helvetica Neue", Arial, sans-serif; +} +#carbon-ads a { + display: inline-block; + color: #7f8c8d; + font-weight: normal; +} +#carbon-ads span { + color: #7f8c8d; + display: inline-block; + margin-bottom: 5px; +} +#carbon-ads img { + width: 125px; +} +#carbon-ads .carbon-img, +#carbon-ads .carbon-text { + display: block; + margin-bottom: 6px; + font-weight: normal; + color: #34495e; +} +#carbon-ads .carbon-text { + display: -webkit-box; + -webkit-box-orient: vertical; + -webkit-line-clamp: 4; + overflow: hidden; +} +#carbon-ads .carbon-poweredby { + color: #aaa ; + font-weight: normal ; + line-height: 1.2 ; +} +</style> diff --git a/site/components/layout.vue b/site/components/layout.vue index 7195811e1..d997b6330 100644 --- a/site/components/layout.vue +++ b/site/components/layout.vue @@ -3,11 +3,11 @@ import { enquireScreen } from 'enquire-js'; import AllDemo from '../demo'; import Header from './header'; import Footer from './footer'; +import CarbonAds from './CarbonAds'; import Sponsors from './sponsors'; import zhCN from 'antd/locale-provider/zh_CN'; import enUS from 'antd/locale-provider/default'; import sortBy from 'lodash/sortBy'; -import axios from 'axios'; import { isZhCN } from '../util'; import { Provider, create } from '../../components/_util/store'; import NProgress from 'nprogress'; @@ -156,24 +156,6 @@ export default { mountedCallback () { NProgress.done(); document.documentElement.scrollTop = 0; - try { - const isGithub = location.host.indexOf('github') !== -1; - if(isGithub){ - document.getElementById('ad').innerHTML = ''; - const src = '//cdn.carbonads.com/carbon.js?serve=CK7DL2JW&placement=vuecomponentgithubio'; - const hm = document.createElement('script'); - hm.src = src; - hm.id = '_carbonads_js'; - const s = document.getElementById('ad'); - s.append(hm); - } else { - axios.get('https://api.codefund.app/properties/162/funder.html?template=square') - .then(function (response) { - document.getElementById("codefund").innerHTML = response.data; - }); - } - - } catch (error) {} }, }, @@ -320,6 +302,7 @@ export default { </div> </a-locale-provider> { name.indexOf('back-top') === -1 ? <a-back-top /> : null } + <CarbonAds /> </div> ); }, diff --git a/site/index.html b/site/index.html index 9b9fa0036..1b3fcd791 100644 --- a/site/index.html +++ b/site/index.html @@ -16,63 +16,6 @@ display: none; } </style> - <style> - #ad, #codefund { - width: 145px; - position: fixed; - bottom: 10px; - right: 10px; - padding: 10px; - background-color: #fff; - border-radius: 3px; - font-size: 13px; - font-family: "Source Sans Pro", "Helvetica Neue", Arial, sans-serif; -} -#ad a, #codefund a { - display: inline-block; - color: #7f8c8d; - font-weight: normal; -} -#codefund a { - color: #7f8c8d !important; - font-weight: normal !important; -} -#ad span { - color: #7f8c8d; - display: inline-block; - margin-bottom: 5px; -} -#codefund #cf { - margin-bottom: 0px!important; - border-radius: 0px!important; -} -#ad img { - width: 125px; -} -#ad .carbon-img, -#ad .carbon-text { - display: block; - margin-bottom: 6px; - font-weight: normal; - color: #34495e; -} -#ad .carbon-text, -#codefund .cf-text { - display: -webkit-box!important; - -webkit-box-orient: vertical!important; - -webkit-line-clamp: 4!important; - overflow: hidden!important; -} -#codefund .cf-text { - padding-bottom: 5px !important; - font-size: 12px !important; -} -#ad .carbon-poweredby, #codefund .cf-powered-by { - color: #aaa !important; - font-weight: normal !important; - line-height: 1.2 !important; -} - </style> <script> var _hmt = _hmt || []; var isGithub = location.host.indexOf('github') !== -1; diff --git a/site/index.js b/site/index.js index 68197d419..53a716683 100644 --- a/site/index.js +++ b/site/index.js @@ -51,7 +51,9 @@ const router = new VueRouter({ routes, }); router.beforeEach((to, from, next) => { - NProgress.start(); + if (to.path !== from.path) { + NProgress.start(); + } next(); }); new Vue({