feat(layout): add adsense widget
This commit is contained in:
parent
dd09bbe55b
commit
ea66ff939d
|
@ -106,5 +106,5 @@ dist
|
||||||
# Stores VSCode versions used for testing VSCode extensions
|
# Stores VSCode versions used for testing VSCode extensions
|
||||||
.vscode-test
|
.vscode-test
|
||||||
|
|
||||||
_config.yml*
|
_config*.yml*
|
||||||
yarn.lock
|
yarn.lock
|
||||||
|
|
|
@ -36,6 +36,9 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"$ref": "/widget/subscribe_email.json"
|
"$ref": "/widget/subscribe_email.json"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"$ref": "/widget/adsense.json"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"required": [
|
"required": [
|
||||||
|
|
|
@ -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"
|
||||||
|
]
|
||||||
|
}
|
|
@ -19,9 +19,9 @@ widget:
|
||||||
links: 'Links'
|
links: 'Links'
|
||||||
tag_cloud: 'Tag Cloud'
|
tag_cloud: 'Tag Cloud'
|
||||||
catalogue: 'Catalogue'
|
catalogue: 'Catalogue'
|
||||||
email:
|
subscribe_email: 'Subscribe to Updates'
|
||||||
title: 'Subscribe Email'
|
subscribe: 'Subscribe'
|
||||||
button: 'Subscribe'
|
adsense: 'Advertisement'
|
||||||
article:
|
article:
|
||||||
more: 'Read More'
|
more: 'Read More'
|
||||||
comments: 'Comments'
|
comments: 'Comments'
|
||||||
|
|
|
@ -19,6 +19,9 @@ widget:
|
||||||
links: '链接'
|
links: '链接'
|
||||||
tag_cloud: '标签云'
|
tag_cloud: '标签云'
|
||||||
catalogue: '目录'
|
catalogue: '目录'
|
||||||
|
subscribe_email: '订阅更新'
|
||||||
|
subscribe: '订阅'
|
||||||
|
adsense: '广告'
|
||||||
article:
|
article:
|
||||||
more: '阅读更多'
|
more: '阅读更多'
|
||||||
comments: '评论'
|
comments: '评论'
|
||||||
|
|
|
@ -19,9 +19,8 @@ widget:
|
||||||
links: '連結'
|
links: '連結'
|
||||||
tag_cloud: '標籤雲'
|
tag_cloud: '標籤雲'
|
||||||
catalogue: '文章目錄'
|
catalogue: '文章目錄'
|
||||||
email:
|
subscribe_email: '訂閱 Email'
|
||||||
title: '訂閱 Email'
|
subscribe: '訂閱'
|
||||||
button: '訂閱'
|
|
||||||
article:
|
article:
|
||||||
more: '繼續閱讀'
|
more: '繼續閱讀'
|
||||||
comments: '評論'
|
comments: '評論'
|
||||||
|
|
|
@ -73,6 +73,11 @@ module.exports = class extends Component {
|
||||||
images = [url_for('/img/og_image.png')];
|
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 <head>
|
return <head>
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
{meta_generator ? <meta name="generator" content={`Hexo ${env.version}`} /> : null}
|
{meta_generator ? <meta name="generator" content={`Hexo ${env.version}`} /> : null}
|
||||||
|
@ -109,6 +114,9 @@ module.exports = class extends Component {
|
||||||
{hlTheme ? <link rel="stylesheet" href={cdn('highlight.js', '9.12.0', 'styles/' + hlTheme + '.css')} /> : null}
|
{hlTheme ? <link rel="stylesheet" href={cdn('highlight.js', '9.12.0', 'styles/' + hlTheme + '.css')} /> : null}
|
||||||
<Plugins site={site} config={config} helper={helper} page={page} head={true} />
|
<Plugins site={site} config={config} helper={helper} page={page} head={true} />
|
||||||
<link rel="stylesheet" href={url_for('/css/style.css')} />
|
<link rel="stylesheet" href={url_for('/css/style.css')} />
|
||||||
|
|
||||||
|
{adsenseClientId ? <script data-ad-client={adsenseClientId}
|
||||||
|
src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js" async={true}></script> : null}
|
||||||
</head>;
|
</head>;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -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 <div class="card widget">
|
||||||
|
<div class="card-content">
|
||||||
|
<div class="notification is-danger">
|
||||||
|
You need to set <code>client_id</code> and <code>slot_id</code> to show this AD unit.
|
||||||
|
Please set it in <code>_config.yml</code>.
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>;
|
||||||
|
}
|
||||||
|
return <div class="card widget">
|
||||||
|
<div class="card-content">
|
||||||
|
<div class="menu">
|
||||||
|
<h3 class="menu-label">{title}</h3>
|
||||||
|
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
|
||||||
|
<ins class="adsbygoogle"
|
||||||
|
data-ad-client={clientId}
|
||||||
|
data-ad-slot={slotId}></ins>
|
||||||
|
<script dangerouslySetInnerHTML={{ __html: '(adsbygoogle = window.adsbygoogle || []).push({});' }}></script>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
});
|
|
@ -9,27 +9,23 @@ class SubscribeEmail extends Component {
|
||||||
<div class="card-content">
|
<div class="card-content">
|
||||||
<div class="menu">
|
<div class="menu">
|
||||||
<h3 class="menu-label">{title}</h3>
|
<h3 class="menu-label">{title}</h3>
|
||||||
<div>
|
<form action="https://feedburner.google.com/fb/a/mailverify" method="post" target="popupwindow"
|
||||||
<form action="https://feedburner.google.com/fb/a/mailverify" method="post" target="popupwindow"
|
onsubmit={`window.open('https://feedburner.google.com/fb/a/mailverify?uri=${feedburnerId}','popupwindow','scrollbars=yes,width=550,height=520');return true`}>
|
||||||
onsubmit={`window.open('https://feedburner.google.com/fb/a/mailverify?uri=${feedburnerId}','popupwindow','scrollbars=yes,width=550,height=520');return true`}>
|
<input type="hidden" value={feedburnerId} name="uri" />
|
||||||
<input type="hidden" value={feedburnerId} name="uri" />
|
<input type="hidden" name="loc" value="en_US" />
|
||||||
<input type="hidden" name="loc" value="en_US" />
|
<div class="field has-addons">
|
||||||
<div class="field">
|
<div class="control has-icons-left">
|
||||||
<div class="control has-icons-left">
|
<input class="input" name="email" type="email" placeholder="Email" />
|
||||||
<input class="input" name="email" type="email" />
|
<span class="icon is-small is-left">
|
||||||
<span class="icon is-small is-left">
|
<i class="fas fa-envelope"></i>
|
||||||
<i class="fas fa-envelope"></i>
|
</span>
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<p class="help">{description}</p>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="field is-grouped is-grouped-right">
|
<div class="control">
|
||||||
<div class="control">
|
<input class="button is-link" type="submit" value={buttonTitle} />
|
||||||
<input class="button is-link" type="submit" value={buttonTitle} />
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</form>
|
{description ? <p class="help">{description}</p> : null}
|
||||||
</div>
|
</div>
|
||||||
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>;
|
</div>;
|
||||||
|
@ -43,7 +39,7 @@ module.exports = cacheComponent(SubscribeEmail, 'widget.subscribeemail', props =
|
||||||
return {
|
return {
|
||||||
description,
|
description,
|
||||||
feedburnerId: feedburner_id,
|
feedburnerId: feedburner_id,
|
||||||
title: helper.__('widget.email.title'),
|
title: helper.__('widget.subscribe_email'),
|
||||||
buttonTitle: helper.__('widget.email.button')
|
buttonTitle: helper.__('widget.subscribe')
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue