Skip to content

Commit

Permalink
feat(view): add cnzz plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
ppoffice committed Mar 8, 2020
1 parent 2a78c04 commit 826bb98
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/schema/plugin/cnzz.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "/plugin/cnzz.json",
"description": "CNZZ statistics\nhttps://www.umeng.com/web",
"type": "object",
"properties": {
"id": {
"type": [
"string",
"number"
],
"description": "CNZZ tracker id",
"nullable": true
},
"web_id": {
"type": [
"string",
"number"
],
"description": "CNZZ website id",
"nullable": true
}
},
"required": [
"id",
"web_id"
]
}
43 changes: 43 additions & 0 deletions src/view/plugin/cnzz.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* CNZZ statistics plugin JSX component.
* @module view/plugin/cnzz
*/
const { Component } = require('inferno');
const { cacheComponent } = require('../../util/cache');

/**
* CNZZ statistics plugin JSX component.
*
* @see https://developer.umeng.com/docs/67963/detail/68609
* @example
* <Cnzz id="******" webId="******" />
*/
class Cnzz extends Component {
render() {
const { id, webId } = this.props;
return <script src={`https://s9.cnzz.com/z_stat.php?id=${id}&web_id=${webId}`} async={true}></script>;
}
}

/**
* Cacheable CNZZ statistics plugin JSX component.
* <p>
* This class is supposed to be used in combination with the <code>locals</code> hexo filter
* ({@link module:hexo/filter/locals}).
*
* @see module:util/cache.cacheComponent
* @example
* <Cnzz.Cacheable
* head={false}
* plugin={{ id: '******', web_id: '******' }} />
*/
module.exports = cacheComponent(Cnzz, 'plugin.cnzz', props => {
const { head, plugin } = props;
if (head || !plugin.id || !plugin.web_id) {
return null;
}
return {
id: plugin.id,
webId: plugin.web_id
};
});

1 comment on commit 826bb98

@ppoffice
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.