Three New Plugins Released

More new plugins available...

3 mins

Along with our new 0.9.0 release, we have also released three new plugins. The Archives plugin is used for displaying a list of months that can filter pages based on taxonomy. The GitHub plugin provides an easy way to access the GitHub API from Grav, either directly in plugins or in Twig templates. TwigCache is a plugin for advanced users that are trying to include slow requests or processing in their Twig template output.

Archives Plugin

We use this new Archives plugin right here on getgrav.org. Prior to this plugin, we used a Twig template to create a simple HTML list of months, starting with the current month and working backwards for twelve months. Then the links were generated with the month as a taxonomy type. This taxonomy had to be manually added to each page.

This worked, but was far from ideal. If there were no blog posts for a particular month, clicking on that month could potentially find no matching pages resulting in a blank page. You had to manually set this taxonomy on the page.

The new Archives plugin fixes these shortcomings.

  1. When Grav initially processes each page, it uses the onPageProcessed event to automatically insert the appropriate taxonomy for the month and year. This is only done the first time the page is processed. It doesn't run again after the page is cached.

  2. It uses Grav's Taxonomy to gather up a list of pages that match the filter you configure, for example: all blog posts, and then builds an archives array that contains the months which have posts, and counts of the number of posts available.

  3. It makes this archives array available to Twig, so that the built-in partials/archives.html.twig template can be easily included in your template's sidebar or wherever else you need it.

GitHub Plugin

This plugin allows Grav to easily interact with the GitHub API to easily get information concerning your GitHub repositories and projects. We developed this plugin to easily allow us to get statistics and information for all our getgrav repos, and decided that others may benefit so we made it available for all.

An example of how you could use this plugin is provided as a Twig template in the plugin itself:

Grav Repository has: <b>{{ github.client.api('repo').show('getgrav', 'grav')['stargazers_count'] }}</b> stargazers

As you can see, it's pretty simple to use and quite powerful.

TwigCache Plugin

One thing that became apparent as we were writing our GitHub plugin, was that compared to Grav itself, making an API call to GitHub to get some information was crazy slow! When Grav is running in 10ms or less, a 500ms call feels like an incredible slow down. To tackle this, we created a simple plugin using the Twig-Cache-Extension available on GitHub.

We implemented it utilizing the same cache configuration as Grav uses. So if you have APC installed, and Grav is using that, the Twig Cache plugin will too. We have supported the lifetime cache strategy so you can provide a time (in seconds) that the calls between the tags should be cached for.

For example: the following include that makes a GitHub API call will be cached for 10 minutes before it refreshes:

{% cache 'github_api' 600 %}
    {% include 'github.html.twig' %}
{% endcache %}
Grav Premium
Turbo-charge your Grav site - from the creators of Grav