From ea66ff939d39fc00759a7c8e66452998bf609e86 Mon Sep 17 00:00:00 2001 From: ppoffice Date: Thu, 26 Dec 2019 12:02:07 -0500 Subject: [PATCH] feat(layout): add adsense widget --- .gitignore | 2 +- include/schema/common/widgets.json | 3 +++ include/schema/widget/adsense.json | 25 ++++++++++++++++++ languages/en.yml | 6 ++--- languages/zh-CN.yml | 3 +++ languages/zh-TW.yml | 5 ++-- layout/common/head.jsx | 8 ++++++ layout/widget/adsense.jsx | 41 ++++++++++++++++++++++++++++++ layout/widget/subscribe_email.jsx | 38 +++++++++++++-------------- 9 files changed, 103 insertions(+), 28 deletions(-) create mode 100644 include/schema/widget/adsense.json create mode 100644 layout/widget/adsense.jsx diff --git a/.gitignore b/.gitignore index 7a1d212..4e2a447 100644 --- a/.gitignore +++ b/.gitignore @@ -106,5 +106,5 @@ dist # Stores VSCode versions used for testing VSCode extensions .vscode-test -_config.yml* +_config*.yml* yarn.lock diff --git a/include/schema/common/widgets.json b/include/schema/common/widgets.json index f89c3f2..3be97f6 100644 --- a/include/schema/common/widgets.json +++ b/include/schema/common/widgets.json @@ -36,6 +36,9 @@ }, { "$ref": "/widget/subscribe_email.json" + }, + { + "$ref": "/widget/adsense.json" } ], "required": [ diff --git a/include/schema/widget/adsense.json b/include/schema/widget/adsense.json new file mode 100644 index 0000000..ed3815a --- /dev/null +++ b/include/schema/widget/adsense.json @@ -0,0 +1,25 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "$id": "/widget/adsense.json", + "description": "Google AdSense unit configurations", + "type": "object", + "properties": { + "type": { + "type": "string", + "const": "adsense" + }, + "client_id": { + "type": "string", + "description": "AdSense client ID" + }, + "slot_id": { + "type": "string", + "description": "AdSense AD unit ID" + } + }, + "required": [ + "type", + "client_id", + "slot_id" + ] +} \ No newline at end of file diff --git a/languages/en.yml b/languages/en.yml index 657939f..57da28e 100644 --- a/languages/en.yml +++ b/languages/en.yml @@ -19,9 +19,9 @@ widget: links: 'Links' tag_cloud: 'Tag Cloud' catalogue: 'Catalogue' - email: - title: 'Subscribe Email' - button: 'Subscribe' + subscribe_email: 'Subscribe to Updates' + subscribe: 'Subscribe' + adsense: 'Advertisement' article: more: 'Read More' comments: 'Comments' diff --git a/languages/zh-CN.yml b/languages/zh-CN.yml index af22ef3..5044492 100644 --- a/languages/zh-CN.yml +++ b/languages/zh-CN.yml @@ -19,6 +19,9 @@ widget: links: '链接' tag_cloud: '标签云' catalogue: '目录' + subscribe_email: '订阅更新' + subscribe: '订阅' + adsense: '广告' article: more: '阅读更多' comments: '评论' diff --git a/languages/zh-TW.yml b/languages/zh-TW.yml index a705b73..007e14c 100644 --- a/languages/zh-TW.yml +++ b/languages/zh-TW.yml @@ -19,9 +19,8 @@ widget: links: '連結' tag_cloud: '標籤雲' catalogue: '文章目錄' - email: - title: '訂閱 Email' - button: '訂閱' + subscribe_email: '訂閱 Email' + subscribe: '訂閱' article: more: '繼續閱讀' comments: '評論' diff --git a/layout/common/head.jsx b/layout/common/head.jsx index 0592f7e..9bf26e9 100644 --- a/layout/common/head.jsx +++ b/layout/common/head.jsx @@ -73,6 +73,11 @@ module.exports = class extends Component { images = [url_for('/img/og_image.png')]; } + let adsenseClientId = null; + if (Array.isArray(config.widgets)) { + adsenseClientId = config.widgets.find(widget => widget.type === 'adsense').client_id; + } + return {meta_generator ? : null} @@ -109,6 +114,9 @@ module.exports = class extends Component { {hlTheme ? : null} + + {adsenseClientId ? : null} ; } }; diff --git a/layout/widget/adsense.jsx b/layout/widget/adsense.jsx new file mode 100644 index 0000000..1e4e73c --- /dev/null +++ b/layout/widget/adsense.jsx @@ -0,0 +1,41 @@ +const { Component } = require('inferno'); +const { cacheComponent } = require('../util/cache'); + +class AdSense extends Component { + render() { + const { title, clientId, slotId } = this.props; + if (!clientId || !slotId) { + return
+
+
+ You need to set client_id and slot_id to show this AD unit. + Please set it in _config.yml. +
+
+
; + } + return
+
+ +
+
; + } +} + +module.exports = cacheComponent(AdSense, 'widget.adsense', props => { + const { widget, helper } = props; + const { client_id, slot_id } = widget; + + return { + title: helper.__('widget.adsense'), + clientId: client_id, + slotId: slot_id + } +}); \ No newline at end of file diff --git a/layout/widget/subscribe_email.jsx b/layout/widget/subscribe_email.jsx index 1964a1f..f27fce0 100644 --- a/layout/widget/subscribe_email.jsx +++ b/layout/widget/subscribe_email.jsx @@ -9,27 +9,23 @@ class SubscribeEmail extends Component {
; @@ -43,7 +39,7 @@ module.exports = cacheComponent(SubscribeEmail, 'widget.subscribeemail', props = return { description, feedburnerId: feedburner_id, - title: helper.__('widget.email.title'), - buttonTitle: helper.__('widget.email.button') + title: helper.__('widget.subscribe_email'), + buttonTitle: helper.__('widget.subscribe') }; });