Keybase Static Site Verification

Joe • April 14, 2019

General Laravel static-sites Jigsaw

I recently converted my WordPress site over to a static site (using TightenCo's Jigsaw and ran into a problem I figured others might also: my web site verification failed because the URL to my verification file no longer exists. Keybase sent me an email with the subject "your web ( proof just broke" letting me know that I needed to replace the file or revoke the proof. Since I left my WordPress server running it is no big deal for me to grab the file and drop it into the repo. When I tried this, I added the file to source/.well-known/keybase.txt thinking that Jigsaw may automatically pick that file up and place it in the root of my build folder, and thus it would get deployed automatically to my Netlify host. I noticed this assumption was incorrect when I ran php vendor/bin/jigsaw build production the ./well-known folder was not created. Fair enough, Jigsaw makes no such claims and I read in the documentation there are events that I can create listeners for.

I specifically chose Jigsaw for my static site generator because I've previously used and enjoyed I wanted to check out Jigsaw as it is built using Laravel. My own familiarity with Laravel came in handy as I opened up bootstrap.php to see an example of creating a PHP class to listen to the events emitted by Jigsaw.

I created a new listener class in listeners/GenerateKeybaseFile.php:

namespace App\Listeners;

use TightenCo\Jigsaw\Jigsaw;

class GenerateKeybaseFile
    public function handle(Jigsaw $jigsaw)
        $pathToFile = $jigsaw->getConfig('keyBaseFilePath');
        $keyBaseFile = file_get_contents($pathToFile);

        if (!is_dir($jigsaw->getDestinationPath().'/.well-known'))

        file_put_contents($jigsaw->getDestinationPath().'/.well-known/keybase.txt', $keyBaseFile);

And called my new class from bootstrap.php:


You'll note our GenerateKeybaseFile class introduces a hard dependency on having a configuration value keyBaseFilePath. So we'll want to add this value to our config.php:

'keyBaseFilePath' => __DIR__ . '/source/.well-known/keybase.txt',

Since I already dropped my keybase.txt file into the source folder I went ahead and used this path. Just remember the path will be relative to where config.php is located. Now we can run php /vendor/bin/jigsaw build to create our build and ./vendor/bin/jigsaw serve to preview that our file shows up as expected at http://localhost:8000/.well-known/keybase.txt. Once I commited the changes and the site deployed, everything was fine on the Keybase side!

If you're looking to make the move from WordPress to a static site, check out this fantastic blog post by Anthony Terrell: Making the Move from WordPress to Jigsaw. Thanks for reading, happy coding.