Displaying Hexo Blog View Counts on AWTRIX
Why I Wanted to Build This App
Back in 2021, when I was revamping my desk setup, I wanted to add a clock. After looking around, I ended up getting an AWTRIX Pro mini.
There are plenty of interesting apps in the AWTRIX App Store — things like GithubFollowers, Bilibili, and so on. I installed GithubFollowers, but after a while I noticed the number was stuck at 7. Pretty embarrassing, honestly. It barely registered emotionally, so I uninstalled it.
That got me thinking — what if I could see the total view count of my blog (the sum of views across all posts)?
How It Works
This was my first time developing an AWTRIX app, and I was pretty clueless at first. Reading the official documentation is the fastest way to get started — if you’re interested, check out Programming (blueforcer.de).
My blog is built with Hexo, and view counting is handled by LeanCloud.
LeanCloud provides a REST API — see the docs here: Storage REST API Guide - LeanCloud Docs
Step 1: Fetch the Data
1 | Sub App_startDownload(jobNr As Int) |
One thing to watch out for here is the case sensitivity of keys in App.get(). I stumbled on this myself.
Step 2: Process the Data
1 | Sub App_evalJobResponse(Resp As JobResponse) |
total_view is a global variable — remember to reset it to zero.
Step 3: Display the Output
1 | Sub App_genFrame |
Full source code: https://github.com/chengqing-su/awtrix-hexo-leancloud-counter
If you need a pre-compiled JAR, grab it here: https://github.com/chengqing-su/awtrix-hexo-leancloud-counter/releases/download/v1.0.0/HexoLeanCloud.tar.gz
Experience
Watching the number change over the past few days has actually given me more motivation to write and maintain my blog.
