tidy, buff the readme
This commit is contained in:
parent
a0a5f8a575
commit
369915854c
17
README.md
17
README.md
|
@ -10,10 +10,21 @@ SQL checking macros, so your DB needs to have the tables to allow the SQL checks
|
||||||
|
|
||||||
## How does it work?
|
## How does it work?
|
||||||
|
|
||||||
If you wish to use this on your webpage, just add the following lines to the page you want a counter
|
If you wish to use this on your webpage, you need to add a couple lines. First, a "tracking pixel"
|
||||||
on:
|
that registers the current page's view:
|
||||||
|
|
||||||
|
``` html
|
||||||
|
<img src=http://localhost:5000/hit style="visibility:hidden">
|
||||||
|
```
|
||||||
|
|
||||||
|
Then, some javascript to retrieve the hit counts:
|
||||||
|
|
||||||
|
``` html
|
||||||
|
help I don't know how to javascript, we need to get http://localhost:5000/hits/all (or 'day' or
|
||||||
|
'week'), and that will return the number of recorded hits for this page for that time period.
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
TODO!!!
|
|
||||||
|
|
||||||
It uses the `referer` header to get the page it was called from, and uses that as the key for
|
It uses the `referer` header to get the page it was called from, and uses that as the key for
|
||||||
counting the hit.
|
counting the hit.
|
||||||
|
|
|
@ -22,7 +22,7 @@ async fn main() {
|
||||||
|
|
||||||
let pool = db().await;
|
let pool = db().await;
|
||||||
let app = Router::new()
|
let app = Router::new()
|
||||||
.route("/hit", get(count_hit))
|
.route("/hit", get(register_hit))
|
||||||
.route("/hits/:period", get(get_hits))
|
.route("/hits/:period", get(get_hits))
|
||||||
.with_state(pool.clone())
|
.with_state(pool.clone())
|
||||||
.into_make_service();
|
.into_make_service();
|
||||||
|
@ -35,7 +35,7 @@ async fn main() {
|
||||||
pool.close().await;
|
pool.close().await;
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn count_hit(State(db): State<SqlitePool>, headers: HeaderMap) -> String {
|
async fn register_hit(State(db): State<SqlitePool>, headers: HeaderMap) -> String {
|
||||||
let now = chrono::Utc::now();
|
let now = chrono::Utc::now();
|
||||||
let referer = headers.get(REFERER);
|
let referer = headers.get(REFERER);
|
||||||
let page = if let Some(referer) = referer {
|
let page = if let Some(referer) = referer {
|
||||||
|
@ -109,7 +109,7 @@ async fn get_period_hits(db: &SqlitePool, page: &str, when: &str) -> i32 {
|
||||||
)
|
)
|
||||||
.fetch_one(db)
|
.fetch_one(db)
|
||||||
.await
|
.await
|
||||||
.unwrap_or(1)
|
.unwrap_or(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
//-************************************************************************
|
//-************************************************************************
|
||||||
|
|
Loading…
Reference in New Issue