From e61aeb7288f90281bb7e42cbafd007686b540ddc Mon Sep 17 00:00:00 2001 From: Robert Bak Date: Thu, 1 Sep 2022 22:22:58 +0200 Subject: [PATCH 1/7] Update README.md (#105) Add a missing event name to README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e59b778..26ede8b 100644 --- a/README.md +++ b/README.md @@ -122,7 +122,7 @@ Note that Regex support is available: Just append `.*` to a path to ignore all o If you have some dynamic content being added to your site via another plugin, or perhaps a 3rd party API, you can now add them dynamically to the sitemap with a simple event: -Make sure you are subscribed to the `` event then add simply add your entry to the sitemap like this: +Make sure you are subscribed to the `onSitemapProcessed` event then add simply add your entry to the sitemap like this: ```php public function onSitemapProcessed(\RocketTheme\Toolbox\Event\Event $e) From c6731138a9564d572bc4627514d519567f048b9d Mon Sep 17 00:00:00 2001 From: Rotzbua Date: Fri, 22 Sep 2023 21:07:44 +0200 Subject: [PATCH 2/7] Add `yaml` highlighting (#101) Change links to https --- README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 26ede8b..0be338b 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Grav Sitemap Plugin -`Sitemap` is a [Grav](http://github.com/getgrav/grav) Plugin that generates a [map of your pages](http://en.wikipedia.org/wiki/Site_map) in `XML` format that is easily understandable and indexable by Search engines. +`Sitemap` is a [Grav](https://github.com/getgrav/grav) Plugin that generates a [map of your pages](https://en.wikipedia.org/wiki/Site_map) in `XML` format that is easily understandable and indexable by Search engines. # Installation @@ -8,7 +8,7 @@ Installing the Sitemap plugin can be done in one of two ways. Our GPM (Grav Pack ## GPM Installation (Preferred) -The simplest way to install this plugin is via the [Grav Package Manager (GPM)](http://learn.getgrav.org/advanced/grav-gpm) through your system's Terminal (also called the command line). From the root of your Grav install type: +The simplest way to install this plugin is via the [Grav Package Manager (GPM)](https://learn.getgrav.org/advanced/grav-gpm) through your system's Terminal (also called the command line). From the root of your Grav install type: bin/gpm install sitemap @@ -16,13 +16,13 @@ This will install the Sitemap plugin into your `/user/plugins` directory within ## Manual Installation -To install this plugin, just download the zip version of this repository and unzip it under `/your/site/grav/user/plugins`. Then, rename the folder to `sitemap`. You can find these files either on [GitHub](https://github.com/getgrav/grav-plugin-sitemap) or via [GetGrav.org](http://getgrav.org/downloads/plugins#extras). +To install this plugin, just download the zip version of this repository and unzip it under `/your/site/grav/user/plugins`. Then, rename the folder to `sitemap`. You can find these files either on [GitHub](https://github.com/getgrav/grav-plugin-sitemap) or via [GetGrav.org](https://getgrav.org/downloads/plugins#extras). You should now have all the plugin files under /your/site/grav/user/plugins/sitemap ->> NOTE: This plugin is a modular component for Grav which requires [Grav](http://github.com/getgrav/grav), the [Error](https://github.com/getgrav/grav-plugin-error) and [Problems](https://github.com/getgrav/grav-plugin-problems) plugins, and a theme to be installed in order to operate. +>> NOTE: This plugin is a modular component for Grav which requires [Grav](https://github.com/getgrav/grav), the [Error](https://github.com/getgrav/grav-plugin-error) and [Problems](https://github.com/getgrav/grav-plugin-problems) plugins, and a theme to be installed in order to operate. # Usage @@ -31,7 +31,7 @@ The `sitemap` plugin works out of the box. You can just go directly to `http://y ## Config Defaults -``` +```yaml enabled: true route: '/sitemap' ignore_external: true @@ -64,7 +64,7 @@ additions: 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: -``` +```yaml sitemap: ignore: true ``` @@ -79,7 +79,7 @@ This is handled automatically based on your Grav multi-language System configura You can add images to the sitemap by adding an entry in the page's Frontmatter. -``` +```yaml sitemap: images: your_image: @@ -108,7 +108,7 @@ You can copy and extend this Twig template in your theme to customize it for you You can manually add URLs to the sitemap using the Admin settings, or by adding entries to your `sitemap.yaml` with this format: -``` +```yaml additions: - location: /something-special From d6153745843be4c86082563016b0ea22e745ba82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonat=C3=A3=20Bolzan=20Loss?= Date: Fri, 22 Sep 2023 16:13:09 -0300 Subject: [PATCH 3/7] Add support for news tags (#93) Co-authored-by: Andy Miller <1084697+rhukster@users.noreply.github.com> --- blueprints.yaml | 18 ++++++++++++++++++ languages.yaml | 3 +++ sitemap.yaml | 2 ++ templates/sitemap.xml.twig | 15 +++++++++++++++ 4 files changed, 38 insertions(+) diff --git a/blueprints.yaml b/blueprints.yaml index 61a03f0..403ec2f 100644 --- a/blueprints.yaml +++ b/blueprints.yaml @@ -110,6 +110,24 @@ form: label: PLUGIN_SITEMAP.URLSET help: PLUGIN_SITEMAP.URLSET_HELP + include_news_tags: + type: toggle + label: PLUGIN_SITEMAP.INCLUDE_NEWS_TAGS + help: PLUGIN_SITEMAP.INCLUDE_NEWS_TAGS_HELP + highlight: 1 + default: 0 + options: + 1: PLUGIN_ADMIN.ENABLED + 0: PLUGIN_ADMIN.DISABLED + validate: + type: bool + + urlnewsset: + type: text + default: 'http://www.google.com/schemas/sitemap-news/0.9' + label: PLUGIN_SITEMAP.URLNEWSSET + help: PLUGIN_SITEMAP.URLNEWSSET_HELP + short_date_format: type: toggle label: PLUGIN_ADMIN.SHORT_DATE_FORMAT diff --git a/languages.yaml b/languages.yaml index 1ebd2b7..2eedcb8 100644 --- a/languages.yaml +++ b/languages.yaml @@ -30,6 +30,9 @@ en: IGNORE_REDIRECT_HELP: 'Ignores pages that have a custom "redirect" entry in the header' URLSET: 'URLSet' URLSET_HELP: 'The URLSet XML Namespace, don''t change this!' + URLNEWSSET: 'URLNewsSet' + URLNEWSSET_HELP: 'The URLNewsSet XML Namespace, don''t change this!' + INCLUDE_NEWS_TAGS: 'Include News Tags' MULTILANG_ENABLED: 'Multi-Lang Features' MULTILANG_ENABLED_HELP: 'Enables support for multilanguage features' INCLUDE_CHANGEFREQ: 'Include Change Frequency' diff --git a/sitemap.yaml b/sitemap.yaml index 9d20ddb..3614d28 100644 --- a/sitemap.yaml +++ b/sitemap.yaml @@ -3,10 +3,12 @@ route: '/sitemap' ignore_external: true ignore_protected: true ignore_redirect: true +include_news_tags: false ignores: whitelist: html_support: false urlset: 'http://www.sitemaps.org/schemas/sitemap/0.9' +urlnewsset: 'http://www.google.com/schemas/sitemap-news/0.9' short_date_format: true include_changefreq: true changefreq: daily diff --git a/templates/sitemap.xml.twig b/templates/sitemap.xml.twig index 7f3ee10..b71f9ec 100644 --- a/templates/sitemap.xml.twig +++ b/templates/sitemap.xml.twig @@ -1,11 +1,26 @@ {% for entry in sitemap %} {{ entry.location|e }} + {% if config.plugins.sitemap.include_news_tags %} + + + {{ site.title }} + {{ site.default_lang }} + + {% if entry.lastmod %} + {{ entry.lastmod }} + {% endif %} + {{ entry.title }} + + {% endif %} {% for hreflang in entry.hreflangs %} {% endfor %} From b66cf9a390fa57ee4c0f1fbe820c5b663024d436 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Fri, 22 Sep 2023 14:08:34 -0600 Subject: [PATCH 4/7] news sitemap enabled --- README.md | 11 ++++++ blueprints.yaml | 1 + classes/SitemapEntry.php | 44 +++++++++++++++++++++ languages.yaml | 2 + sitemap.php | 14 +++++++ sitemap.yaml | 3 ++ templates/sitemap-extensions/news.html.twig | 8 ++++ templates/sitemap.xml.twig | 16 +++----- 8 files changed, 88 insertions(+), 11 deletions(-) create mode 100644 templates/sitemap-extensions/news.html.twig diff --git a/README.md b/README.md index 0be338b..91a9fd6 100644 --- a/README.md +++ b/README.md @@ -41,9 +41,14 @@ ignores: - /blog/blog-post-to-ignore - /ignore-this-route - /ignore-children-of-this-route/.* +include_news_tags: false +news_max_age_days: 2 +news_enabled_paths: + - /blog whitelist: html_support: false urlset: 'http://www.sitemaps.org/schemas/sitemap/0.9' +urlnewsset: 'http://www.google.com/schemas/sitemap-news/0.9' short_date_format: true include_changefreq: true changefreq: daily @@ -75,6 +80,12 @@ The latest Sitemap `v3.0` includes all new multi-language support utilizing the This is handled automatically based on your Grav multi-language System configuration. +### News Support + +New in version 4.0 of the plugin is support for Google's [**News Sitemap Extension**](https://developers.google.com/search/docs/crawling-indexing/sitemaps/news-sitemap) that uses a specific tags under a `` tag to provide Google News specific data. When enabled, the news extensions will be enabled when an item is in one of the configured news paths (`/` by default, so all), and if the published date is not older than the configured `max age` (default of 2 per Googles recommendations). + +The output of the news tags is controlled by an overridable `sitemap-extensions/news.html.twig` template + ## Images You can add images to the sitemap by adding an entry in the page's Frontmatter. diff --git a/blueprints.yaml b/blueprints.yaml index 403ec2f..568b671 100644 --- a/blueprints.yaml +++ b/blueprints.yaml @@ -122,6 +122,7 @@ form: validate: type: bool + urlnewsset: type: text default: 'http://www.google.com/schemas/sitemap-news/0.9' diff --git a/classes/SitemapEntry.php b/classes/SitemapEntry.php index 2a9d29c..b5a53a6 100644 --- a/classes/SitemapEntry.php +++ b/classes/SitemapEntry.php @@ -14,6 +14,11 @@ class SitemapEntry public $images; public $hreflangs = []; + public int $timestamp; + public string $rawroute; + public string $longdate; + public string $shortdate; + /** * SitemapEntry constructor. * @@ -258,5 +263,44 @@ public function setHreflangs(array $hreflangs): SitemapEntry return $this; } + public function getTimestamp(): int + { + return $this->timestamp; + } + + public function setTimestamp(int $timestamp): void + { + $this->timestamp = $timestamp; + } + + public function getRawroute(): string + { + return $this->rawroute; + } + + public function setRawroute(string $rawroute): void + { + $this->rawroute = $rawroute; + } + + public function getLongdate(): string + { + return $this->longdate; + } + + public function setLongdate(string $longdate): void + { + $this->longdate = $longdate; + } + + public function getShortdate(): string + { + return $this->shortdate; + } + + public function setShortdate(string $shortdate): void + { + $this->shortdate = $shortdate; + } } diff --git a/languages.yaml b/languages.yaml index 2eedcb8..fec30b0 100644 --- a/languages.yaml +++ b/languages.yaml @@ -33,6 +33,8 @@ en: URLNEWSSET: 'URLNewsSet' URLNEWSSET_HELP: 'The URLNewsSet XML Namespace, don''t change this!' INCLUDE_NEWS_TAGS: 'Include News Tags' + NEWS_MAX_AGE_DAYS: 'News Max Age (Days)' + NEWS_TAG_PATHS: 'News Tag Paths' MULTILANG_ENABLED: 'Multi-Lang Features' MULTILANG_ENABLED_HELP: 'Enables support for multilanguage features' INCLUDE_CHANGEFREQ: 'Include Change Frequency' diff --git a/sitemap.php b/sitemap.php index 1dfc470..83a26af 100644 --- a/sitemap.php +++ b/sitemap.php @@ -198,6 +198,9 @@ public function onTwigInitialized() $this->grav['twig']->twig()->addFunction( new TwigFunction('sort_sitemap_entries_by_language', [$this, 'sortSitemapEntriesByLanguage']) ); + $this->grav['twig']->twig()->addFunction( + new TwigFunction('timestamp_within_days', [$this, 'timestampWithinDays']) + ); } /** @@ -255,6 +258,13 @@ public function sortSitemapEntriesByLanguage() return $entries; } + public function timestampWithinDays(int $timestamp, int $days): bool + { + $now = time(); + $days_ago = $now - ($days * 24 * 60 * 60); + return $timestamp >= $days_ago; + } + protected function addRouteData($pages, $lang) { $routes = array_unique($pages->routes()); @@ -285,6 +295,10 @@ protected function addRouteData($pages, $lang) 'translated' => in_array($lang, $page_languages), 'location' => $location, 'lastmod' => date($this->datetime_format, $page->modified()), + 'longdate' => date('Y-m-d\TH:i:sP', $page->date()), + 'shortdate' => date('Y-m-d', $page->date()), + 'timestamp' => $page->date(), + 'rawroute' => $page->rawRoute(), ]; if ($this->include_change_freq) { diff --git a/sitemap.yaml b/sitemap.yaml index 3614d28..c0c5f71 100644 --- a/sitemap.yaml +++ b/sitemap.yaml @@ -4,6 +4,9 @@ ignore_external: true ignore_protected: true ignore_redirect: true include_news_tags: false +news_max_age_days: 2 +news_enabled_paths: + - /blog ignores: whitelist: html_support: false diff --git a/templates/sitemap-extensions/news.html.twig b/templates/sitemap-extensions/news.html.twig new file mode 100644 index 0000000..7cdd939 --- /dev/null +++ b/templates/sitemap-extensions/news.html.twig @@ -0,0 +1,8 @@ + + + {{ site.title }} + {{ entry.lang }} + + {{ entry.shortdate }} + {{ entry.title }} + \ No newline at end of file diff --git a/templates/sitemap.xml.twig b/templates/sitemap.xml.twig index b71f9ec..37a041a 100644 --- a/templates/sitemap.xml.twig +++ b/templates/sitemap.xml.twig @@ -9,17 +9,11 @@ {% for entry in sitemap %} {{ entry.location|e }} - {% if config.plugins.sitemap.include_news_tags %} - - - {{ site.title }} - {{ site.default_lang }} - - {% if entry.lastmod %} - {{ entry.lastmod }} - {% endif %} - {{ entry.title }} - + {% if config.plugins.sitemap.include_news_tags and + timestamp_within_days(entry.timestamp, config.plugin.sitemap.news_max_age_days|default(2)) and + entry.rawroute|starts_with(config.plugins.sitemap.news_enabled_paths) + %} + {% include 'sitemap-extensions/news.html.twig' %} {% endif %} {% for hreflang in entry.hreflangs %} From 407514fc9f57b18302b435e520012498758d25a9 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Fri, 22 Sep 2023 14:13:08 -0600 Subject: [PATCH 5/7] updated blueprints --- blueprints.yaml | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/blueprints.yaml b/blueprints.yaml index 568b671..25f2af2 100644 --- a/blueprints.yaml +++ b/blueprints.yaml @@ -122,13 +122,27 @@ form: validate: type: bool - urlnewsset: type: text default: 'http://www.google.com/schemas/sitemap-news/0.9' label: PLUGIN_SITEMAP.URLNEWSSET help: PLUGIN_SITEMAP.URLNEWSSET_HELP + news_max_age_days: + type: number + default: 2 + size: x-small + label: PLUGIN_SITEMAP.NEWS_MAX_AGE_DAYS + append: Days + validate: + type: int + + news_enabled_paths: + type: array + label: PLUGIN_SITEMAP.NEWS_TAG_PATHS + value_only: true + placeholder_value: '/news' + short_date_format: type: toggle label: PLUGIN_ADMIN.SHORT_DATE_FORMAT From b3688adb7aa68fb72b96a0ebe597aed1ffa307fd Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Fri, 22 Sep 2023 14:16:24 -0600 Subject: [PATCH 6/7] updated changelog --- CHANGELOG.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index dda4742..cad2344 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +# v4.0.0 +## 09/22/2023 + +1. [](#new) + * Added support for Google News tags [#93](https://github.com/getgrav/grav-plugin-sitemap/pull/93) + * Enhanced Google News to allow restriction to paths and configurable max-age in days +1. [](#improved) + * Added YAML syntax highlighting in README.md [#101](https://github.com/getgrav/grav-plugin-sitemap/pull/101) + # v3.0.2 ## 06/14/2022 From c7bfe6f0b8363e12ddabd99bacd3a42cb9cea916 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Fri, 22 Sep 2023 14:17:05 -0600 Subject: [PATCH 7/7] prepare for release --- blueprints.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/blueprints.yaml b/blueprints.yaml index 25f2af2..c0c0d14 100644 --- a/blueprints.yaml +++ b/blueprints.yaml @@ -1,7 +1,7 @@ name: Sitemap type: plugin slug: sitemap -version: 3.0.2 +version: 4.0.0 description: "Provide automatically generated **XML sitemaps** with this very useful, but simple to configure, Grav plugin." icon: map-marker author: