Skip to content
This repository has been archived by the owner on Mar 6, 2024. It is now read-only.

Commit

Permalink
meger branch 'feature/es6-class'
Browse files Browse the repository at this point in the history
  • Loading branch information
dongyuanxin committed May 15, 2019
2 parents 08174d4 + 41ca616 commit 147250b
Show file tree
Hide file tree
Showing 12 changed files with 188 additions and 170 deletions.
2 changes: 1 addition & 1 deletion dist/page-counter.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 0 additions & 35 deletions examples/bomb.html

This file was deleted.

11 changes: 7 additions & 4 deletions examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
</script> -->
</head>
<body>
<header>
<a href="https://github.com/dongyuanxin/page-counter#leancloud-%E5%B9%B3%E5%8F%B0" target="_blank">LEANCLOUD</a>
<a href="https://github.com/dongyuanxin/page-counter#bomb-%E5%B9%B3%E5%8F%B0" target="_blank">BOMB</a>
<a href="https://www.npmjs.com/package/page-counter" target="_blank">NPM</a>
</header>
<div class="logo">
<div class="logo-title">
Page Counter: 极简网页计数器
Expand All @@ -27,10 +32,8 @@
</div>
</div>
<footer>
<span id="busuanzi_container_site_pv">
全站访问人数: <span id="page-counter-total-times"></span> |
当前页面访问人数: <span id="page-counter-single-times"></span>
</span>
全站访问人数: <span id="page-counter-total-times"></span> |
当前页面访问人数: <span id="page-counter-single-times"></span>
</footer>
<script>
window.PAGE_COUNTER_CONFIG = {
Expand Down
35 changes: 0 additions & 35 deletions examples/leancloud.html

This file was deleted.

45 changes: 44 additions & 1 deletion examples/static/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,49 @@ body {
min-height: 100vh;
min-width: 100vw;
background: #0C0C0C;
font-family: -apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen,Ubuntu,Cantarell,Fira Sans,Droid Sans,Helvetica Neue,sans-serif;
}

header {
position: fixed;
width: 100vw;
left: 0;
padding: 20px;
text-align: center;
}

header a {
position: relative;
text-decoration: none;
text-transform: uppercase;
font-size: 9px;
font-weight: bold;
margin: 0 15px;
user-select: none;
letter-spacing: 1px;
color: rgb(101, 103, 101);
}

header a::before {
content: "";
position: absolute;
width: 100%;
height: 1px;
bottom: -5px;
left: 0;
background-color: white;
visibility: hidden;
transform: scaleX(0);
transition: all .25s ease;
}

header a:hover {
color: white;
}

header a:hover::before {
visibility: visible;
transform: scaleX(1);
}

.logo {
Expand Down Expand Up @@ -67,7 +110,7 @@ body {
footer {
text-align: center;
position: fixed;
bottom: 10px;
bottom: 20px;
left: 50%;
transform: translateX(-50%);
color: rgb(101, 103, 101);
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "page-counter",
"version": "1.3.4",
"version": "1.4.0",
"description": "基于Serverless开发的的极简网页计数器,支持基于Hexo、Jekyll、Octopress、ReactJS、VueJS等框架开发的博客、网站、中后台等任何应用。",
"main": "index.js",
"scripts": {
Expand All @@ -18,7 +18,9 @@
"blog",
"serverless",
"analysis",
"es6"
"es6",
"leancloud",
"bomb"
],
"author": "DongYuanxin",
"license": "MIT",
Expand Down
5 changes: 4 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ import ServerLessFactory from './serverless'
import config from './config'
import {
PowerDate,
formatURL
formatURL,
copyright
} from './utils'

copyright()

const platform = config.serverless
const serverless = new ServerLessFactory(platform)

Expand Down
82 changes: 44 additions & 38 deletions src/serverless/bomb.js
Original file line number Diff line number Diff line change
@@ -1,52 +1,58 @@
import config from './../config'
import ServerLessInterface from './interface'

class Hydrogen extends ServerLessInterface {
constructor () {
super()
const {
Bomb,
bomb: {
appId,
restApi
}
} = config
Bomb.initialize(appId, restApi)
}

function Hydrogen() {
const {
Bomb,
bomb: {
appId,
restApi
}
} = config

Bomb.initialize(appId, restApi)
}

Hydrogen.prototype.ACL = function () {
return {
'*': {
read: true
ACL () {
return {
'*': {
read: true
}
}
}
}

Hydrogen.prototype.setData = async function(table, data) {
const query = Bmob.Query(table)
async setData (table, data) {
const { Bomb } = config
const query = Bmob.Query(table)

for (let key of Reflect.ownKeys(data)) {
query.set(key, data[key])
}
for (let key of Reflect.ownKeys(data)) {
query.set(key, data[key])
}

query.set('ACL', this.ACL())
query.set('ACL', this.ACL())

try {
await query.save()
return true
} catch (error) {
return false
try {
await query.save()
return true
} catch (error) {
return false
}
}
}

Hydrogen.prototype.count = async function(table, url) {
const query = Bmob.Query(table)
if (typeof url === 'string' && url.length > 0) {
query.equalTo('URL', '==', url)
}
async count (table, url) {
const { Bomb } = config
const query = Bmob.Query(table)

if (typeof url === 'string' && url.length > 0) {
query.equalTo('URL', '==', url)
}

try {
return await query.count()
} catch (error) {
return 0
try {
return await query.count()
} catch (error) {
return 0
}
}
}

Expand Down
20 changes: 11 additions & 9 deletions src/serverless/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import LeanCloud from './leancloud'
import Bomb from './bomb'

function ServerLessFactory(name) {
name = name.toLocaleLowerCase()
class ServerLessFactory {
constructor (name) {
name = name.toLocaleLowerCase()

switch (name) {
case 'leancloud':
return new LeanCloud()
case 'bomb':
return new Bomb()
default:
throw new Error('Serverless must be one of [leancloud]')
switch (name) {
case 'leancloud':
return new LeanCloud()
case 'bomb':
return new Bomb()
default:
throw new Error('Serverless must be one of [ leancloud, bomb ]')
}
}
}

Expand Down
15 changes: 15 additions & 0 deletions src/serverless/interface.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export default class ServerLessInterface {
constructor () {}

ACL () {
throw new Error('Interface method "ACL" must be rewritten')
}

setData () {
throw new Error('Interface method "setData" must be rewritten')
}

count () {
throw new Error('Interface method "count" must be rewritten')
}
}
Loading

0 comments on commit 147250b

Please sign in to comment.