https://github.com/stulzq/hexo-statistics
https://github.com/stulzq/hexo-statistics
Last synced: 10 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/stulzq/hexo-statistics
- Owner: stulzq
- License: apache-2.0
- Created: 2022-07-04T04:55:42.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2022-07-08T03:43:52.000Z (almost 4 years ago)
- Last Synced: 2024-10-28T11:38:36.937Z (over 1 year ago)
- Language: Go
- Size: 905 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Hexo Statistics
English|[中文](README_zh-CN.md)
Hexo blog traffic statistics service, based on redis. Use hyperloglog to count UV.
Demo: https://xcmaster.com/
Article pv:

Site uv and pv:

## Get Start
### Step
- 1.Install redis and run in standalone mode
- 2.Run hexo-statistics
- 3.Configure your hexo template
### Install Redis
Ubuntu: `apt-get install redis-server`
#### Docker
````shell
mkdir -p /data/redis
docker run -p 6379:6379 \
-v /data/redis/conf/redis.conf:/etc/redis/redis.conf \
-v /data/redis/data:/data \
--name hexo-stat-redis \
-d redis:5.0 redis-server /etc/redis/redis.conf
````
### Run hexo-statistics
#### Binary
````shell
export hexo_version=v0.5.7
wget https://github.com/stulzq/hexo-statistics/releases/download/$hexo_version/hexo-statistics-$hexo_version-linux-amd64.tar.gz
tar -xzvf hexo-statistics-$hexo_version_linux_amd64.tar.gz
cd hexo-statistics-$hexo_version_linux_amd64
# update your config on conf/config.yml
chmod +x hexo_statistics
./hexo-statistics
````
#### Docker
````shell
mkdir -p /data/hexo-stat/conf
curl https://raw.githubusercontent.com/stulzq/hexo-statistics/main/conf/config.yml -o /data/hexo-stat/config.yml
# update your config /data/hexo-stat/config.yml
docker run --name hexo-stat \
-v /data/hexo-stat/conf:/app/conf \
-v /data/hexo-stat/logs:/app/logs \
-d stulzq/hexo-statistics:v0.1.0
````
### Configure template
Save file to /source/js/hexo-stat.js
````javascript
"use strict";
(function() {
var serverDomain = ""
var apiPrefix="" // eg: /api
function hexoGetData() {
$.ajax({
url: serverDomain+ apiPrefix +"/stat/get?u=" +encodeURIComponent(window.location.href),
type: "GET",
dataType: "json",
success: function (resp) {
hexoProcessResult(resp)
hexoCounter()
},
});
}
function hexoCounter(){
var hm = document.createElement("script");
hm.src = serverDomain + apiPrefix +"/stat/counter?u=" + encodeURIComponent(window.location.href);
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hm, s);
}
function hexoProcessResult(data) {
// set result
// site pv -> data.sitePv
// site uv -> data.siteUv
// page pv -> data.pagePv
// example:
$(".statistics").append(`总访问量 ${data.sitePv} 次`);
$(".statistics").append(`总访客数 ${data.siteUv} 人`);
$("div .mt-1").append(
` ${data.pagePv+1} 次`
);
}
hexoGetData();
})();
````
Inject js file:
>file in blog_root/scripts/inject.js
````javascript
hexo.extend.injector.register('body_end', '', 'default');
````
## TODO
- Data Export
- Data Import