Skip to content

Commit

Permalink
Merge branch 'release/2.0.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
rhukster committed Jul 9, 2020
2 parents 0bd5506 + ebcd2cb commit 4eaeaa7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# v2.0.1
## 07/09/2020

1. [](#bugfix)
* Fix for archives on homepage [#26](https://github.com/getgrav/grav-plugin-archives/issues/26)

# v2.0.0
## 04/06/2020

Expand Down
19 changes: 18 additions & 1 deletion archives.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Grav\Common\Plugin;
use Grav\Common\Page\Collection;
use Grav\Common\Taxonomy;
use Grav\Common\Uri;
use Grav\Common\Utils;
use Grav\Common\Yaml;
use RocketTheme\Toolbox\Event\Event;
Expand Down Expand Up @@ -127,7 +128,7 @@ public function onTwigSiteVariables()
if ($page && is_array($page_specific_config)) {
foreach ($page_specific_config as $page_config) {
// Does the page config match route of this current page
if (isset($page_config['route']) && Utils::startsWith($page->route(), $page_config['route'], false)) {
if (isset($page_config['route']) && $this->isValidPageRoute($page, $page_config['route'])) {
$filters = $page_config['filters'] ?? (array) $this->config->get('plugins.archives.filters');

// get around limitation of no YAML filtering support in list field
Expand Down Expand Up @@ -159,6 +160,22 @@ public function onTwigSiteVariables()
$this->grav['twig']->twig_vars['archives_url'] = $archives_url;
}

/** Something like this should be in Page object in future */
protected function isValidPageRoute(PageInterface $page, $route)
{
$uri = $this->grav['uri'];
$page_routes = [$page->route(), $page->rawRoute()];
$page_routes[] = str_replace($page->canonical(false), $uri->rootUrl(true), '');
$page_routes = array_merge($page_routes, $page->routeAliases());

foreach ($page_routes as $proute) {
if (Utils::startsWith($proute, $route, false)) {
return true;
}
}
return false;
}

protected function getArchives($filters, $operator, $order)
{
$order_by = $order['by'] ?? 'date';
Expand Down
4 changes: 3 additions & 1 deletion blueprints.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
name: Archives
version: 2.0.0
version: 2.0.1
type: plugin
slug: archives
description: The **Archives** plugin creates links for pages grouped by month/year
icon: university
author:
Expand Down

0 comments on commit 4eaeaa7

Please sign in to comment.