This repository has been archived by the owner on Jun 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a3890f5
Showing
8 changed files
with
274 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# v0.1.0 | ||
## 08/31/2016 | ||
|
||
1. [](#new) | ||
* ChangeLog started... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2016 Aaron Dalton | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# Grav Tag Cloud Plugin | ||
|
||
The **Tagcloud** Plugin is for [Grav CMS](http://github.com/getgrav/grav). It creates a rudimentary tag cloud that can be easily styled to fit your needs. | ||
|
||
# Installation | ||
|
||
Installing the Tag Cloud plugin can be done in one of two ways. The 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 tagcloud | ||
|
||
This will install the Tag Cloud plugin into your `/user/plugins` directory within Grav. Its files can be found under `/your/site/grav/user/plugins/tagcloud`. | ||
|
||
## 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 `tagcloud`. 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/tagcloud | ||
|
||
>> 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), [Problems](https://github.com/getgrav/grav-plugin-problems) and [Taxonomy List](https://github.com/getgrav/grav-plugin-taxonomylist) plugins, and a theme to be installed in order to operate. | ||
# Usage | ||
|
||
To use `tagcloud` you need to set your pages header with at least a taxonomy tag: | ||
|
||
``` | ||
taxonomy: | ||
tag: [tag1, tag2] | ||
``` | ||
|
||
You will also need to do the following: | ||
|
||
- Copy the `tagcloud.html.twig` file from the plugin folder to your theme and adjust as you see fit. | ||
- `include` the twig file somewhere in your theme skeleton (usually in `sidebar.html.twig`) along the following lines: | ||
``` | ||
{% if config.plugins.tagcloud.enabled %} | ||
<aside class="widget widget_meta"> | ||
<h2 class="widget-title">{{config.plugins.tagcloud.title|t}}</h2> | ||
{% include 'partials/tagcloud.html.twig' %} | ||
</aside> | ||
{% endif %} | ||
``` | ||
- Copy the contents of the CSS in the `assets` folder of the plugin into your theme and adjust as you see fit. | ||
> Remember that the plugin `taxonomylist` must be installed and enabled! | ||
I recognize that you can configure the PHP file to use the files in the plugin folder, but I can't imagine someone using these files as is. If I'm wrong, let me know and I'll go the PHP file route. | ||
# Config Defaults | ||
``` | ||
enabled: true | ||
threshold: 0 | ||
title: "POPULAR TAGS" | ||
``` | ||
The fields `enabled` and `title` are self-explanatory, but `threshold` takes a little explaining. The tags are sized based on how frequently they appear. This is done by first determining the number of times the *most* frequent tag appears (`max`) and then comparing each tag's count (`count`) against it, forming a percentage: `percent = (count/max) * 100`. | ||
That `percent` number is then compared against the different tiers in the twig file to determine how it should be sized. The `threshold` in the config determines the minimum `percent` a tag must be to even be displayed. A value of 0 shows all tags. A value of 100 only shows the tags whose `counts` equal the `max`. Any value between that will show some subset of your tags. You'll need to do some trial and error to find the right number. It really depends on how many different tags your blog uses. | ||
# Support | ||
This is my very first Grav plugin. I welcome any feedback and pull requests. | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#tagcloud { | ||
width: 100%; /*300px;*/ | ||
/*background:#CFE3FF;*/ | ||
/*color:#0066FF;*/ | ||
padding: 10px; | ||
padding-top: 0px; | ||
border: 1px solid rgba(51, 51, 51, 0.0980392); /*#559DFF;*/ | ||
text-align:center; | ||
-moz-border-radius: 4px; | ||
-webkit-border-radius: 4px; | ||
border-radius: 4px; | ||
} | ||
|
||
#tagcloud a:link, #tagcloud a:visited { | ||
text-decoration:none; | ||
color: #333; | ||
} | ||
|
||
#tagcloud a:hover { | ||
text-decoration: underline; | ||
} | ||
|
||
#tagcloud span { | ||
padding: 4px; | ||
} | ||
|
||
#tagcloud .smallest { | ||
font-size: x-small; | ||
} | ||
|
||
#tagcloud .small { | ||
font-size: small; | ||
} | ||
|
||
#tagcloud .medium { | ||
font-size:medium; | ||
} | ||
|
||
#tagcloud .large { | ||
font-size:large; | ||
} | ||
|
||
#tagcloud .largest { | ||
font-size:x-large; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
name: Tagcloud | ||
version: 0.1.0 | ||
description: Create a simple tag cloud | ||
icon: plug | ||
author: | ||
name: Aaron Dalton | ||
email: [email protected] | ||
homepage: https://github.com/Perlkonig/grav-plugin-tagcloud | ||
demo: http://perlkonig.com | ||
keywords: grav, plugin, etc | ||
bugs: https://github.com/Perlkonig/grav-plugin-tagcloud/issues | ||
readme: https://github.com/Perlkonig/grav-plugin-tagcloud/blob/develop/README.md | ||
license: MIT | ||
|
||
dependencies: | ||
- taxonomylist | ||
|
||
form: | ||
validation: strict | ||
fields: | ||
enabled: | ||
type: toggle | ||
label: Plugin status | ||
highlight: 1 | ||
default: 0 | ||
options: | ||
1: Enabled | ||
0: Disabled | ||
validate: | ||
type: bool | ||
title: | ||
type: text | ||
label: Cloud title | ||
help: Appears above the cloud | ||
threshold: | ||
type: text | ||
label: Threshold | ||
help: A number between 0 and 100. The default (0) includes all tags. Any other number will drop tags from the cloud. A value of 100 will only show the most popular tag (or tags, if there are ties). See the documentation for an explanation of how this works. You'll have to do some trial and error to figure it out for your specific taxonomy. | ||
validate: | ||
type: int | ||
min: 0 | ||
max: 100 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
namespace Grav\Plugin; | ||
|
||
use Grav\Common\Plugin; | ||
use RocketTheme\Toolbox\Event\Event; | ||
|
||
/** | ||
* Class TagcloudPlugin | ||
* @package Grav\Plugin | ||
*/ | ||
class TagcloudPlugin extends Plugin | ||
{ | ||
/** | ||
* @return array | ||
* | ||
* The getSubscribedEvents() gives the core a list of events | ||
* that the plugin wants to listen to. The key of each | ||
* array section is the event that the plugin listens to | ||
* and the value (in the form of an array) contains the | ||
* callable (or function) as well as the priority. The | ||
* higher the number the higher the priority. | ||
*/ | ||
public static function getSubscribedEvents() | ||
{ | ||
return [ | ||
'onPluginsInitialized' => ['onPluginsInitialized', 0] | ||
]; | ||
} | ||
|
||
/** | ||
* Initialize the plugin | ||
*/ | ||
public function onPluginsInitialized() | ||
{ | ||
// Don't proceed if we are in the admin plugin | ||
if ($this->isAdmin()) { | ||
return; | ||
} | ||
|
||
// Enable the main event we are interested in | ||
$this->enable([ | ||
'onPageContentRaw' => ['onPageContentRaw', 0] | ||
]); | ||
} | ||
|
||
/** | ||
* Do some work for this event, full details of events can be found | ||
* on the learn site: http://learn.getgrav.org/plugins/event-hooks | ||
* | ||
* @param Event $e | ||
*/ | ||
public function onPageContentRaw(Event $e) | ||
{ | ||
// Get a variable from the plugin configuration | ||
$text = $this->grav['config']->get('plugins.tagcloud.text_var'); | ||
|
||
// Get the current raw content | ||
$content = $e['page']->getRawContent(); | ||
|
||
// Prepend the output with the custom text and set back on the page | ||
$e['page']->setRawContent($text . "\n\n" . $content); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
enabled: true | ||
threshold: 0 | ||
title: "POPULAR TAGS" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{% set taxlist = taxonomylist.get() %} | ||
|
||
{% if taxlist %} | ||
{% set max = max(taxlist['tag']) %} | ||
{% set threshold = 0 %} | ||
{% if config.plugins.tagcloud.threshold is defined %} | ||
{% set threshold = config.plugins.tagcloud.threshold %} | ||
{% endif %} | ||
<div id="tagcloud"> | ||
{% for tax,value in taxlist['tag']|ksort %} | ||
{% set percent = (value / max) * 100 %} | ||
{% set class = 'largest' %} | ||
{% if percent < 20 %} | ||
{% set class = 'smallest' %} | ||
{% elseif percent >= 20 and percent < 40 %} | ||
{% set class = 'small' %} | ||
{% elseif percent >= 40 and percent < 60 %} | ||
{% set class = 'medium' %} | ||
{% elseif percent >= 50 and percent < 80 %} | ||
{% set class = 'large' %} | ||
{% endif %} | ||
{% if percent > threshold %} | ||
<span class="{{ class }}" title="{{ value }} posts"><a href="{{ base_url }}/tag{{ config.system.param_sep }}{{ tax|e('url') }}">{{ tax }}</a></span> | ||
{% endif %} | ||
{% endfor %} | ||
</div> | ||
{% endif %} |