From 611c32fa04229eaeb0ab9514337d158f83a488db Mon Sep 17 00:00:00 2001 From: Nick Hayward Date: Wed, 12 Apr 2017 09:32:40 -0400 Subject: [PATCH 01/10] re-implementing wildcard ignore with updated README and YAML defaults (#34) --- README.md | 1 + sitemap.php | 2 +- sitemap.yaml | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5b71889..b1b08c8 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,7 @@ route: '/sitemap' ignores: - /blog/blog-post-to-ignore - /ignore-this-route + - /ignore-children-of-this-route/.* ``` You can ignore your own pages by providing a list of routes to ignore. diff --git a/sitemap.php b/sitemap.php index 620cc72..6ceef60 100644 --- a/sitemap.php +++ b/sitemap.php @@ -68,7 +68,7 @@ public function onPagesInitialized() foreach ($routes as $route => $path) { $page = $pages->get($path); - if ($page->published() && $page->routable() && !in_array($page->route(), $ignores)) { + if ($page->published() && $page->routable() && !preg_match(sprintf("@^(%s)$@i", implode('|', $ignores)), $page->route())) { $entry = new SitemapEntry(); $entry->location = $page->canonical(); $entry->lastmod = date('Y-m-d', $page->modified()); diff --git a/sitemap.yaml b/sitemap.yaml index def0b0c..fa26f5b 100644 --- a/sitemap.yaml +++ b/sitemap.yaml @@ -5,3 +5,4 @@ priority: !!float 1 ignores: - /blog/blog-post-to-ignore - /ignore-this-route + - /ignore-children-of-this-route/.* From a792362477080bbffdbb8a5fa76856b42cabe8ec Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Wed, 12 Apr 2017 15:34:15 +0200 Subject: [PATCH 02/10] Changelog --- CHANGELOG.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d6df5a0..c238a3b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# v1.9.0 +## 03/14/2017 + +1. [](#new) + * Added wildcard ignores [#34](https://github.com/getgrav/grav-plugin-sitemap/pull/34) + # v1.8.0 ## 03/14/2017 @@ -59,7 +65,7 @@ 1. [](#improved) * Added blueprints for Grav Admin plugin -1. [](#bugfix) +1. [](#bugfix) * Don't show unpublished pages in sitemap # v1.3.0 From b522ff68452133372d2071edaa0f638e4af68686 Mon Sep 17 00:00:00 2001 From: Shikiryu Date: Wed, 12 Apr 2017 15:35:10 +0200 Subject: [PATCH 03/10] Added ability to add non-grav URL to sitemap (#35) --- sitemap.php | 11 +++++++++++ sitemap.yaml | 5 +++++ 2 files changed, 16 insertions(+) diff --git a/sitemap.php b/sitemap.php index 6ceef60..8068a54 100644 --- a/sitemap.php +++ b/sitemap.php @@ -81,6 +81,17 @@ public function onPagesInitialized() $this->sitemap[$route] = $entry; } } + + $rootUrl = $this->grav['uri']->rootUrl(true) . $pages->base(); + $additions = (array) $this->config->get('plugins.sitemap.additions'); + + foreach ($additions as $addition) { + $entry = new SitemapEntry(); + $entry->location = $rootUrl . $addition['location']; + $entry->lastmod = $addition['lastmod']; + + $this->sitemap[] = $entry; + } } public function onPageInitialized() diff --git a/sitemap.yaml b/sitemap.yaml index fa26f5b..0802150 100644 --- a/sitemap.yaml +++ b/sitemap.yaml @@ -6,3 +6,8 @@ ignores: - /blog/blog-post-to-ignore - /ignore-this-route - /ignore-children-of-this-route/.* + +additions: + - + location: /not-a-grav-url + lastmod: '2017-04-06' From 6f219b5bff79d6b7024b4d8860d782579abf63fa Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Wed, 12 Apr 2017 15:35:52 +0200 Subject: [PATCH 04/10] Changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c238a3b..ea06527 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ 1. [](#new) * Added wildcard ignores [#34](https://github.com/getgrav/grav-plugin-sitemap/pull/34) + * Added ability to add external URLs to sitemap [#35](https://github.com/getgrav/grav-plugin-sitemap/pull/35) # v1.8.0 ## 03/14/2017 From f40c4c0fa29f5b4b9c0b4f92c5cd096142b3e3e0 Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Wed, 12 Apr 2017 15:36:04 +0200 Subject: [PATCH 05/10] Fix date --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ea06527..93d51b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,5 @@ # v1.9.0 -## 03/14/2017 +## 04/xx/2017 1. [](#new) * Added wildcard ignores [#34](https://github.com/getgrav/grav-plugin-sitemap/pull/34) From 99586188867d396c573ce64187df6b224a4560d5 Mon Sep 17 00:00:00 2001 From: Nick Hayward Date: Fri, 14 Apr 2017 10:11:50 -0400 Subject: [PATCH 06/10] page-level sitemap ignore (#37) * re-implementing wildcard ignore with updated README and YAML defaults * adding ability to ignore a page in it's frontmatter --- README.md | 7 ++++++- sitemap.php | 5 +++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b1b08c8..edd3c27 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,12 @@ ignores: - /ignore-children-of-this-route/.* ``` -You can ignore your own pages by providing a list of routes to ignore. +You can ignore your own pages by providing a list of routes to ignore. You can also use a page's Frontmatter to signal that the sitemap should ignore it: + +``` +sitemap: + ignore: true +``` ## Only allow access to the .xml file diff --git a/sitemap.php b/sitemap.php index 8068a54..0ee33ff 100644 --- a/sitemap.php +++ b/sitemap.php @@ -67,14 +67,15 @@ public function onPagesInitialized() foreach ($routes as $route => $path) { $page = $pages->get($path); + $header = $page->header(); + $page_ignored = isset($header->sitemap['ignore']) ? $header->sitemap['ignore'] : false; - if ($page->published() && $page->routable() && !preg_match(sprintf("@^(%s)$@i", implode('|', $ignores)), $page->route())) { + if ($page->published() && $page->routable() && !preg_match(sprintf("@^(%s)$@i", implode('|', $ignores)), $page->route()) && !$page_ignored) { $entry = new SitemapEntry(); $entry->location = $page->canonical(); $entry->lastmod = date('Y-m-d', $page->modified()); // optional changefreq & priority that you can set in the page header - $header = $page->header(); $entry->changefreq = (isset($header->sitemap['changefreq'])) ? $header->sitemap['changefreq'] : $this->config->get('plugins.sitemap.changefreq'); $entry->priority = (isset($header->sitemap['priority'])) ? $header->sitemap['priority'] : $this->config->get('plugins.sitemap.priority'); From 307a7a65a8a75c29312cf61fb75efc68afdea970 Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Fri, 14 Apr 2017 16:12:42 +0200 Subject: [PATCH 07/10] Add multilanguage support in sitemap #25 (#36) --- sitemap.php | 13 +++++++++++++ templates/sitemap.xml.twig | 29 +++++++++++++++++------------ 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/sitemap.php b/sitemap.php index 0ee33ff..2f4ad15 100644 --- a/sitemap.php +++ b/sitemap.php @@ -79,6 +79,19 @@ public function onPagesInitialized() $entry->changefreq = (isset($header->sitemap['changefreq'])) ? $header->sitemap['changefreq'] : $this->config->get('plugins.sitemap.changefreq'); $entry->priority = (isset($header->sitemap['priority'])) ? $header->sitemap['priority'] : $this->config->get('plugins.sitemap.priority'); + if (count($this->config->get('system.languages.supported', [])) > 0) { + $entry->translated = $page->translatedLanguages(); + + foreach($entry->translated as $lang => $page_route) { + $page_route = $page->rawRoute(); + if ($page->home()) { + $page_route = '/'; + } + + $entry->translated[$lang] = $page_route; + } + } + $this->sitemap[$route] = $entry; } } diff --git a/templates/sitemap.xml.twig b/templates/sitemap.xml.twig index e187420..1311e07 100644 --- a/templates/sitemap.xml.twig +++ b/templates/sitemap.xml.twig @@ -1,16 +1,21 @@ - {% for entry in sitemap %} - - {{ entry.location|e }} - {{ entry.lastmod }} - {% if entry.changefreq %} - {{ entry.changefreq }} - {% endif %} - {% if entry.priority %} - {{ entry.priority|number_format(1) }} - {% endif %} - - {% endfor %} +{% for entry in sitemap %} + + {{ entry.location|e }} +{% if entry.translated %} +{% for language, page_route in entry.translated %} + +{% endfor %} +{% endif %} + {{ entry.lastmod }} +{% if entry.changefreq %} + {{ entry.changefreq }} +{% endif %} +{% if entry.priority %} + {{ entry.priority|number_format(1) }} +{% endif %} + +{% endfor %} From 23ea0cf07ad42dbbb25b07f221bd05b53ee2dbc4 Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Fri, 14 Apr 2017 16:13:54 +0200 Subject: [PATCH 08/10] Changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 93d51b8..e5c26aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ 1. [](#new) * Added wildcard ignores [#34](https://github.com/getgrav/grav-plugin-sitemap/pull/34) * Added ability to add external URLs to sitemap [#35](https://github.com/getgrav/grav-plugin-sitemap/pull/35) + * Added page-level ignores [#37](https://github.com/getgrav/grav-plugin-sitemap/pull/37) + * Added multilanguage support [#36](https://github.com/getgrav/grav-plugin-sitemap/pull/36) # v1.8.0 ## 03/14/2017 From 05b88f3701c40b062824ac2f326627267e697164 Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Wed, 19 Apr 2017 13:23:00 +0200 Subject: [PATCH 09/10] Remove default config for `additions`, add to README and to blueprint --- README.md | 16 ++++++++++++++-- blueprints.yaml | 15 +++++++++++++++ sitemap.yaml | 9 --------- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index edd3c27..b7827a3 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ # Installation -Installing the Sitemap 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. +Installing the Sitemap 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) @@ -29,7 +29,7 @@ You should now have all the plugin files under The `sitemap` plugin works out of the box. You can just go directly to `http://yoursite.com/sitemap` and you will see the generated `XML`. -# Config Defaults +## Config Defaults ``` enabled: true @@ -52,3 +52,15 @@ sitemap: If you want your sitemap to only be accessible via `sitemap.xml` for example, set the route to `/sitemap` and add this to your `.htaccess` file: `Redirect 301 /sitemap /sitemap.xml` + + +## Manually add pages to the sitemap + +You can manually add URLs to the sitemap using the Admin settings, or by adding entries to your `sitemap.yaml` with this format: + +``` +additions: + - + location: /not-a-grav-url + lastmod: '2017-04-06' +``` \ No newline at end of file diff --git a/blueprints.yaml b/blueprints.yaml index 03b75d9..f7808c0 100644 --- a/blueprints.yaml +++ b/blueprints.yaml @@ -41,3 +41,18 @@ form: help: "URLs to ignore" value_only: true placeholder_value: /ignore-this-route + + additions: + type: list + label: Additional URLs + help: "Add external URLs to the sitemap" + + fields: + .location: + type: text + label: The URL location + placeholder: "/not-a-grav-url" + .lastmod: + type: text + label: "Last modification e.g. 2017-04-06" + placeholder: "2017-04-06" diff --git a/sitemap.yaml b/sitemap.yaml index 0802150..c876c7f 100644 --- a/sitemap.yaml +++ b/sitemap.yaml @@ -2,12 +2,3 @@ enabled: true route: '/sitemap' changefreq: daily priority: !!float 1 -ignores: - - /blog/blog-post-to-ignore - - /ignore-this-route - - /ignore-children-of-this-route/.* - -additions: - - - location: /not-a-grav-url - lastmod: '2017-04-06' From 2736bafea3671f004ac42c1aeeb8c7d560f5641f Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Wed, 19 Apr 2017 15:36:43 -0600 Subject: [PATCH 10/10] prepare for release --- CHANGELOG.md | 2 +- blueprints.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e5c26aa..42ea276 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,5 @@ # v1.9.0 -## 04/xx/2017 +## 04/19/2017 1. [](#new) * Added wildcard ignores [#34](https://github.com/getgrav/grav-plugin-sitemap/pull/34) diff --git a/blueprints.yaml b/blueprints.yaml index f7808c0..5dbc695 100644 --- a/blueprints.yaml +++ b/blueprints.yaml @@ -1,5 +1,5 @@ name: Sitemap -version: 1.8.0 +version: 1.9.0 description: "Provide automatically generated **XML sitemaps** with this very useful, but simple to configure, Grav plugin." icon: map-marker author: