Keybase Static Site Verification
Joe • April 14, 2019
general laravel static-sites jigsawI 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 Keybase.io web site verification failed because the URL to my verification file no longer exists. Keybase sent me an email with the subject "your web (joeferguson.me) 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 https://sculpin.io. 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'))
{
mkdir($jigsaw->getDestinationPath().'/.well-known');
}
file_put_contents($jigsaw->getDestinationPath().'/.well-known/keybase.txt', $keyBaseFile);
}
}
And called my new class from bootstrap.php
:
$events->afterBuild(App\Listeners\GenerateKeybaseFile::class);
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.
As Seen On
Recent Posts
- PHP to Rust via Copilot
- Compiling Python 3.12 from Source Tarball on Linux
- HTML Form Processing with PHP - php[architect] Magazine August 2014
- The Workshop: Local Dev with Lando - php[architect] Magazine November 2022
- Getting back into the swing of things
- All Posts
Categories
- ansible
- apache
- applesilicon
- aws
- blackwidow
- cakephp
- community
- composer
- conferences
- copilot
- data-storage
- day-job
- devops
- docker
- fpv
- general
- github
- givecamp
- homestead
- jigsaw
- joindin
- keyboard
- laravel
- learning
- linux
- maker
- mamp
- mentoring
- music
- nonprofit
- opensource
- packages
- php
- phparch
- projects
- provisioning
- python
- razer
- rust
- s3
- security
- slimphp
- speaking
- static-sites
- storage
- testing
- tiny-whoop
- today-i-learned
- training
- ubuntu
- vagrant
- version-control
- windows
- writing
- wsl
- wsl2
- zend-zray