From e764af5f707faaef0173d48ea830b90966abb8e2 Mon Sep 17 00:00:00 2001 From: Nicholas Krebs Date: Thu, 13 Jun 2024 17:25:14 +0200 Subject: [PATCH 1/4] Add option to set a custom `lastmod` date (#113) * add to blueprint * use header.sitemap.lastmod if set * refactor * make option toggleable * fix from code review --- blueprints/sitemap.yaml | 5 +++++ languages.yaml | 1 + sitemap.php | 3 ++- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/blueprints/sitemap.yaml b/blueprints/sitemap.yaml index b414ac6..5e56da4 100644 --- a/blueprints/sitemap.yaml +++ b/blueprints/sitemap.yaml @@ -25,6 +25,11 @@ form: type: bool required: false + header.sitemap.lastmod: + type: datetime + label: PLUGIN_SITEMAP.HEADER_LASTMOD + default: '' + header.sitemap.changefreq: type: select label: PLUGIN_SITEMAP.HEADER_CHANGEFREQ diff --git a/languages.yaml b/languages.yaml index 4b205b5..87e047b 100644 --- a/languages.yaml +++ b/languages.yaml @@ -2,6 +2,7 @@ en: PLUGIN_SITEMAP: SITEMAP: 'Sitemap' HEADER_IGNORE: 'Sitemap ignore page' + HEADER_LASTMOD: 'Sitemap Last Modified' HEADER_CHANGEFREQ: 'Sitemap Change Frequency' HEADER_PRIORITY: 'Sitemap priority' CHANGEFREQ: 'Global - Sitemap Change Frequency' diff --git a/sitemap.php b/sitemap.php index 0597080..a90d050 100644 --- a/sitemap.php +++ b/sitemap.php @@ -310,6 +310,7 @@ protected function addRouteData($pages, $lang) $include_lang = $this->multilang_skiplang_prefix !== $lang; $location = $page->canonical($include_lang); $url = $page->url(false, $include_lang); + $lastmod = !empty($header->sitemap['lastmod']) ? strtotime($header->sitemap['lastmod']) : $page->modified(); $lang_route = [ 'title' => $page->title(), @@ -318,7 +319,7 @@ protected function addRouteData($pages, $lang) 'lang' => $lang, 'translated' => in_array($lang, $page_languages), 'location' => $location, - 'lastmod' => date($this->datetime_format, $page->modified()), + 'lastmod' => date($this->datetime_format, $lastmod), 'longdate' => date('Y-m-d\TH:i:sP', $page->date()), 'shortdate' => date('Y-m-d', $page->date()), 'timestamp' => $page->date(), From 03968b2ec538eca5c6d634fa1200beda02e1cbc2 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Mon, 17 Jun 2024 11:49:59 -0600 Subject: [PATCH 2/4] updatded readme --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index 1213951..a7f1fa0 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,17 @@ sitemap: ignore: true ``` +## Overrides + +You can override several elements of the sitemap entry for the page in the page's header. For example, as well as `ignore` mentioned above, these are available: + +```yaml +sitemap: + lastmod: # e.g. '2024-04-17' + changefreq: # always| hourly | daily: | weekly | monthly | yearly | never + priority: # 0.1 -> 1.0 +``` + ## Multi-Language Support The latest Sitemap `v3.0` includes all new multi-language support utilizing the latest [Google Search SEO Recomendations](https://developers.google.com/search/docs/advanced/crawling/localized-versions?hl=en&visit_id=637468720624267418-280936473&rd=2) which creates bi-directional `hreflang` entries for each language available. @@ -98,6 +109,7 @@ https://yoursite.com/blog/sitemap-news.xml You can change the "News Path" to be something other than `sitemap-news.xml` if you wish. + ## Images You can add images to the sitemap by adding an entry in the page's Frontmatter. From 68bd8f08ac5a4970e9c1c912753a9637c6ac1160 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Mon, 17 Jun 2024 11:51:38 -0600 Subject: [PATCH 3/4] updated changelog --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 92009a0..b8179d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +# v5.1.0 +## 06/17/24 + +1. [](#new) + * Added page-level `lastmod` options [#113](https://github.com/getgrav/grav-plugin-sitemap/pull/113) +1. [](#improved) + * Updated README.md with page override options. + # v5.0.0 ## 10/05/2023 From 3384ad31560160527e1d852cdab36d93344ead2e Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Mon, 17 Jun 2024 11:51:57 -0600 Subject: [PATCH 4/4] prepaer for release --- blueprints.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/blueprints.yaml b/blueprints.yaml index fdf37b3..7e3d846 100644 --- a/blueprints.yaml +++ b/blueprints.yaml @@ -1,7 +1,7 @@ name: Sitemap type: plugin slug: sitemap -version: 5.0.0 +version: 5.1.0 description: "Provide automatically generated **XML sitemaps** with this very useful, as a simple to configure Grav plugin." icon: map-marker author: