From 931448982af982edf40ba4c93345d8e6bb8eaeae Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Wed, 8 Jul 2020 23:27:09 -0600 Subject: [PATCH 1/3] fix for archives on homepage Signed-off-by: Andy Miller --- CHANGELOG.md | 6 ++++++ archives.php | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8fdca56..bc088c8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# v2.0.1 +## mm/dd/2020 + +1. [](#bugfix) + * Fix for archives on homepage [#26](https://github.com/getgrav/grav-plugin-archives/issues/26) + # v2.0.0 ## 04/06/2020 diff --git a/archives.php b/archives.php index 9a7e1f4..7dfaa81 100644 --- a/archives.php +++ b/archives.php @@ -127,7 +127,9 @@ 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']) && + (Utils::startsWith($page->route(), $page_config['route'], false) || + Utils::startsWith($page->rawRoute(), $page_config['route'], false))) { $filters = $page_config['filters'] ?? (array) $this->config->get('plugins.archives.filters'); // get around limitation of no YAML filtering support in list field From 8c21c8b7a3f2f634b6f088e9846dae20a38d3895 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Thu, 9 Jul 2020 10:21:45 -0600 Subject: [PATCH 2/3] more robust route matching Signed-off-by: Andy Miller --- archives.php | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/archives.php b/archives.php index 7dfaa81..49f1ae4 100644 --- a/archives.php +++ b/archives.php @@ -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; @@ -127,9 +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) || - Utils::startsWith($page->rawRoute(), $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 @@ -161,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'; From ebcd2cba777ec51b72c5b126104d90da270097ab Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Thu, 9 Jul 2020 10:22:28 -0600 Subject: [PATCH 3/3] prepare for release Signed-off-by: Andy Miller --- CHANGELOG.md | 2 +- blueprints.yaml | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bc088c8..91ceaf6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,5 @@ # v2.0.1 -## mm/dd/2020 +## 07/09/2020 1. [](#bugfix) * Fix for archives on homepage [#26](https://github.com/getgrav/grav-plugin-archives/issues/26) diff --git a/blueprints.yaml b/blueprints.yaml index 591c034..2d3adc0 100644 --- a/blueprints.yaml +++ b/blueprints.yaml @@ -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: