Skip to content

Commit

Permalink
Merge branch 'release/1.9.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
rhukster committed Apr 19, 2017
2 parents e304267 + 2736baf commit fb12429
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 22 deletions.
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# v1.9.0
## 04/19/2017

1. [](#new)
* Added wildcard ignores [#34](https://github.com/getgrav/grav-plugin-sitemap/pull/34)
* Added ability to add external URLs to sitemap [#35](https://github.com/getgrav/grav-plugin-sitemap/pull/35)
* Added page-level ignores [#37](https://github.com/getgrav/grav-plugin-sitemap/pull/37)
* Added multilanguage support [#36](https://github.com/getgrav/grav-plugin-sitemap/pull/36)

# v1.8.0
## 03/14/2017

Expand Down Expand Up @@ -59,7 +68,7 @@

1. [](#improved)
* Added blueprints for Grav Admin plugin
1. [](#bugfix)
1. [](#bugfix)
* Don't show unpublished pages in sitemap

# v1.3.0
Expand Down
24 changes: 21 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# Installation

Installing the Sitemap plugin can be done in one of two ways. Our GPM (Grav Package Manager) installation method enables you to quickly and easily install the plugin with a simple terminal command, while the manual method enables you to do so via a zip file.
Installing the Sitemap plugin can be done in one of two ways. Our GPM (Grav Package Manager) installation method enables you to quickly and easily install the plugin with a simple terminal command, while the manual method enables you to do so via a zip file.

## GPM Installation (Preferred)

Expand All @@ -29,20 +29,38 @@ You should now have all the plugin files under

The `sitemap` plugin works out of the box. You can just go directly to `http://yoursite.com/sitemap` and you will see the generated `XML`.

# Config Defaults
## Config Defaults

```
enabled: true
route: '/sitemap'
ignores:
- /blog/blog-post-to-ignore
- /ignore-this-route
- /ignore-children-of-this-route/.*
```

You can ignore your own pages by providing a list of routes to ignore.
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:

```
sitemap:
ignore: true
```

## Only allow access to the .xml file

If you want your sitemap to only be accessible via `sitemap.xml` for example, set the route to `/sitemap` and add this to your `.htaccess` file:

`Redirect 301 /sitemap /sitemap.xml`


## 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:

```
additions:
-
location: /not-a-grav-url
lastmod: '2017-04-06'
```
17 changes: 16 additions & 1 deletion blueprints.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Sitemap
version: 1.8.0
version: 1.9.0
description: "Provide automatically generated **XML sitemaps** with this very useful, but simple to configure, Grav plugin."
icon: map-marker
author:
Expand Down Expand Up @@ -41,3 +41,18 @@ form:
help: "URLs to ignore"
value_only: true
placeholder_value: /ignore-this-route

additions:
type: list
label: Additional URLs
help: "Add external URLs to the sitemap"

fields:
.location:
type: text
label: The URL location
placeholder: "/not-a-grav-url"
.lastmod:
type: text
label: "Last modification e.g. 2017-04-06"
placeholder: "2017-04-06"
29 changes: 27 additions & 2 deletions sitemap.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,45 @@ public function onPagesInitialized()

foreach ($routes as $route => $path) {
$page = $pages->get($path);
$header = $page->header();
$page_ignored = isset($header->sitemap['ignore']) ? $header->sitemap['ignore'] : false;

if ($page->published() && $page->routable() && !in_array($page->route(), $ignores)) {
if ($page->published() && $page->routable() && !preg_match(sprintf("@^(%s)$@i", implode('|', $ignores)), $page->route()) && !$page_ignored) {
$entry = new SitemapEntry();
$entry->location = $page->canonical();
$entry->lastmod = date('Y-m-d', $page->modified());

// optional changefreq & priority that you can set in the page header
$header = $page->header();
$entry->changefreq = (isset($header->sitemap['changefreq'])) ? $header->sitemap['changefreq'] : $this->config->get('plugins.sitemap.changefreq');
$entry->priority = (isset($header->sitemap['priority'])) ? $header->sitemap['priority'] : $this->config->get('plugins.sitemap.priority');

if (count($this->config->get('system.languages.supported', [])) > 0) {
$entry->translated = $page->translatedLanguages();

foreach($entry->translated as $lang => $page_route) {
$page_route = $page->rawRoute();
if ($page->home()) {
$page_route = '/';
}

$entry->translated[$lang] = $page_route;
}
}

$this->sitemap[$route] = $entry;
}
}

$rootUrl = $this->grav['uri']->rootUrl(true) . $pages->base();
$additions = (array) $this->config->get('plugins.sitemap.additions');

foreach ($additions as $addition) {
$entry = new SitemapEntry();
$entry->location = $rootUrl . $addition['location'];
$entry->lastmod = $addition['lastmod'];

$this->sitemap[] = $entry;
}
}

public function onPageInitialized()
Expand Down
3 changes: 0 additions & 3 deletions sitemap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,3 @@ enabled: true
route: '/sitemap'
changefreq: daily
priority: !!float 1
ignores:
- /blog/blog-post-to-ignore
- /ignore-this-route
29 changes: 17 additions & 12 deletions templates/sitemap.xml.twig
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="{{ uri.rootUrl }}/user/plugins/sitemap/sitemap.xsl"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
{% for entry in sitemap %}
<url>
<loc>{{ entry.location|e }}</loc>
<lastmod>{{ entry.lastmod }}</lastmod>
{% if entry.changefreq %}
<changefreq>{{ entry.changefreq }}</changefreq>
{% endif %}
{% if entry.priority %}
<priority>{{ entry.priority|number_format(1) }}</priority>
{% endif %}
</url>
{% endfor %}
{% for entry in sitemap %}
<url>
<loc>{{ entry.location|e }}</loc>
{% if entry.translated %}
{% for language, page_route in entry.translated %}
<xhtml:link rel="alternate" hreflang="{{ language }}" href="{{uri.rootUrl(true)}}{{grav.language.getLanguageURLPrefix(language)}}{{ page_route }}" />
{% endfor %}
{% endif %}
<lastmod>{{ entry.lastmod }}</lastmod>
{% if entry.changefreq %}
<changefreq>{{ entry.changefreq }}</changefreq>
{% endif %}
{% if entry.priority %}
<priority>{{ entry.priority|number_format(1) }}</priority>
{% endif %}
</url>
{% endfor %}
</urlset>

0 comments on commit fb12429

Please sign in to comment.