My first Jekyll Plugin - Google Search Console Site Verification File Generator
Generate what generated can be!
This site is built using the SSG A Static Site Generator compiles the website before deployment. Then the generated web content is simply retrieved as-is by the client without any code running at retrieve time. Jekyll A Static Site Generator (SSG) built with ruby. Popularized as of its adoption in GitHub Pages.
and I’ve enjoyed every bit of it! I like the idea of generating everything (boilerplate) that can be generated so that I and the source tree of this blog can focus on the actual content of this site. As I started to set this site up at the stage of migrating content over from my old handcrafted site I cam across the
google47733b3288357e4.html file in my old source tree. I guess I need this one and should copy it over? A quick refresher on the purpose of this file: it’s a verification method offered by Google Search Console for website owners to verify the ownership of a site, before getting insights and control over how Google can index it.
There are multiple ways to verify the ownership of your site. The two simpler ways, both suitable for GitHub Pages owners, are to add an
<meta> tag to your pages or upload a special unique file to the root of the site. For adding the meta tag, there are excellent plugins making this very easy for example jekyll-seo-tag. If you want to the meta tag, I recommend this plugin.
However if you feel that it’s bloated to add this
<meta> tag to the header all you pages, keeping file size and page load speed in mind, you may one to go for the file based verification method instead.
So with the file based method, why not just add the file you downloaded from GSC to your source directory and let Jekyll put it in
_site/ on generation? As we’re using a SSG, we should generate everything we can! It’s verdantly nice to keep the source tree clean and make everything that can be a configuration that generates what is needed.
An opportunity to learn Jekyll and Ruby*
Thus, I decided to write myself a plugin to solve this problem, and learn a bit more about Jekyll and the ruby development ecosystem in general. I’m not passing on such an opportunity!
The plugin I developed is named
jekyll-google_search_console_verification_file and can be found on my GitHub profile erikw/jekyll-google_search_console_verification_file or at rubygems.org.
Give the plugin the unique code GSC provided you and it will generate the file for you in
_site/! Setting it up would be as simple as
Installation & Usage
1) When standing in your Jekyll project root, run
2) In your site’s
_config.yml, enable the plugin and set the verification code from Google
3) Now just build your site and verify that the verification file now exist!
I learned a whole lot by writing this plugin. Implementing the actual logic was rather straight forward, but learning about ruby gem mainelopment and rspec testing ecosystem was more challenging and interesting!
If you find this plugin useful or have suggestions on improvements, please let me know in the comments below or create an issue in the GitHub Project!
Leave a comment
Your email address will not be published. Required fields are marked *