jekyll-google_search_console_verification_file

jekyll-google_search_console_verification_file

Jekyll plugin that generates a Google Search Console verification file from configuration.

Jekyll Google Search Console Verification File Generator Plugin

:point_right: Live demo: https://erikw.github.io/jekyll-google_search_console_verification_file/

This is a very simple plugin that will generate a Google Search Console (GSC from here on) verification file to your _site/ directory in a Jekyll project. This file is used by GSC to verify that you own the site and looks for example like my googlef47733b3288357e4.html.

Why?

Why use this plugin?

Tl;DR

  • Don't stuff bloating <meta> tag to all your HTML pages; use simple file in the site's root
  • Generate what can be generated; keep your source tree clean!

!TL;DidRead

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 (Static Site Generator), 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.

Thus, this plugin exist to solve this problem. Give the plugin the unique code GSC provided you and it will generate the file for you in _site/!

Note that if you do place a verification file in the root of the source tree, this will override the generation by this plugin.

Installation

  1. Add this gem to your Jekyll site's Gemfile in the :jekyll_plugins group:
    • On CLI (in project root directory):
      bundle add --group jekyll_plugins jekyll-google_search_console_verification_file
      
    • Or manually:
      group :jekyll_plugins do
      [...]
      gem 'jekyll-google_search_console_verification_file'
      end
      
  2. Run $ bundle install.
  3. In your site's _config.yml, enable the plugin:
    plugins:
      - jekyll-google_search_console_verification_file
    
  4. Get the GSC unique code for you website.
    1. Register your website at Google Search Console
    2. From the main dashboard of your site at GSC: Settings > Ownership Verification > HTML File and download the unique file
    3. Instead of putting this file in our jekyll site, just copy the unique code from the HTML file name e.g. from googlef47733b3288357e4.html copy f47733b3288357e4.
  5. In your site's _config.yml, configure this plugin with the code from the previous step:
    google_search_console:
      verification_file_code: 47733b3288357e4
    
  6. Now just build your site and verify that the verification file now exist!
    $ bundle exec jekyll build
    $ ls _site/ | grep "google.*\.html"
    google47733b3288357e4.html
    

Development

The structure of this plugin was inspired by https://ayastreb.me/writing-a-jekyll-plugin/, the plugin jekyll-sitemap and the Bundler Gem tutorial.

After checking out the repo;

  1. Install RVM and install a supported ruby version (see .gemspec)
  2. run script/setup to install dependencies
  3. run script/test to run the tests
  4. You can also run script/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and the created tag, and push the .gem file to rubygems.org.

Local development

Following the setup at how-to-specify-local-ruby-gems-in-your-gemfile, these are the steps needed to build a jekyll site with a local clone of this plugin for local testing.

  1. Clone this repo to your machine, say at ~/src/jekyll-google_search_console_verification_file
  2. In your Jekyll project's Gemfile:
    • Remove the gem 'jekyll-google_search_console_verification_file' part
    • Add instead gem 'jekyll-google_search_console_verification_file', github: 'erikw/jekyll-google_search_console_verification_file', branch: 'main'
  3. Configure bundler to use a local path for this gem in this project:
    • $ bundle config --local local.jekyll-google_search_console_verification_file ~/src/jekyll-google_search_console_verification_file
  4. Update the project: $ bundle install
  5. Now the project will build with the local clone of this plugin when issuing e.g. bundle exec jekyll build
  6. When you're done:
  • Remove the local override with: $ bundle config --delete local.jekyll-google_search_console_verification_file
  • Optionally restore the original gem include in Gemfile or keep building from a branch in the github repo.

Releasing

Instructions for releasing on rubygems.org below. Optionally make a GitHub release after this for the pushed git tag.

Using bundler/gem_tasks rake tasks

Following instructions from bundler.io:

vi -p lib/jekyll-google_search_console_verification_file/version.rb CHANGELOG.md
bundle exec rake build
ver=$(ruby -r jekyll-google_search_console_verification_file/version -e 'puts Jekyll::GoogleSearchConsoleVerificationFile::VERSION')

# Optional: test locally by including in another project
gem install pkg/jekyll-google_search_console_verification_file-$ver.gem

bundle exec rake release

Using gem-release gem extension

Using gem-release:

vi CHANGELOG.md && git add CHANGELOG.md && git commit -m "Update CHANGELOG.md" && git push
gem bump --version minor --tag --push --release --sign

For --version, use major|minor|patch as needed.

Multi-versions

  • For ruby, just use RVM to switch between supported ruby version specified in .gemspec.
  • To run with different jekyll versions, Appraisal is used with Appraisals to generate different gemfiles/
    • To use a specific Gemfile, run like
      BUNDLE_GEMFILE=gemfiles/jekyll_4.x.x.gemfile bundle exec rake spec
      bundle exec appraisal jekyll-4.x.x rake spec
      
    • To run rake spec for all gemfiles:
      bundle exec appraisal rake spec
      
    • To generate new/updated gemfiles from Appraisals
      bundle exec appraisal install
      bundle exec appraisal generate --travis
      

Travis

To use the travis cli client (installed from Gemfile):

  1. Get a GitHub OAuth token by
  2. Set travis.com as the default so we don't need to add --pro to most commands
    bundle exec travis endpoint --set-default --api-endpoint https://api.travis-ci.com/
    
  3. Login with the cli client
    bundle exec travis login --github-token $GITHUB_TOKEN
    
  4. Now the cli client can be used (might need --pro to use travis.com)
    bundle exec travis lint
    bundle exec travis accounts
    bundle exec travis status
    bundle exec travis branches
    bundle exec travis monitor
    

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/erikw/jekyll-google_search_console_verification_file.

License

The gem is available as open source under the terms of the MIT License.

More Jekyll

Check out my other Jekyll repositories here.