From 49d9e4a5bbe5408ba1cc0616937bb5f3fdeca5f3 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Mon, 8 Feb 2021 15:12:44 -0700 Subject: [PATCH 1/4] reorganized blueprint to match yaml --- blueprints.yaml | 136 ++++++++++++++++++++++++++---------------------- 1 file changed, 74 insertions(+), 62 deletions(-) diff --git a/blueprints.yaml b/blueprints.yaml index 2241ba6..bb1dd47 100644 --- a/blueprints.yaml +++ b/blueprints.yaml @@ -22,7 +22,69 @@ form: enabled: type: toggle label: PLUGIN_ADMIN.PLUGIN_STATUS + highlight: 0 + default: 0 + options: + 1: PLUGIN_ADMIN.ENABLED + 0: PLUGIN_ADMIN.DISABLED + validate: + type: bool + + ignore_external: + type: toggle + label: PLUGIN_SITEMAP.IGNORE_EXTERNAL + help: PLUGIN_SITEMAP.IGNORE_EXTERNAL_HELP + highlight: 1 + default: 1 + options: + 1: PLUGIN_ADMIN.ENABLED + 0: PLUGIN_ADMIN.DISABLED + validate: + type: bool + + ignore_protected: + type: toggle + label: PLUGIN_SITEMAP.IGNORE_PROTECTED + help: PLUGIN_SITEMAP.IGNORE_PROTECTED_HELP + highlight: 1 + default: 1 + options: + 1: PLUGIN_ADMIN.ENABLED + 0: PLUGIN_ADMIN.DISABLED + validate: + type: bool + + ignore_redirect: + type: toggle + label: PLUGIN_SITEMAP.IGNORE_REDIRECT + help: PLUGIN_SITEMAP.IGNORE_REDIRECT_HELP highlight: 1 + default: 1 + options: + 1: PLUGIN_ADMIN.ENABLED + 0: PLUGIN_ADMIN.DISABLED + 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-_]+/?)+" + + html_support: + type: toggle + label: PLUGIN_SITEMAP.HTML_SUPPORT + help: PLUGIN_SITEMAP.HTML_SUPPORT_HELP + highlight: 0 default: 0 options: 1: PLUGIN_ADMIN.ENABLED @@ -36,6 +98,18 @@ form: label: PLUGIN_SITEMAP.URLSET help: PLUGIN_SITEMAP.URLSET_HELP + short_date_format: + type: toggle + label: PLUGIN_ADMIN.SHORT_DATE_FORMAT + help: PLUGIN_ADMIN.SHORT_DATE_FORMAT_HELP + highlight: 1 + default: 0 + options: + 1: PLUGIN_ADMIN.ENABLED + 0: PLUGIN_ADMIN.DISABLED + validate: + type: bool + include_changefreq: type: toggle label: PLUGIN_SITEMAP.INCLUDE_CHANGEFREQ @@ -93,68 +167,6 @@ form: validate: type: float - short_date_format: - type: toggle - label: PLUGIN_ADMIN.SHORT_DATE_FORMAT - help: PLUGIN_ADMIN.SHORT_DATE_FORMAT_HELP - highlight: 1 - default: 0 - options: - 1: PLUGIN_ADMIN.ENABLED - 0: PLUGIN_ADMIN.DISABLED - validate: - type: bool - - route: - type: text - label: PLUGIN_SITEMAP.ROUTE - placeholder: /sitemap - validate: - pattern: "/([a-z-_]+/?)+" - - ignore_external: - type: toggle - label: PLUGIN_SITEMAP.IGNORE_EXTERNAL - help: PLUGIN_SITEMAP.IGNORE_EXTERNAL_HELP - highlight: 1 - default: 1 - options: - 1: PLUGIN_ADMIN.ENABLED - 0: PLUGIN_ADMIN.DISABLED - validate: - type: bool - - ignore_protected: - type: toggle - label: PLUGIN_SITEMAP.IGNORE_PROTECTED - help: PLUGIN_SITEMAP.IGNORE_PROTECTED_HELP - highlight: 1 - default: 1 - options: - 1: PLUGIN_ADMIN.ENABLED - 0: PLUGIN_ADMIN.DISABLED - validate: - type: bool - - ignore_redirect: - type: toggle - label: PLUGIN_SITEMAP.IGNORE_REDIRECT - help: PLUGIN_SITEMAP.IGNORE_REDIRECT_HELP - highlight: 1 - default: 1 - options: - 1: PLUGIN_ADMIN.ENABLED - 0: PLUGIN_ADMIN.DISABLED - validate: - type: bool - - ignores: - type: array - label: PLUGIN_SITEMAP.IGNORES - help: PLUGIN_SITEMAP.IGNORES_HELP - value_only: true - placeholder_value: '/ignore-this-route' - additions: type: list label: PLUGIN_SITEMAP.ADDITIONS From a69208aa081799626a1294dbfc2e45f1e9d22ee2 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Mon, 8 Feb 2021 15:13:32 -0700 Subject: [PATCH 2/4] Add support for HTML sitemap --- CHANGELOG.md | 6 ++++++ README.md | 7 +++++++ languages.yaml | 7 ++++++- sitemap.php | 14 ++++++++++++-- sitemap.yaml | 1 + templates/sitemap.html.twig | 31 +++++++++++++++++++++++++++++++ 6 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 templates/sitemap.html.twig diff --git a/CHANGELOG.md b/CHANGELOG.md index 226cdbe..36505df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# v3.0.1 +## mm/dd/2021 + +1. [](#new) + * Added support for new optional `html_support` option that allows you to render the sitemap as an HTML page in your site when you access the sitemap URL with no extension or `.html`. Can be customized and extended in your theme as needed. + # v3.0.0 ## 01/30/2021 diff --git a/README.md b/README.md index 440a2a6..e59b778 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,7 @@ ignores: - /ignore-this-route - /ignore-children-of-this-route/.* whitelist: +html_support: false urlset: 'http://www.sitemaps.org/schemas/sitemap/0.9' short_date_format: true include_changefreq: true @@ -97,6 +98,12 @@ If you want your sitemap to only be accessible via `sitemap.xml` for example, se `Redirect 301 /sitemap /sitemap.xml` +## HTML Support + +As of Sitemap version `3.0.1` you can enable `html_support` in the configuration and then when you go to `/sitemap` or `/sitemap.html` you will view an HTML version of the sitemap per the `templates/sitemap.html.twig` template. + +You can copy and extend this Twig template in your theme to customize it for your needs. + ## 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: diff --git a/languages.yaml b/languages.yaml index a7a7d65..8d61a0a 100644 --- a/languages.yaml +++ b/languages.yaml @@ -34,7 +34,12 @@ en: INCLUDE_PRIORITY: 'Include Priority' SHORT_DATE_FORMAT: 'Short Date Format' SHORT_DATE_FORMAT_HELP: 'Use Short or Long Date format' - + HTML_SUPPORT: 'HTML Support' + HTML_SUPPORT_HELP: 'Use "sitemap.html.twig" if no extension or ".html" passed in the URL' + TITLE_LOCATION: 'Location' + TITLE_TITLE: 'Title' + TITLE_LASTMOD: 'Last Modified' + UNTITLED: 'Untitled' ru: PLUGIN_SITEMAP: SITEMAP: 'Карта сайта' diff --git a/sitemap.php b/sitemap.php index 05b7d87..3dfb150 100644 --- a/sitemap.php +++ b/sitemap.php @@ -9,6 +9,7 @@ use Grav\Common\Page\Interfaces\PageInterface; use Grav\Common\Page\Page; use Grav\Common\Plugin; +use Grav\Common\Twig\Twig; use Grav\Common\Uri; use Grav\Common\Page\Pages; use Grav\Common\Utils; @@ -104,6 +105,7 @@ public function onPagesInitialized() /** @var Language $language */ $language = $this->grav['language']; $default_lang = $language->getDefault() ?: 'en'; + $active_lang = $language->getActive() ?? $default_lang; $languages = $language->enabled() ? $language->getLanguages() : [$default_lang]; $this->multilang_skiplang_prefix = $this->config->get('system.languages.include_default_lang') ? '' : $language->getDefault(); @@ -119,7 +121,7 @@ public function onPagesInitialized() $this->ignore_protected = $this->config->get('plugins.sitemap.ignore_protected'); $this->ignore_redirect = $this->config->get('plugins.sitemap.ignore_redirect'); - // Gather data + // Gather data for all languages foreach ($languages as $lang) { $language->init(); $language->setActive($lang); @@ -127,6 +129,13 @@ public function onPagesInitialized() $this->addRouteData($pages, $lang); } + // Reset back to active language + if ($language->enabled() && $language->getActive() !== $active_lang) { + $language->init(); + $language->setActive($active_lang); + $pages->reset(); + } + // Build sitemap foreach ($languages as $lang) { foreach($this->route_data as $route => $route_data) { @@ -166,7 +175,8 @@ public function onPageInitialized($event) $route = $this->config->get('plugins.sitemap.route'); if (is_null($page) || $page->route() !== $route) { - $extension = $this->grav['uri']->extension() ?? 'xml'; + $html_support = $this->config->get('plugins.sitemap.html_support', false); + $extension = $this->grav['uri']->extension() ?? ($html_support ? 'html': 'xml'); // set a dummy page $page = new Page; diff --git a/sitemap.yaml b/sitemap.yaml index 7759c7b..d65646a 100644 --- a/sitemap.yaml +++ b/sitemap.yaml @@ -5,6 +5,7 @@ ignore_protected: true ignore_redirect: true ignores: whitelist: +html_support: false urlset: 'http://www.sitemaps.org/schemas/sitemap/0.9' short_date_format: true include_changefreq: true diff --git a/templates/sitemap.html.twig b/templates/sitemap.html.twig new file mode 100644 index 0000000..b0cf5ea --- /dev/null +++ b/templates/sitemap.html.twig @@ -0,0 +1,31 @@ +{% extends 'partials/base.html.twig' %} + +{% block content %} + {% set language = grav.language %} + {% set lang = language.enabled ? (language.active ?: language.default) : null %} + {% set count = 1 %} + + + + + + + + + + + + {% for entry in sitemap %} + {% if lang is null or entry.lang == lang %} + + + + + + + {% set count = count + 1 %} + {% endif %} + {% endfor %} + +
#{{ 'PLUGIN_SITEMAP.TITLE_TITLE'|t }}{{ 'PLUGIN_SITEMAP.TITLE_LOCATION'|t }}{{ 'PLUGIN_SITEMAP.TITLE_LASTMOD'|t }}
{{ count }}{{ entry.title ?: 'PLUGIN_SITEMAP.UNTITLED'|t }}{{ entry.location }}{{ entry.lastmod }}
+{% endblock %} From f01a7e5a1e93510968bede8d52c99fb86d269b16 Mon Sep 17 00:00:00 2001 From: Florian Schlittenbauer Date: Tue, 23 Feb 2021 19:48:06 +0100 Subject: [PATCH 3/4] add multilang setting (#96) --- blueprints.yaml | 12 ++++++++++++ languages.yaml | 4 ++++ sitemap.php | 5 ++++- sitemap.yaml | 3 ++- 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/blueprints.yaml b/blueprints.yaml index bb1dd47..95a9280 100644 --- a/blueprints.yaml +++ b/blueprints.yaml @@ -30,6 +30,18 @@ form: validate: type: bool + multilang_enabled: + type: toggle + label: PLUGIN_SITEMAP.MULTILANG_ENABLED + help: PLUGIN_SITEMAP.MULTILANG_ENABLED_HELP + highlight: 1 + default: 1 + options: + 1: PLUGIN_ADMIN.ENABLED + 0: PLUGIN_ADMIN.DISABLED + validate: + type: bool + ignore_external: type: toggle label: PLUGIN_SITEMAP.IGNORE_EXTERNAL diff --git a/languages.yaml b/languages.yaml index 8d61a0a..1ebd2b7 100644 --- a/languages.yaml +++ b/languages.yaml @@ -30,6 +30,8 @@ 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!' + MULTILANG_ENABLED: 'Multi-Lang Features' + MULTILANG_ENABLED_HELP: 'Enables support for multilanguage features' INCLUDE_CHANGEFREQ: 'Include Change Frequency' INCLUDE_PRIORITY: 'Include Priority' SHORT_DATE_FORMAT: 'Short Date Format' @@ -111,6 +113,8 @@ de: ADDITIONS_HELP: 'Füge externe URLs zur Sitemap hinzu' LOCATION: 'Seiten Pfad' LASTMOD: 'Letzte Änderung e.g. 2017-04-06' + MULTILANG_ENABLED: 'Mehrsprachigkeit' + MULTILANG_ENABLED_HELP: 'Aktiviert Funktionen zur Mehrsprachigkeit' zh: PLUGIN_SITEMAP: diff --git a/sitemap.php b/sitemap.php index 3dfb150..ae23dfa 100644 --- a/sitemap.php +++ b/sitemap.php @@ -27,6 +27,7 @@ class SitemapPlugin extends Plugin protected $multilang_skiplang_prefix = null; protected $multilang_include_fallbacks = false; + protected $multilang_enabled = true; protected $datetime_format = null; protected $include_change_freq = true; protected $default_change_freq = null; @@ -102,11 +103,13 @@ public function onPagesInitialized() $this->sitemap = $cache->fetch($cache_id); if ($this->sitemap === false) { + $this->multilang_enabled = $this->config->get('plugins.sitemap.multilang_enabled'); + /** @var Language $language */ $language = $this->grav['language']; $default_lang = $language->getDefault() ?: 'en'; $active_lang = $language->getActive() ?? $default_lang; - $languages = $language->enabled() ? $language->getLanguages() : [$default_lang]; + $languages = $this->multilang_enabled && $language->enabled() ? $language->getLanguages() : [$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')); diff --git a/sitemap.yaml b/sitemap.yaml index d65646a..9d20ddb 100644 --- a/sitemap.yaml +++ b/sitemap.yaml @@ -12,4 +12,5 @@ include_changefreq: true changefreq: daily include_priority: true priority: !!float 1 -additions: [] \ No newline at end of file +additions: [] +multilang_enabled: true From 9e8a9724540e8b932e8893a9c71cd598ba6f0197 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Tue, 23 Feb 2021 15:11:42 -0700 Subject: [PATCH 4/4] prepare for release --- CHANGELOG.md | 3 ++- blueprints.yaml | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 36505df..05987d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,8 @@ # v3.0.1 -## mm/dd/2021 +## 02/23/2021 1. [](#new) + * Added ability to disable multi-lang completely to replicate prior functionality [#96](https://github.com/getgrav/grav-plugin-sitemap/pull/96) * Added support for new optional `html_support` option that allows you to render the sitemap as an HTML page in your site when you access the sitemap URL with no extension or `.html`. Can be customized and extended in your theme as needed. # v3.0.0 diff --git a/blueprints.yaml b/blueprints.yaml index 95a9280..7e45980 100644 --- a/blueprints.yaml +++ b/blueprints.yaml @@ -1,7 +1,7 @@ name: Sitemap type: plugin slug: sitemap -version: 3.0.0 +version: 3.0.1 description: "Provide automatically generated **XML sitemaps** with this very useful, but simple to configure, Grav plugin." icon: map-marker author: