From 8b8a402c238cace69254445863c5541b30fe0a23 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Tue, 26 Sep 2023 11:08:05 -0600 Subject: [PATCH 01/10] add xmlns option + restructure --- CHANGELOG.md | 6 ++++ blueprints.yaml | 35 +++++++++++++------ languages.yaml | 8 +++-- sitemap.yaml | 2 ++ templates/sitemap-extensions/image.xml.twig | 17 +++++++++ .../{news.html.twig => news.xml.twig} | 0 templates/sitemap-partials/xmlns.xml.twig | 7 ++++ templates/sitemap.xml.twig | 29 +++------------ 8 files changed, 68 insertions(+), 36 deletions(-) create mode 100644 templates/sitemap-extensions/image.xml.twig rename templates/sitemap-extensions/{news.html.twig => news.xml.twig} (100%) create mode 100644 templates/sitemap-partials/xmlns.xml.twig diff --git a/CHANGELOG.md b/CHANGELOG.md index cad2344..b667113 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# v4.0.1 +## mm/dd/2023 + +1. [](#new) + * Added a toggle for XSL transform support to be disabled + # v4.0.0 ## 09/22/2023 diff --git a/blueprints.yaml b/blueprints.yaml index c0c0d14..4c66cbf 100644 --- a/blueprints.yaml +++ b/blueprints.yaml @@ -92,6 +92,18 @@ form: validate: pattern: "/([a-z-_]+/?)+" + xsl_transform: + type: toggle + label: PLUGIN_SITEMAP.XSL_TRANSFORM + help: PLUGIN_SITEMAP.XSL_TRANSFORM_HELP + highlight: 1 + default: 1 + options: + 1: PLUGIN_ADMIN.ENABLED + 0: PLUGIN_ADMIN.DISABLED + validate: + type: bool + html_support: type: toggle label: PLUGIN_SITEMAP.HTML_SUPPORT @@ -110,6 +122,12 @@ form: label: PLUGIN_SITEMAP.URLSET help: PLUGIN_SITEMAP.URLSET_HELP + urlimageset: + type: text + default: 'http://www.google.com/schemas/sitemap-image/1.1' + label: PLUGIN_SITEMAP.URLIMAGESET + help: PLUGIN_SITEMAP.URLIMAGESET_HELP + include_news_tags: type: toggle label: PLUGIN_SITEMAP.INCLUDE_NEWS_TAGS @@ -143,17 +161,14 @@ form: value_only: true placeholder_value: '/news' - short_date_format: - type: toggle - label: PLUGIN_ADMIN.SHORT_DATE_FORMAT - help: PLUGIN_ADMIN.SHORT_DATE_FORMAT_HELP - highlight: 1 - default: 0 + date_type: + type: select + label: PLUGIN_SITEMAP.DATE_TYPE + default: page_date + size: medium options: - 1: PLUGIN_ADMIN.ENABLED - 0: PLUGIN_ADMIN.DISABLED - validate: - type: bool + page_date: PLUGIN_SITEMAP.DATE_TYPE_PAGE_DATE + last_modified: PLUGIN_SITEMAP.DATE_TYPE_LAST_MODIFIED include_changefreq: type: toggle diff --git a/languages.yaml b/languages.yaml index fec30b0..83da071 100644 --- a/languages.yaml +++ b/languages.yaml @@ -29,9 +29,11 @@ en: IGNORE_REDIRECT: 'Ignore Redirect Pages' 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!' + URLSET_HELP: 'The URLSet XML Namespace' + URLIMAGESET: 'URLImageSet' + URLIMAGESET_HELP: 'The URLImageSet XML Namespace,' URLNEWSSET: 'URLNewsSet' - URLNEWSSET_HELP: 'The URLNewsSet XML Namespace, don''t change this!' + URLNEWSSET_HELP: 'The URLNewsSet XML Namespace' INCLUDE_NEWS_TAGS: 'Include News Tags' NEWS_MAX_AGE_DAYS: 'News Max Age (Days)' NEWS_TAG_PATHS: 'News Tag Paths' @@ -47,6 +49,8 @@ en: TITLE_TITLE: 'Title' TITLE_LASTMOD: 'Last Modified' UNTITLED: 'Untitled' + XSL_TRANSFORM: 'XSL Transform' + XSL_TRANSFORM_HELP: 'Use "sitemap.xsl" to transform the XML output when viewing in a browser' ru: PLUGIN_SITEMAP: SITEMAP: 'Карта сайта' diff --git a/sitemap.yaml b/sitemap.yaml index c0c5f71..c09a6bb 100644 --- a/sitemap.yaml +++ b/sitemap.yaml @@ -9,9 +9,11 @@ news_enabled_paths: - /blog ignores: whitelist: +xsl_transform: true html_support: false urlset: 'http://www.sitemaps.org/schemas/sitemap/0.9' urlnewsset: 'http://www.google.com/schemas/sitemap-news/0.9' +urlimageset: 'http://www.google.com/schemas/sitemap-image/1.1' short_date_format: true include_changefreq: true changefreq: daily diff --git a/templates/sitemap-extensions/image.xml.twig b/templates/sitemap-extensions/image.xml.twig new file mode 100644 index 0000000..04bd10a --- /dev/null +++ b/templates/sitemap-extensions/image.xml.twig @@ -0,0 +1,17 @@ + +{% if image.loc %} + {{ url(image.loc, true) }} +{% endif %} +{% if image.caption %} + {{ image.caption }} +{% endif %} +{% if image.geoloc %} + {{ image.geoloc }} +{% endif %} +{% if image.title %} + {{ image.title }} +{% endif %} +{% if image.license %} + {{ image.license }} +{% endif %} + \ No newline at end of file diff --git a/templates/sitemap-extensions/news.html.twig b/templates/sitemap-extensions/news.xml.twig similarity index 100% rename from templates/sitemap-extensions/news.html.twig rename to templates/sitemap-extensions/news.xml.twig diff --git a/templates/sitemap-partials/xmlns.xml.twig b/templates/sitemap-partials/xmlns.xml.twig new file mode 100644 index 0000000..744b3a1 --- /dev/null +++ b/templates/sitemap-partials/xmlns.xml.twig @@ -0,0 +1,7 @@ + diff --git a/templates/sitemap.xml.twig b/templates/sitemap.xml.twig index 37a041a..34e32ba 100644 --- a/templates/sitemap.xml.twig +++ b/templates/sitemap.xml.twig @@ -1,11 +1,8 @@ +{% if config.plugins.sitemap.xsl_transform %} - +{% endif %} +{% include 'sitemap-partials/xmlns.xml.twig' %} {% for entry in sitemap %} {{ entry.location|e }} @@ -13,7 +10,7 @@ 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' %} + {% include 'sitemap-extensions/news.xml.twig' %} {% endif %} {% for hreflang in entry.hreflangs %} @@ -28,23 +25,7 @@ {{ entry.priority|number_format(1) }} {% endif %} {% for image in entry.images %} - - {% if image.loc %} - {{ url(image.loc, true) }} - {% endif %} - {% if image.caption %} - {{ image.caption }} - {% endif %} - {% if image.geoloc %} - {{ image.geoloc }} - {% endif %} - {% if image.title %} - {{ image.title }} - {% endif %} - {% if image.license %} - {{ image.license }} - {% endif %} - + {% include 'sitemap-extensions/image.xml.twig' %} {% endfor %} {% endfor %} From 710f3a7a459a076a2701405df5ae90a2cb2c666d Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Wed, 4 Oct 2023 15:05:36 -0600 Subject: [PATCH 02/10] wip standalone sitemap-news support --- sitemap.php | 24 +++++++++++++++++----- sitemap.yaml | 1 + templates/sitemap-extensions/news.xml.twig | 4 ++-- templates/sitemap-news.xml.twig | 18 ++++++++++++++++ templates/sitemap-partials/xmlns.xml.twig | 7 ------- templates/sitemap.xml.twig | 9 +++++++- 6 files changed, 48 insertions(+), 15 deletions(-) create mode 100644 templates/sitemap-news.xml.twig delete mode 100644 templates/sitemap-partials/xmlns.xml.twig diff --git a/sitemap.php b/sitemap.php index 83a26af..5e63d04 100644 --- a/sitemap.php +++ b/sitemap.php @@ -74,9 +74,14 @@ public function onPluginsInitialized() /** @var Uri $uri */ $uri = $this->grav['uri']; - $route = $this->config->get('plugins.sitemap.route'); + $route = $this->config()['route']; + $news_route = str_replace($this->config()['news_route_suffix'], '', $uri->route()); - if ($route && $route == $uri->path()) { + if ($route && ($route == $uri->route() || + ($uri->extension() === 'xml' && + $this->config()['include_news_tags'] && + in_array($news_route, $this->config()['news_enabled_paths']))) + ) { $this->enable([ 'onTwigInitialized' => ['onTwigInitialized', 0], @@ -176,10 +181,11 @@ public function onPageInitialized($event) { $page = $event['page'] ?? null; $route = $this->config->get('plugins.sitemap.route'); + $uri = $this->grav['uri']; + $html_support = $this->config->get('plugins.sitemap.html_support', false); + $extension = $this->grav['uri']->extension() ?? ($html_support ? 'html': 'xml'); - if (is_null($page) || $page->route() !== $route) { - $html_support = $this->config->get('plugins.sitemap.html_support', false); - $extension = $this->grav['uri']->extension() ?? ($html_support ? 'html': 'xml'); + if (is_null($page) || $uri->route() === $route) { // set a dummy page $page = new Page; @@ -189,6 +195,14 @@ public function onPageInitialized($event) $this->grav['page'] = $page; $twig = $this->grav['twig']; $twig->template = "sitemap.$extension.twig"; + } elseif ( + $extension === 'xml' && + $this->config()['include_news_tags'] && + $this->config()['standalone_sitemap_news'] && + in_array($uri->route(), $this->config()['news_enabled_paths'] )) { + $extension = $this->grav['uri']->extension(); + $twig = $this->grav['twig']; + $twig->template = "sitemap-news.$extension.twig"; } } diff --git a/sitemap.yaml b/sitemap.yaml index c09a6bb..69b41f7 100644 --- a/sitemap.yaml +++ b/sitemap.yaml @@ -4,6 +4,7 @@ ignore_external: true ignore_protected: true ignore_redirect: true include_news_tags: false +standalone_sitemap_news: false news_max_age_days: 2 news_enabled_paths: - /blog diff --git a/templates/sitemap-extensions/news.xml.twig b/templates/sitemap-extensions/news.xml.twig index 7cdd939..b378771 100644 --- a/templates/sitemap-extensions/news.xml.twig +++ b/templates/sitemap-extensions/news.xml.twig @@ -3,6 +3,6 @@ {{ site.title }} {{ entry.lang }} - {{ entry.shortdate }} + {{ entry.longdate }} {{ entry.title }} - \ No newline at end of file + diff --git a/templates/sitemap-news.xml.twig b/templates/sitemap-news.xml.twig new file mode 100644 index 0000000..7de8477 --- /dev/null +++ b/templates/sitemap-news.xml.twig @@ -0,0 +1,18 @@ + +{% if config.plugins.sitemap.xsl_transform %} + +{% endif %} + +{% for entry in sitemap %} + {% if timestamp_within_days(entry.timestamp, config.plugin.sitemap.news_max_age_days|default(2)) and + entry.rawroute|starts_with(page.route) %} + + {{ entry.location|e }} + {% include 'sitemap-extensions/news.xml.twig' %} + + {% endif %} +{% endfor %} + \ No newline at end of file diff --git a/templates/sitemap-partials/xmlns.xml.twig b/templates/sitemap-partials/xmlns.xml.twig deleted file mode 100644 index 744b3a1..0000000 --- a/templates/sitemap-partials/xmlns.xml.twig +++ /dev/null @@ -1,7 +0,0 @@ - diff --git a/templates/sitemap.xml.twig b/templates/sitemap.xml.twig index 34e32ba..cca6521 100644 --- a/templates/sitemap.xml.twig +++ b/templates/sitemap.xml.twig @@ -2,11 +2,18 @@ {% if config.plugins.sitemap.xsl_transform %} {% endif %} -{% include 'sitemap-partials/xmlns.xml.twig' %} + {% for entry in sitemap %} {{ entry.location|e }} {% if config.plugins.sitemap.include_news_tags and + config.plugins.sitemap.standalone_sitemap_news == false 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) %} From e5acab68f1cfb1aacf4141d327ea4fab914235f4 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Wed, 4 Oct 2023 15:07:54 -0600 Subject: [PATCH 03/10] no more news_route_suffix --- sitemap.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sitemap.php b/sitemap.php index 5e63d04..4bffa50 100644 --- a/sitemap.php +++ b/sitemap.php @@ -75,12 +75,11 @@ public function onPluginsInitialized() /** @var Uri $uri */ $uri = $this->grav['uri']; $route = $this->config()['route']; - $news_route = str_replace($this->config()['news_route_suffix'], '', $uri->route()); if ($route && ($route == $uri->route() || ($uri->extension() === 'xml' && $this->config()['include_news_tags'] && - in_array($news_route, $this->config()['news_enabled_paths']))) + in_array($uri->route(), $this->config()['news_enabled_paths']))) ) { $this->enable([ From 44cf366668e21abc738d9cc2579d8772940625d4 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Wed, 4 Oct 2023 19:11:22 -0600 Subject: [PATCH 04/10] news specific XSLT stylesheet --- sitemap-news.xsl | 114 ++++++++++++++++++++++++++++++++ templates/sitemap-news.xml.twig | 2 +- 2 files changed, 115 insertions(+), 1 deletion(-) create mode 100644 sitemap-news.xsl diff --git a/sitemap-news.xsl b/sitemap-news.xsl new file mode 100644 index 0000000..f53c6cb --- /dev/null +++ b/sitemap-news.xsl @@ -0,0 +1,114 @@ + + + + + + + XML Sitemap + + + + + + + + + + + + + + + + + + + + + + + + + + +
News Sitemap
TitletitlePublication Date
+ + + + + + + + + + +
+ + +
+
diff --git a/templates/sitemap-news.xml.twig b/templates/sitemap-news.xml.twig index 7de8477..b3e0954 100644 --- a/templates/sitemap-news.xml.twig +++ b/templates/sitemap-news.xml.twig @@ -1,6 +1,6 @@ {% if config.plugins.sitemap.xsl_transform %} - + {% endif %} Date: Wed, 4 Oct 2023 19:16:40 -0600 Subject: [PATCH 05/10] sort by deate desc --- sitemap-news.xsl | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/sitemap-news.xsl b/sitemap-news.xsl index f53c6cb..25d0178 100644 --- a/sitemap-news.xsl +++ b/sitemap-news.xsl @@ -79,15 +79,16 @@ News Sitemap - Title - title - Publication Date + loc + news:title + news:publication_date + From 340e78ef032d8ef1bb056f5d62b7a7abe998647d Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Wed, 4 Oct 2023 19:59:40 -0600 Subject: [PATCH 06/10] fixes to support /sitemap-news.xml trailing path --- sitemap.php | 39 ++++++++++++++++++++------------- templates/sitemap-news.xml.twig | 3 ++- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/sitemap.php b/sitemap.php index 4bffa50..3fa61b3 100644 --- a/sitemap.php +++ b/sitemap.php @@ -38,6 +38,8 @@ class SitemapPlugin extends Plugin protected $ignore_protected = true; protected $ignore_redirect = true; + protected $news_route = null; + /** * @return array */ @@ -75,12 +77,18 @@ public function onPluginsInitialized() /** @var Uri $uri */ $uri = $this->grav['uri']; $route = $this->config()['route']; + $uri_route = $uri->route(); + $news_page = false; + + if ($this->config()['include_news_tags'] && + $this->config()['standalone_sitemap_news'] && + Utils::endsWith($uri->uri(), $this->config()['sitemap_news_path']) && + in_array(dirname($uri->route()), $this->config()['news_enabled_paths'])) { + $this->news_route = dirname($uri->route()); + } + - if ($route && ($route == $uri->route() || - ($uri->extension() === 'xml' && - $this->config()['include_news_tags'] && - in_array($uri->route(), $this->config()['news_enabled_paths']))) - ) { + if ($route === $uri->route() || !empty($this->news_route)) { $this->enable([ 'onTwigInitialized' => ['onTwigInitialized', 0], @@ -184,7 +192,7 @@ public function onPageInitialized($event) $html_support = $this->config->get('plugins.sitemap.html_support', false); $extension = $this->grav['uri']->extension() ?? ($html_support ? 'html': 'xml'); - if (is_null($page) || $uri->route() === $route) { + if (is_null($page) || $uri->route() === $route || !empty($this->news_route)) { // set a dummy page $page = new Page; @@ -193,15 +201,16 @@ public function onPageInitialized($event) unset($this->grav['page']); $this->grav['page'] = $page; $twig = $this->grav['twig']; - $twig->template = "sitemap.$extension.twig"; - } elseif ( - $extension === 'xml' && - $this->config()['include_news_tags'] && - $this->config()['standalone_sitemap_news'] && - in_array($uri->route(), $this->config()['news_enabled_paths'] )) { - $extension = $this->grav['uri']->extension(); - $twig = $this->grav['twig']; - $twig->template = "sitemap-news.$extension.twig"; + + if (!empty($this->news_route)) { + $header = $page->header(); + $header->sitemap['news_route'] = $this->news_route; + $page->header($header); + $twig->template = "sitemap-news.$extension.twig"; + } else { + $twig->template = "sitemap.$extension.twig"; + } + } } diff --git a/templates/sitemap-news.xml.twig b/templates/sitemap-news.xml.twig index b3e0954..837c1fb 100644 --- a/templates/sitemap-news.xml.twig +++ b/templates/sitemap-news.xml.twig @@ -1,3 +1,4 @@ +{% set sitemap_config = page.header.sitemap %} {% if config.plugins.sitemap.xsl_transform %} @@ -8,7 +9,7 @@ xmlns:news="{{ config.plugins.sitemap.urlnewsset }}"> {% for entry in sitemap %} {% if timestamp_within_days(entry.timestamp, config.plugin.sitemap.news_max_age_days|default(2)) and - entry.rawroute|starts_with(page.route) %} + entry.rawroute|starts_with(sitemap_config.news_route ~ '/') %} {{ entry.location|e }} {% include 'sitemap-extensions/news.xml.twig' %} From cf6e8bb7c02d46696992be81ced0261043e42f8b Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Thu, 5 Oct 2023 11:37:06 -0600 Subject: [PATCH 07/10] standalone sitemap support --- CHANGELOG.md | 5 +- README.md | 14 ++- blueprints.yaml | 300 +++++++++++++++++++++++++++--------------------- languages.yaml | 13 ++- sitemap.yaml | 1 + 5 files changed, 198 insertions(+), 135 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b667113..f714f7b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,11 @@ -# v4.0.1 +# v4.1.0 ## mm/dd/2023 1. [](#new) + * New capability to support "standalone" Sitemap News pages * Added a toggle for XSL transform support to be disabled +1. [](#improved) + * Improved blueprint and created sections # v4.0.0 ## 09/22/2023 diff --git a/README.md b/README.md index 91a9fd6..1213951 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,8 @@ ignores: - /ignore-this-route - /ignore-children-of-this-route/.* include_news_tags: false +standalone_sitemap_news: false +sitemap_news_path: '/sitemap-news.xml' news_max_age_days: 2 news_enabled_paths: - /blog @@ -84,7 +86,17 @@ This is handled automatically based on your Grav multi-language System configura 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 +The output of the news tags is controlled by an overridable `sitemap-extensions/news.html.twig` template. + +The default behavior when **Include News Tags** is enabled, is to include the news tags directly in the primary `sitemap.xml` file. However, if you enabled the **Standalone News URLs** option, news tags will not be added to the primary `sitemap.xml`, rather, they will be available in standalone paths that contain only the pages in the designated news paths. + +For example, the default behavior is to enable `/blog` as a news path. If this path exists, you have content in subfolders of this page, and that content is less than the defined "News Max Age" (2 days recommended by Google), then that sitemap-news-specific sitemap would be available via: + +``` +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 diff --git a/blueprints.yaml b/blueprints.yaml index 4c66cbf..3dc0a88 100644 --- a/blueprints.yaml +++ b/blueprints.yaml @@ -30,6 +30,14 @@ form: validate: type: bool + route: + type: text + size: medium + label: PLUGIN_SITEMAP.ROUTE + placeholder: /sitemap + validate: + pattern: "/([a-z-_]+/?)+" + multilang_enabled: type: toggle label: PLUGIN_SITEMAP.MULTILANG_ENABLED @@ -78,20 +86,6 @@ form: validate: type: bool - ignores: - type: array - label: PLUGIN_SITEMAP.IGNORES - help: PLUGIN_SITEMAP.IGNORES_HELP - value_only: true - placeholder_value: '/ignore-this-route' - - route: - type: text - label: PLUGIN_SITEMAP.ROUTE - placeholder: /sitemap - validate: - pattern: "/([a-z-_]+/?)+" - xsl_transform: type: toggle label: PLUGIN_SITEMAP.XSL_TRANSFORM @@ -116,133 +110,95 @@ form: validate: type: bool - urlset: - type: text - default: 'http://www.sitemaps.org/schemas/sitemap/0.9' - label: PLUGIN_SITEMAP.URLSET - help: PLUGIN_SITEMAP.URLSET_HELP - - urlimageset: - type: text - default: 'http://www.google.com/schemas/sitemap-image/1.1' - label: PLUGIN_SITEMAP.URLIMAGESET - help: PLUGIN_SITEMAP.URLIMAGESET_HELP + ignores: + type: array + label: PLUGIN_SITEMAP.IGNORES + help: PLUGIN_SITEMAP.IGNORES_HELP + value_only: true + placeholder_value: '/ignore-this-route' - 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 + news_section: + type: section + title: Sitemap News + underline: true - urlnewsset: - type: text - default: 'http://www.google.com/schemas/sitemap-news/0.9' - label: PLUGIN_SITEMAP.URLNEWSSET - help: PLUGIN_SITEMAP.URLNEWSSET_HELP + fields: - news_max_age_days: - type: number - default: 2 - size: x-small - label: PLUGIN_SITEMAP.NEWS_MAX_AGE_DAYS - append: Days - validate: - type: int + 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 - news_enabled_paths: - type: array - label: PLUGIN_SITEMAP.NEWS_TAG_PATHS - value_only: true - placeholder_value: '/news' + standalone_sitemap_news: + type: toggle + label: PLUGIN_SITEMAP.STANDALONE_SITEMAP_NEWS + help: PLUGIN_SITEMAP.STANDALONE_SITEMAP_NEWS_HELP + highlight: 1 + default: 0 + options: + 1: PLUGIN_ADMIN.ENABLED + 0: PLUGIN_ADMIN.DISABLED + validate: + type: bool - date_type: - type: select - label: PLUGIN_SITEMAP.DATE_TYPE - default: page_date - size: medium - options: - page_date: PLUGIN_SITEMAP.DATE_TYPE_PAGE_DATE - last_modified: PLUGIN_SITEMAP.DATE_TYPE_LAST_MODIFIED + sitemap_news_path: + type: text + size: medium + label: PLUGIN_SITEMAP.SITEMAP_NEWS_PATH + help: PLUGIN_SITEMAP.SITEMAP_NEWS_PATH_HELP - include_changefreq: - type: toggle - label: PLUGIN_SITEMAP.INCLUDE_CHANGEFREQ - help: PLUGIN_SITEMAP.INCLUDE_CHANGEFREQ_HELP - highlight: 1 - default: 0 - options: - 1: PLUGIN_ADMIN.ENABLED - 0: PLUGIN_ADMIN.DISABLED - validate: - type: bool + news_max_age_days: + type: number + default: 2 + size: x-small + label: PLUGIN_SITEMAP.NEWS_MAX_AGE_DAYS + append: Days + validate: + type: int - changefreq: - type: select - label: PLUGIN_SITEMAP.CHANGEFREQ - default: '' - options: - '': PLUGIN_SITEMAP.CHANGEFREQ_DEFAULT - always: PLUGIN_SITEMAP.CHANGEFREQ_ALWAYS - hourly: PLUGIN_SITEMAP.CHANGEFREQ_HOURLY - daily: PLUGIN_SITEMAP.CHANGEFREQ_DAILY - weekly: PLUGIN_SITEMAP.CHANGEFREQ_WEEKLY - monthly: PLUGIN_SITEMAP.CHANGEFREQ_MONTHLY - yearly: PLUGIN_SITEMAP.CHANGEFREQ_YEARLY - never: PLUGIN_SITEMAP.CHANGEFREQ_NEVER + news_enabled_paths: + type: array + label: PLUGIN_SITEMAP.NEWS_TAG_PATHS + value_only: true + placeholder_value: '/news' - include_priority: - type: toggle - label: PLUGIN_SITEMAP.INCLUDE_PRIORITY - help: PLUGIN_SITEMAP.INCLUDE_PRIORITY_HELP - highlight: 1 - default: 0 - options: - 1: PLUGIN_ADMIN.ENABLED - 0: PLUGIN_ADMIN.DISABLED - validate: - type: bool + data_section: + type: section + title: Sitemap Data + underline: true + fields: - priority: - type: select - label: PLUGIN_SITEMAP.PRIORITY - default: '' - options: - '': PLUGIN_SITEMAP.PRIORITY_USE_GLOBAL - '0.1': 0.1 - '0.2': 0.2 - '0.3': 0.3 - '0.4': 0.4 - '0.5': 0.5 - '0.6': 0.6 - '0.7': 0.7 - '0.8': 0.8 - '0.9': 0.9 - '1.0': 1.0 - validate: - type: float + date_type: + type: select + label: PLUGIN_SITEMAP.DATE_TYPE + default: page_date + size: medium + options: + page_date: PLUGIN_SITEMAP.DATE_TYPE_PAGE_DATE + last_modified: PLUGIN_SITEMAP.DATE_TYPE_LAST_MODIFIED - additions: - type: list - label: PLUGIN_SITEMAP.ADDITIONS - help: PLUGIN_SITEMAP.ADDITIONS_HELP + include_changefreq: + type: toggle + label: PLUGIN_SITEMAP.INCLUDE_CHANGEFREQ + help: PLUGIN_SITEMAP.INCLUDE_CHANGEFREQ_HELP + highlight: 1 + default: 0 + options: + 1: PLUGIN_ADMIN.ENABLED + 0: PLUGIN_ADMIN.DISABLED + validate: + type: bool - fields: - .location: - type: text - label: PLUGIN_SITEMAP.LOCATION - placeholder: "/not-a-grav-url" - .lastmod: - type: text - label: PLUGIN_SITEMAP.LASTMOD - placeholder: "2017-04-06" - .changefreq: + changefreq: type: select + size: medium label: PLUGIN_SITEMAP.CHANGEFREQ default: '' options: @@ -254,9 +210,23 @@ form: monthly: PLUGIN_SITEMAP.CHANGEFREQ_MONTHLY yearly: PLUGIN_SITEMAP.CHANGEFREQ_YEARLY never: PLUGIN_SITEMAP.CHANGEFREQ_NEVER - .priority: + + include_priority: + type: toggle + label: PLUGIN_SITEMAP.INCLUDE_PRIORITY + help: PLUGIN_SITEMAP.INCLUDE_PRIORITY_HELP + highlight: 1 + default: 0 + options: + 1: PLUGIN_ADMIN.ENABLED + 0: PLUGIN_ADMIN.DISABLED + validate: + type: bool + + priority: type: select label: PLUGIN_SITEMAP.PRIORITY + size: small default: '' options: '': PLUGIN_SITEMAP.PRIORITY_USE_GLOBAL @@ -272,3 +242,73 @@ form: '1.0': 1.0 validate: type: float + + advanced_section: + type: section + title: Advanced Features + underline: true + fields: + + additions: + type: list + label: PLUGIN_SITEMAP.ADDITIONS + help: PLUGIN_SITEMAP.ADDITIONS_HELP + + fields: + .location: + type: text + label: PLUGIN_SITEMAP.LOCATION + placeholder: "/not-a-grav-url" + .lastmod: + type: text + label: PLUGIN_SITEMAP.LASTMOD + placeholder: "2017-04-06" + .changefreq: + type: select + label: PLUGIN_SITEMAP.CHANGEFREQ + default: '' + options: + '': PLUGIN_SITEMAP.CHANGEFREQ_DEFAULT + always: PLUGIN_SITEMAP.CHANGEFREQ_ALWAYS + hourly: PLUGIN_SITEMAP.CHANGEFREQ_HOURLY + daily: PLUGIN_SITEMAP.CHANGEFREQ_DAILY + weekly: PLUGIN_SITEMAP.CHANGEFREQ_WEEKLY + monthly: PLUGIN_SITEMAP.CHANGEFREQ_MONTHLY + yearly: PLUGIN_SITEMAP.CHANGEFREQ_YEARLY + never: PLUGIN_SITEMAP.CHANGEFREQ_NEVER + .priority: + type: select + label: PLUGIN_SITEMAP.PRIORITY + default: '' + options: + '': PLUGIN_SITEMAP.PRIORITY_USE_GLOBAL + '0.1': 0.1 + '0.2': 0.2 + '0.3': 0.3 + '0.4': 0.4 + '0.5': 0.5 + '0.6': 0.6 + '0.7': 0.7 + '0.8': 0.8 + '0.9': 0.9 + '1.0': 1.0 + validate: + type: float + + urlset: + type: text + default: 'http://www.sitemaps.org/schemas/sitemap/0.9' + label: PLUGIN_SITEMAP.URLSET + help: PLUGIN_SITEMAP.URLSET_HELP + + urlimageset: + type: text + default: 'http://www.google.com/schemas/sitemap-image/1.1' + label: PLUGIN_SITEMAP.URLIMAGESET + help: PLUGIN_SITEMAP.URLIMAGESET_HELP + + urlnewsset: + type: text + default: 'http://www.google.com/schemas/sitemap-news/0.9' + label: PLUGIN_SITEMAP.URLNEWSSET + help: PLUGIN_SITEMAP.URLNEWSSET_HELP diff --git a/languages.yaml b/languages.yaml index 83da071..4b205b5 100644 --- a/languages.yaml +++ b/languages.yaml @@ -16,7 +16,7 @@ en: PRIORITY: 'Global - Sitemap Priority' PRIORITY_USE_GLOBAL: 'Use Global (1)' ROUTE: 'Route to Sitemap' - IGNORES: 'Ignore' + IGNORES: 'Ignore URLs' IGNORES_HELP: 'URLs to ignore (You can ignore all children of a path by using regex and appending ".*" to the ignore path)' ADDITIONS: 'Additional URLs' ADDITIONS_HELP: 'Add external URLs to the sitemap' @@ -36,7 +36,7 @@ en: URLNEWSSET_HELP: 'The URLNewsSet XML Namespace' INCLUDE_NEWS_TAGS: 'Include News Tags' NEWS_MAX_AGE_DAYS: 'News Max Age (Days)' - NEWS_TAG_PATHS: 'News Tag Paths' + NEWS_TAG_PATHS: 'News Enabled Paths' MULTILANG_ENABLED: 'Multi-Lang Features' MULTILANG_ENABLED_HELP: 'Enables support for multilanguage features' INCLUDE_CHANGEFREQ: 'Include Change Frequency' @@ -50,7 +50,14 @@ en: TITLE_LASTMOD: 'Last Modified' UNTITLED: 'Untitled' XSL_TRANSFORM: 'XSL Transform' - XSL_TRANSFORM_HELP: 'Use "sitemap.xsl" to transform the XML output when viewing in a browser' + XSL_TRANSFORM_HELP: 'Use XSL stylesheets to transform the XML output when viewing in a browser' + DATE_TYPE: 'Date Type' + DATE_TYPE_PAGE_DATE: 'Page Date' + DATE_TYPE_LAST_MODIFIED: 'Last Modified' + STANDALONE_SITEMAP_NEWS: 'Standalone News URLs' + STANDALONE_SITEMAP_NEWS_HELP: 'Create a standalone sitemap-news.xml file for each news-enabled path' + SITEMAP_NEWS_PATH: 'Sitemap News Path' + SITEMAP_NEWS_PATH_HELP: 'The path to the Sitemap News file' ru: PLUGIN_SITEMAP: SITEMAP: 'Карта сайта' diff --git a/sitemap.yaml b/sitemap.yaml index 69b41f7..a249bb6 100644 --- a/sitemap.yaml +++ b/sitemap.yaml @@ -5,6 +5,7 @@ ignore_protected: true ignore_redirect: true include_news_tags: false standalone_sitemap_news: false +sitemap_news_path: '/sitemap-news.xml' news_max_age_days: 2 news_enabled_paths: - /blog From a3e45ccb086434a7675093833cbab3c83005dd68 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Thu, 5 Oct 2023 12:40:13 -0600 Subject: [PATCH 08/10] fix for translated routes + hide x-default if include_default_lang enabled --- CHANGELOG.md | 5 ++++- sitemap.php | 8 +++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f714f7b..23bd7be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,10 @@ * Added a toggle for XSL transform support to be disabled 1. [](#improved) * Improved blueprint and created sections - + * Hide `x-default` alternate links when `include_default_lang` is enabled +1. [](#bugfix) + * Fixed an issue with translated links were not being handled properly and not showing all alternate languages + # v4.0.0 ## 09/22/2023 diff --git a/sitemap.php b/sitemap.php index 3fa61b3..0597080 100644 --- a/sitemap.php +++ b/sitemap.php @@ -112,7 +112,7 @@ public function onPagesInitialized() $pages = $this->grav['pages']; $cache_id = md5('sitemap-data-'.$pages->getPagesCacheId()); - $this->sitemap = $cache->fetch($cache_id); +// $this->sitemap = $cache->fetch($cache_id); if ($this->sitemap === false) { $this->multilang_enabled = $this->config->get('plugins.sitemap.multilang_enabled'); @@ -122,6 +122,7 @@ public function onPagesInitialized() $default_lang = $language->getDefault() ?: 'en'; $active_lang = $language->getActive() ?? $default_lang; $languages = $this->multilang_enabled && $language->enabled() ? $language->getLanguages() : [$default_lang]; + $include_default_lang = $this->config->get('system.languages.include_default_lang'); $this->multilang_skiplang_prefix = $this->config->get('system.languages.include_default_lang') ? '' : $language->getDefault(); $this->multilang_include_fallbacks = $this->config->get('system.languages.pages_fallback_only') || !empty($this->config->get('system.languages.content_fallback')); @@ -160,7 +161,7 @@ public function onPagesInitialized() if ($language->enabled()) { foreach ($route_data as $l => $l_data) { $entry->addHreflangs(['hreflang' => $l, 'href' => $l_data['location']]); - if ($l == $default_lang) { + if ($include_default_lang === false && $l == $default_lang) { $entry->addHreflangs(['hreflang' => 'x-default', 'href' => $l_data['location']]); } } @@ -296,6 +297,7 @@ protected function addRouteData($pages, $lang) /** @var PageInterface $page */ $page = $pages->get($path); + $rawroute = $page->rawRoute(); $header = $page->header(); $external_url = $this->ignore_external ? isset($header->external_url) : false; $protected_page = $this->ignore_protected ? isset($header->access) : false; @@ -346,7 +348,7 @@ protected function addRouteData($pages, $lang) - $this->route_data[$route][$lang] = $lang_route; + $this->route_data[$rawroute][$lang] = $lang_route; } } } From 3d0750528176c47a1955d7fa9c219acdfd871208 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Thu, 5 Oct 2023 12:46:06 -0600 Subject: [PATCH 09/10] udpated changelog --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 23bd7be..a789701 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,9 @@ -# v4.1.0 +# v5.0.0 ## mm/dd/2023 1. [](#new) * New capability to support "standalone" Sitemap News pages + * New XSL format for Sitemap News * Added a toggle for XSL transform support to be disabled 1. [](#improved) * Improved blueprint and created sections From 73f37fab15802a8af554fc04154377d0c808e0f1 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Thu, 5 Oct 2023 12:48:58 -0600 Subject: [PATCH 10/10] prepare for release --- CHANGELOG.md | 2 +- blueprints.yaml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a789701..92009a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,5 @@ # v5.0.0 -## mm/dd/2023 +## 10/05/2023 1. [](#new) * New capability to support "standalone" Sitemap News pages diff --git a/blueprints.yaml b/blueprints.yaml index 3dc0a88..fdf37b3 100644 --- a/blueprints.yaml +++ b/blueprints.yaml @@ -1,8 +1,8 @@ name: Sitemap type: plugin slug: sitemap -version: 4.0.0 -description: "Provide automatically generated **XML sitemaps** with this very useful, but simple to configure, Grav plugin." +version: 5.0.0 +description: "Provide automatically generated **XML sitemaps** with this very useful, as a simple to configure Grav plugin." icon: map-marker author: name: Team Grav