/site

My website

Primary LanguageGoBSD 3-Clause "New" or "Revised" LicenseBSD-3-Clause

dnlm.pw

Code for dnlm.pw, a personal website.

Technology

Development

$ go run ./cmd/dnlm

or

$ go build -o ./bin/web ./cmd/dnlm
$ ./bin/web

The application will be available at http://localhost:4000 by default.

The app also accepts an optional -config flag to specify the location of the configuration file. The default location is ./config/config.yml so you can run the app with a custom configuration file like so:

$ go run ./cmd/dnlm -config /path/to/config.yml

By default, the app will look for a config.yml file in the ./config directory. It will fail if it does not find one.

The application also has an optional -blog flag to specify the location of the blog posts. The default location is ./blog so you can run the app with a custom blog directory like so:

$ go run ./cmd/dnlm -blog /path/to/blog

Blog Posts

By default the app will look for blog posts in the ./blog directory. The blog posts should be written in markdown and file names should be in the format title-of-the-post.md.

Frontmatter is currently not supported but will be in the future.

Configuration

The application uses a YAML configuration file to set up the application. The default location is ./config/config.yml. The configuration file should look like this:

name: Daniel M. Matongo
profession: Software Developer
description: I build web applications and APIs using Ruby on Rails and Go. I also write about software development and programming. I am based in Bath, UK.
photos_description: A collection of photos I've taken since I started photography.
blog_name: .daniel's musings
repository: https://github.com/mmatongo/site/blob/master/

You can optionally configure the application to show the music you're currently listening to with Spotify. To do this, you need to set up a Spotify application at Spotify Developer and get the client ID and client secret.

For security reasons, the client id and secret should not be stored in the configuration file. Instead, you can set it as an environment variable like so: You need to provide the client ID and client secret, redirect URL and the state. The redirect URL should be the one you set up in the Spotify application. The state is a random string that you generate to protect against CSRF attacks.

$ export SPOTIFY_ID=your-client-id
$ export SPOTIFY_SECRET=your-client-secret
$ export REDIRECT_URI=your-redirect-url
$ export STATE=your-random-string

The application will use these environment variables to authenticate with Spotify and get the currently playing track. You will be required to log in to Spotify to authorise the application to access your account whenever you start the application (will look into caching this in the future).

Now you can run the application and it will show the music you're currently listening to like so:

Spotify

Caveats

Because Heroku restarts the application every 24 hours, you will need to log in to Spotify every time the application restarts. Now you can set up a webhook to listen for when the application restarts but you'd still need to log in to Spotify to authorise the application. My very temporary solution is to send myself an email every time the application restarts so I can log in to Spotify.

Why not just cache the token? Because the token expires every hour and I don't want to deal with refreshing the token every hour. Why not use something like Chanify to send a notification to my phone? Because I'm lazy and I don't want to set it up and I don't want to deal with the notifications.

I will look into a better solution in the future. Especially around refreshing the token. (Note that this does already exist and works but at restart it will require you to log in again. I'm not sure if this is a limitation of the Spotify API or if I'm doing something wrong.)

To get Emails when the application restarts, export the following environment variables:

$ export TO_EMAIL=your-email
$ export FROM_EMAIL=your-email
$ export APP_PASSWORD=the-app-password

The APP_PASSWORD is the password you set up for your email account. You can set up an app password for your email account if you use Gmail. You can find more information here.

Deployment

The application is deployed on Heroku and also uses Cloudflare R2 Storage to store images. The application is deployed automatically when changes are pushed to the master branch.

License

The following directories and their contents are Copyright Daniel M. Matongo. You may not reuse anything therein without my permission:

blog/
notes/
ui/static/images/
ui/static/json/

All other directories and files are BSD 3-Clause Licensed (where applicable).

This project is licensed under the BSD 3-Clause License. See LICENSE for more information.

Roadmap

You can find the project roadmap here.