mep template
This commit is contained in:
@@ -0,0 +1 @@
|
||||
.idea/
|
||||
@@ -0,0 +1,68 @@
|
||||
# v1.3.2
|
||||
## 05/21/2017
|
||||
|
||||
1. [](#improved)
|
||||
* Removed Grav trait in favor of `Grav::instance()`
|
||||
|
||||
# v1.3.1
|
||||
## 11/02/2017
|
||||
|
||||
1. [](#bugfix)
|
||||
* Don't need to lowercase the taxonomy now we have removed `case_insensitive_urls` option in Grav core
|
||||
|
||||
# v1.3.0
|
||||
## 10/31/2017
|
||||
|
||||
1. [](#new)
|
||||
* Added ability to show tags of the child pages of the current page [#17](https://github.com/getgrav/grav-plugin-taxonomylist/pull/17)
|
||||
1. [](#improved)
|
||||
* Improved child-pages logic to use the same include, just pass an optional `children_only` param
|
||||
* Lowercase all tags due to changes in Grav 1.3.8 where URL params are lowercase [#18](https://github.com/getgrav/grav-plugin-taxonomylist/issues/18)
|
||||
|
||||
# v1.2.7
|
||||
## 01/06/2016
|
||||
|
||||
2. [](#improved)
|
||||
* Removed extraneous encoding
|
||||
|
||||
# v1.2.6
|
||||
## 10/07/2015
|
||||
|
||||
2. [](#improved)
|
||||
* Added `active` class on active taxonomies
|
||||
|
||||
# v1.2.5
|
||||
## 07/19/2015
|
||||
|
||||
2. [](#improved)
|
||||
* Set the taxonomy type from the taxonomy being passed in
|
||||
|
||||
# v1.2.4
|
||||
## 02/19/2015
|
||||
|
||||
2. [](#improved)
|
||||
* Implemented new `param_sep` variable from Grav 0.9.18
|
||||
|
||||
# v1.2.3
|
||||
## 02/05/2015
|
||||
|
||||
2. [](#improved)
|
||||
* Added support for HHVM
|
||||
|
||||
# v1.2.2
|
||||
## 01/09/2015
|
||||
|
||||
2. [](#improved)
|
||||
* NOTE: BREAKING CHANGE: Moved templates into `partials/` subfolder for consistency.
|
||||
|
||||
# v1.2.1
|
||||
## 01/07/2015
|
||||
|
||||
1. [](#bugfix)
|
||||
* Support for numeric taxonomy values
|
||||
|
||||
# v1.2.0
|
||||
## 11/30/2014
|
||||
|
||||
1. [](#new)
|
||||
* ChangeLog started...
|
||||
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Grav
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -0,0 +1,64 @@
|
||||
# Grav Taxonomy List Plugin
|
||||
|
||||
`Taxonomylist` is a [Grav](http://github.com/getgrav/grav) plugin that generates a list of linked tags collected throughout the site.
|
||||
|
||||

|
||||
|
||||
# Installation
|
||||
|
||||
Installing the Taxonomy List plugin can be done in one of two ways. Our GPM (Grav Package Manager) installation method enables you to quickly and easily install the plugin with a simple terminal command, while the manual method enables you to do so via a zip file.
|
||||
|
||||
## GPM Installation (Preferred)
|
||||
|
||||
The simplest way to install this plugin is via the [Grav Package Manager (GPM)](http://learn.getgrav.org/advanced/grav-gpm) through your system's Terminal (also called the command line). From the root of your Grav install type:
|
||||
|
||||
bin/gpm install taxonomylist
|
||||
|
||||
This will install the Taxonomy List plugin into your `/user/plugins` directory within Grav. Its files can be found under `/your/site/grav/user/plugins/taxonomylist`.
|
||||
|
||||
## Manual Installation
|
||||
|
||||
To install this plugin, just download the zip version of this repository and unzip it under `/your/site/grav/user/plugins`. Then, rename the folder to `taxonomylist`. You can find these files either on [GitHub](https://github.com/getgrav/grav-plugin-taxonomylist) or via [GetGrav.org](http://getgrav.org/downloads/plugins#extras).
|
||||
|
||||
You should now have all the plugin files under
|
||||
|
||||
/your/site/grav/user/plugins/taxonomylist
|
||||
|
||||
>> NOTE: This plugin is a modular component for Grav which requires [Grav](http://github.com/getgrav/grav), the [Error](https://github.com/getgrav/grav-plugin-error) and [Problems](https://github.com/getgrav/grav-plugin-problems) plugins, and a theme to be installed in order to operate.
|
||||
|
||||
# Usage
|
||||
|
||||
To use `taxonomylist` you need to set your pages header with a taxonomy category and tag:
|
||||
|
||||
```yaml
|
||||
taxonomy:
|
||||
category: blog
|
||||
tag: [tag1, tag2]
|
||||
```
|
||||
|
||||
## Simple Include
|
||||
|
||||
The plugin provides a Twig template that you need to include in your theme. Something like:
|
||||
|
||||
```twig
|
||||
{% include 'partials/taxonomylist.html.twig' with {base_url: my_url, taxonomy: 'tag'} %}
|
||||
```
|
||||
|
||||
Where `my_url` is the URL to link to where the collection can be filtered (e.g. `/blog`) and the `taxonomy` points to a specific taxonomy type to display (e.g. `tag`). This will display all tags throughout your site
|
||||
|
||||
## Child-only Include
|
||||
|
||||
You can also include pass an optional parameter that will show taxonomy for child-pages only:
|
||||
|
||||
```twig
|
||||
{% include 'partials/taxonomylist.html.twig' with {base_url: my_url, taxonomy: 'tag', children_only: true} %}
|
||||
```
|
||||
|
||||
> NOTE: If you want to see this plugin in action, have a look at our [Blog Site Skeleton](http://github.com/grav/grav-skeleton-blog-site/archive/master.zip)
|
||||
|
||||
|
||||
|
||||
# Config Defaults
|
||||
```
|
||||
route: '/blog'
|
||||
```
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 13 KiB |
@@ -0,0 +1,34 @@
|
||||
name: Taxonomy List
|
||||
version: 1.3.2
|
||||
description: "With the **TaxonomyList plugin** you can easily create list of **taxonomy** items such as **tags**, **categories**, etc."
|
||||
icon: tag
|
||||
author:
|
||||
name: Team Grav
|
||||
email: devs@getgrav.org
|
||||
url: http://getgrav.org
|
||||
homepage: https://github.com/getgrav/grav-plugin-taxonomylist
|
||||
demo: http://demo.getgrav.org/blog-skeleton
|
||||
keywords: taxonomylist, plugin, taxonomy, list, tags, categories
|
||||
bugs: https://github.com/getgrav/grav-plugin-taxonomylist/issues
|
||||
license: MIT
|
||||
|
||||
form:
|
||||
validation: strict
|
||||
fields:
|
||||
enabled:
|
||||
type: toggle
|
||||
label: Plugin status
|
||||
highlight: 1
|
||||
default: 0
|
||||
options:
|
||||
1: Enabled
|
||||
0: Disabled
|
||||
validate:
|
||||
type: bool
|
||||
|
||||
route:
|
||||
type: text
|
||||
label: Route to blog
|
||||
placeholder: /blog
|
||||
validate:
|
||||
pattern: "/([a-z\-_]+/?)+"
|
||||
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace Grav\Plugin;
|
||||
|
||||
use Grav\Common\Grav;
|
||||
|
||||
class Taxonomylist
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $taxonomylist;
|
||||
|
||||
/**
|
||||
* Get taxonomy list with all tags of the site.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get()
|
||||
{
|
||||
if (!$this->taxonomylist) {
|
||||
$this->taxonomylist = $this->build(Grav::instance()['taxonomy']->taxonomy());
|
||||
}
|
||||
return $this->taxonomylist;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get taxonomy list with only tags of the child pages.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getChildPagesTags()
|
||||
{
|
||||
$current = Grav::instance()['page'];
|
||||
$taxonomies = [];
|
||||
foreach ($current->children() as $child) {
|
||||
foreach($this->build($child->taxonomy()) as $taxonomyName => $taxonomyValue) {
|
||||
if (!isset($taxonomies[$taxonomyName])) {
|
||||
$taxonomies[$taxonomyName] = $taxonomyValue;
|
||||
} else {
|
||||
foreach ($taxonomyValue as $value => $count) {
|
||||
if (!isset($taxonomies[$taxonomyName][$value])) {
|
||||
$taxonomies[$taxonomyName][$value] = $count;
|
||||
} else {
|
||||
$taxonomies[$taxonomyName][$value] += $count;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $taxonomies;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @param array $taxonomylist
|
||||
* @return array
|
||||
*/
|
||||
protected function build(array $taxonomylist)
|
||||
{
|
||||
$cache = Grav::instance()['cache'];
|
||||
$hash = hash('md5', serialize($taxonomylist));
|
||||
$list = [];
|
||||
|
||||
if ($taxonomy = $cache->fetch($hash . 'x')) {
|
||||
return $taxonomy;
|
||||
} else {
|
||||
foreach ($taxonomylist as $taxonomyName => $taxonomyValue) {
|
||||
$partial = [];
|
||||
foreach ($taxonomyValue as $key => $value) {
|
||||
if (is_array($value)) {
|
||||
$taxonomyValue[strval($key)] = count($value);
|
||||
$partial[strval($key)] = count($value);
|
||||
} else {
|
||||
$partial[strval($value)] = 1;
|
||||
}
|
||||
}
|
||||
arsort($partial);
|
||||
$list[$taxonomyName] = $partial;
|
||||
}
|
||||
|
||||
$cache->save($hash, $list);
|
||||
|
||||
return $list;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"project":"grav-plugin-taxonomylist",
|
||||
"platforms":{
|
||||
"grav":{
|
||||
"nodes":{
|
||||
"plugin":[
|
||||
{
|
||||
"source":"/",
|
||||
"destination":"/user/plugins/taxonomylist"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
namespace Grav\Plugin;
|
||||
|
||||
use Grav\Common\Plugin;
|
||||
use Grav\Plugin\Taxonomylist;
|
||||
|
||||
class TaxonomylistPlugin extends Plugin
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public static function getSubscribedEvents()
|
||||
{
|
||||
return [
|
||||
'onPluginsInitialized' => ['onPluginsInitialized', 0]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize configuration
|
||||
*/
|
||||
public function onPluginsInitialized()
|
||||
{
|
||||
if ($this->isAdmin()) {
|
||||
$this->active = false;
|
||||
return;
|
||||
}
|
||||
|
||||
$this->enable([
|
||||
'onTwigTemplatePaths' => ['onTwigTemplatePaths', 0],
|
||||
'onTwigSiteVariables' => ['onTwigSiteVariables', 0]
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add current directory to twig lookup paths.
|
||||
*/
|
||||
public function onTwigTemplatePaths()
|
||||
{
|
||||
$this->grav['twig']->twig_paths[] = __DIR__ . '/templates';
|
||||
}
|
||||
|
||||
/**
|
||||
* Set needed variables to display the taxonomy list.
|
||||
*/
|
||||
public function onTwigSiteVariables()
|
||||
{
|
||||
require_once __DIR__ . '/classes/taxonomylist.php';
|
||||
|
||||
$twig = $this->grav['twig'];
|
||||
$twig->twig_vars['taxonomylist'] = new Taxonomylist();
|
||||
$twig->twig_vars['list_url'] = $this->config->get(
|
||||
'site.blog.route',
|
||||
$this->config->get('plugins.taxonomylist.route')
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
enabled: true
|
||||
route: '/blog'
|
||||
@@ -0,0 +1,10 @@
|
||||
{% set taxlist = children_only is defined ? taxonomylist.getChildPagesTags() : taxonomylist.get() %}
|
||||
|
||||
{% if taxlist %}
|
||||
<span class="tags">
|
||||
{% for tax,value in taxlist[taxonomy] %}
|
||||
{% set active = uri.param(taxonomy) == tax? 'active' : '' %}
|
||||
<a class="{{ active }}" href="{{ base_url }}/{{ taxonomy }}{{ config.system.param_sep }}{{ tax }}">{{ tax }}</a>
|
||||
{% endfor %}
|
||||
</span>
|
||||
{% endif %}
|
||||
Reference in New Issue
Block a user