Skip to content

Commit

Permalink
Merge branch 'release/1.6.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
rhukster committed Feb 24, 2020
2 parents ddbd22d + 996ea5c commit 6d85913
Show file tree
Hide file tree
Showing 15 changed files with 668 additions and 11 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# v1.6.1
## 2/24/2020

1. [](#new)
* Pass phpstan level 1 tests
* Require Grav v.1.6
1. [](#bugfix)
* Exclude empty folders from archive
* Fixed issue in 1.7 due to `validation: strict` and missing `taxonomy_names` blueprint item

# v1.6.0
## 04/17/2019

Expand Down
34 changes: 26 additions & 8 deletions archives.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<?php
namespace Grav\Plugin;

use Composer\Autoload\ClassLoader;
use Grav\Common\Page\Interfaces\PageInterface;
use Grav\Common\Plugin;
use Grav\Common\Grav;
use Grav\Common\Page\Collection;
use Grav\Common\Page\Page;
use Grav\Common\Debugger;
use Grav\Common\Taxonomy;
use RocketTheme\Toolbox\Event\Event;

Expand All @@ -27,10 +26,23 @@ class ArchivesPlugin extends Plugin
public static function getSubscribedEvents()
{
return [
'onPluginsInitialized' => ['onPluginsInitialized', 0]
'onPluginsInitialized' => [
['autoload', 100001],
['onPluginsInitialized', 0]
]
];
}

/**
* [onPluginsInitialized:100000] Composer autoload.
*
* @return ClassLoader
*/
public function autoload()
{
return require __DIR__ . '/vendor/autoload.php';
}

/**
* Initialize configuration
*/
Expand Down Expand Up @@ -70,8 +82,12 @@ public function onTwigTemplatePaths()
*/
public function onPageProcessed(Event $event)
{
// Get the page header
/** @var PageInterface $page */
$page = $event['page'];
if (!$page->isPage()) {
return;
}

$taxonomy = $page->taxonomy();

// track month taxonomy in "jan_2015" format:
Expand All @@ -93,7 +109,9 @@ public function onPageProcessed(Event $event)
*/
public function onTwigSiteVariables()
{
/** @var PageInterface $page */
$page = $this->grav['page'];

// If a page exists merge the configs
if ($page) {
$this->config->set('plugins.archives', $this->mergeConfig($page));
Expand All @@ -109,15 +127,15 @@ public function onTwigSiteVariables()
// Get current datetime
$start_date = time();

$archives = array();
$archives = [];

// get the plugin filters setting
$filters = (array) $this->config->get('plugins.archives.filters');
$operator = $this->config->get('plugins.archives.filter_combinator');
$new_approach = false;
$collection = null;

if ( ! $filters || (count($filters) == 1 && !reset($filters))){
if (!$filters || (count($filters) === 1 && !reset($filters))){
$collection = $pages->all();
} else {
foreach ($filters as $key => $filter) {
Expand Down Expand Up @@ -160,7 +178,7 @@ public function onTwigSiteVariables()
}

// slice the array to the limit you want
$archives = array_slice($archives, 0, intval($this->config->get('plugins.archives.limit')), is_string(reset($archives)) ? false : true );
$archives = array_slice($archives, 0, (int)$this->config->get('plugins.archives.limit'), is_string(reset($archives)) ? false : true );

// add the archives_start date to the twig variables
$this->grav['twig']->twig_vars['archives_show_count'] = $this->config->get('plugins.archives.show_count');
Expand Down
1 change: 0 additions & 1 deletion archives.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,3 @@ filters:
taxonomy_names:
month: archives_month
year: archives_year

11 changes: 9 additions & 2 deletions blueprints.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Archives
version: 1.6.0
version: 1.6.1
description: The **Archives** plugin creates links for pages grouped by month/year
icon: university
author:
Expand All @@ -11,9 +11,10 @@ demo: http://demo.getgrav.org/blog-skeleton
keywords: archives, plugin, blog, month, year, date, navigation, history
bugs: https://github.com/getgrav/grav-plugin-archives/issues
license: MIT
dependencies:
- { name: grav, version: '>=1.6.0' }

form:
validation: strict
fields:
enabled:
type: toggle
Expand Down Expand Up @@ -106,3 +107,9 @@ form:
options:
and: And - Boolean &&
or: Or - Boolean ||

taxonomy_names:
type: array
label: Taxonomy Names
placeholder_key: e.g. month
placeholder_value: e.g. archives_month
27 changes: 27 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "grav-plugin-archives",
"type": "grav-plugin",
"description": "Archives plugin for Grav CMS",
"keywords": ["archives"],
"homepage": "https://github.com/getgrav/grav-plugin-archives",
"license": "MIT",
"authors": [
{
"name": "Team Grav",
"email": "[email protected]",
"homepage": "http://getgrav.org",
"role": "Developer"
}
],
"require": {
"php": ">=7.1.3"
},
"autoload": {
"classmap": ["archives.php"]
},
"config": {
"platform": {
"php": "7.1.3"
}
}
}
22 changes: 22 additions & 0 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions vendor/autoload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

// autoload.php @generated by Composer

require_once __DIR__ . '/composer/autoload_real.php';

return ComposerAutoloaderInit6a19f37247b1cd77a801d32450df2931::getLoader();
Loading

0 comments on commit 6d85913

Please sign in to comment.