I always hated running. And now I have a open-source running blog. Most entries are automatically generated from runs recorded in Strava - I’m just too lazy to do it by hand :)
These are the implementation details.
Jekyll and Github Pages
I started with a basic Jekyll + Github Pages blog like the one you’re looking at now. You can read about the basic setup in this post. I copied everything from this blog to the new one, deleted all content and customized some logos and colors, mostly in
That is run.dblock.org@6e33b125.
Getting Data from Strava
I created an app on Strava and noted the access token from strava.com/settings/api and used it with strava-ruby-client to talk to Strava’s Open API.
Note that this token expires quickly. See this post for how to refresh it, in general, and below for how to make this process work in Travis-CI.
Plotting Runs with Google Maps
Each activity comes with an encoded summary polyline in
activity.map.summary_polyline, which can be passed directly to Google Static Maps API with the
enc: prefix to render a nice image.
Google Static Maps API requires a key that you can get from the console.
Adding Start and Finish Markers
Strava API does not unfortunately return precise-enough coordinates to plot start and finish of the runs, but we can pluck these out from the decoded polyline using the polylines gem.
These markers are added to the map with
By default Strava API only returns the primary photo. Call
activity_photos to get all of them and specify
size for anything other than thumbnails. Note that this seems to be an undocumented Strava API.
Generating Jekyll Pages
I wrote a Rake task that iterates over Strava activities and outputs a
.md file for each run.
For example, 2018/2018-01-21-run-13.34mi-1h47m18s.md is generated for a post titled #FLMH.
You can see the complete Rake task here.
I wrote a bash script that runs
rake strava:update and commits changes, if any, to Github.
To commit to Github you need a
public_repo permission token. Create one in github.com/settings/tokens. Set it as
And configured Travis-CI to run the script in
This is run.dblock.org@2a08d5ec.
To make this process work recurrently, I added
GH_TOKEN values to Travis-CI UI, then added a daily Cron job. This is because we want Travis to run an update both when code (eg. stylesheet) changes are pushed to Github and when new runs are posted to Strava.
The Strava refresh token must be kept secret and therefore I encrypted it with
travis encrypt STRAVA_API_REFRESH_TOKEN=... --add env, which adds it to
.travis.yml. This uses the Travis-CI public key and can only be decrypted in Travis-CI. The Rake task also updates the refresh token if it has changed as a result of the OAuth workflow.
Find my running blog at run.dblock.org, the latest code for this post at github.com/dblock/run.dblock.org and read about why I run here.