Skip to content

Commit

Permalink
Merge branch 'release/3.0.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
rhukster committed Feb 23, 2021
2 parents 9a773df + 9e8a972 commit 3ca8bfa
Show file tree
Hide file tree
Showing 7 changed files with 161 additions and 68 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# v3.0.1
## 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
## 01/30/2021

Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
150 changes: 87 additions & 63 deletions blueprints.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -22,7 +22,81 @@ 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

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
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
Expand All @@ -36,6 +110,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
Expand Down Expand Up @@ -93,68 +179,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
Expand Down
11 changes: 10 additions & 1 deletion languages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,18 @@ 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'
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: 'Карта сайта'
Expand Down Expand Up @@ -106,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:
Expand Down
19 changes: 16 additions & 3 deletions sitemap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -26,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;
Expand Down Expand Up @@ -101,10 +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';
$languages = $language->enabled() ? $language->getLanguages() : [$default_lang];
$active_lang = $language->getActive() ?? $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'));
Expand All @@ -119,14 +124,21 @@ 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);
$pages->reset();
$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) {
Expand Down Expand Up @@ -166,7 +178,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;
Expand Down
4 changes: 3 additions & 1 deletion sitemap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ 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
changefreq: daily
include_priority: true
priority: !!float 1
additions: []
additions: []
multilang_enabled: true
31 changes: 31 additions & 0 deletions templates/sitemap.html.twig
Original file line number Diff line number Diff line change
@@ -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 %}

<table class="sitemap">
<thead>
<tr>
<th>#</th>
<th>{{ 'PLUGIN_SITEMAP.TITLE_TITLE'|t }}</th>
<th>{{ 'PLUGIN_SITEMAP.TITLE_LOCATION'|t }}</th>
<th>{{ 'PLUGIN_SITEMAP.TITLE_LASTMOD'|t }}</th>
</tr>
</thead>
<tbody>
{% for entry in sitemap %}
{% if lang is null or entry.lang == lang %}
<tr>
<td>{{ count }}</td>
<td><a href="{{ entry.location }}">{{ entry.title ?: 'PLUGIN_SITEMAP.UNTITLED'|t }}</a></td>
<td><a href="{{ entry.location }}">{{ entry.location }}</a></td>
<td>{{ entry.lastmod }}</td>
</tr>
{% set count = count + 1 %}
{% endif %}
{% endfor %}
</tbody>
</table>
{% endblock %}

0 comments on commit 3ca8bfa

Please sign in to comment.