add plugins
This commit is contained in:
@@ -0,0 +1 @@
|
||||
.DS_Store
|
||||
@@ -0,0 +1,101 @@
|
||||
# v1.9.2
|
||||
## 05/09/2019
|
||||
|
||||
1. [](#improved)
|
||||
* Enhanced HTML layout with XSL transformation [#24](https://github.com/getgrav/grav-plugin-sitemap/pull/24)
|
||||
* Global toggles for change frequency and priority [#52](https://github.com/getgrav/grav-plugin-sitemap/pull/52)
|
||||
* Added a meta name="robots" content="noindex" into the header for seo [#50](https://github.com/getgrav/grav-plugin-sitemap/pull/50)
|
||||
* Added `ru` and `uk` translations [#61](https://github.com/getgrav/grav-plugin-sitemap/pull/61)
|
||||
1. [](#bugfix)
|
||||
* Only add published translations to the sitemap [#43](https://github.com/getgrav/grav-plugin-sitemap/issues/43)
|
||||
|
||||
# v1.9.1
|
||||
## 04/21/2017
|
||||
|
||||
1. [](#bugfix)
|
||||
* Add a namespace xhtml for a international sitemap [#40](https://github.com/getgrav/grav-plugin-sitemap/pull/40)
|
||||
|
||||
# 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
|
||||
|
||||
1. [](#new)
|
||||
* Added `changefreq` and `priority` [#28](https://github.com/getgrav/grav-plugin-sitemap/pull/28)
|
||||
1. [](#improved)
|
||||
* Use `$page->canonical()` rather than `$page->permalink()` [#28](https://github.com/getgrav/grav-plugin-sitemap/pull/28)
|
||||
|
||||
# v1.7.0
|
||||
## 10/19/2016
|
||||
|
||||
1. [](#new)
|
||||
* Use new Grav feature to force output to be XML even when not passed `.xml` in URL
|
||||
|
||||
# v1.6.2
|
||||
## 07/14/2016
|
||||
|
||||
1. [](#bugfix)
|
||||
* Fix sitemap XLS in multilanguage
|
||||
|
||||
# v1.6.1
|
||||
## 05/30/2016
|
||||
|
||||
1. [](#bugfix)
|
||||
* Priority should be `float` in blueprints
|
||||
|
||||
# v1.6.0
|
||||
## 04/29/2016
|
||||
|
||||
1. [](#new)
|
||||
* Added compatibility with Grav Admin 1.1
|
||||
1. [](#improved)
|
||||
* Use some common translated strings in the blueprint
|
||||
|
||||
# v1.5.0
|
||||
## 01/06/2016
|
||||
|
||||
1. [](#new)
|
||||
* Added a default XSL file for the sitemap
|
||||
1. [](#improved)
|
||||
* Added a note to the README on how to only allow the link to the .xml sitemap
|
||||
1. [](#bugfix)
|
||||
* Fixed saving the `priority` option when adding it to a page through the Admin Plugin
|
||||
|
||||
# v1.4.2
|
||||
## 11/11/2015
|
||||
|
||||
1. [](#bugfix)
|
||||
* Escape the `loc` so it's properly parsed
|
||||
|
||||
# v1.4.1
|
||||
## 10/07/2015
|
||||
|
||||
1. [](#bugfix)
|
||||
* Avoid duplication of sitemap items
|
||||
|
||||
# v1.4.0
|
||||
## 08/25/2015
|
||||
|
||||
1. [](#improved)
|
||||
* Added blueprints for Grav Admin plugin
|
||||
1. [](#bugfix)
|
||||
* Don't show unpublished pages in sitemap
|
||||
|
||||
# v1.3.0
|
||||
## 02/25/2015
|
||||
|
||||
1. [](#new)
|
||||
* Added `ignores` list to allow certain routes to be left out of sitemap
|
||||
|
||||
# v1.2.0
|
||||
## 11/30/2014
|
||||
|
||||
1. [](#new)
|
||||
* ChangeLog started...
|
||||
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Grav
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -0,0 +1,66 @@
|
||||
# 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.
|
||||
|
||||
# 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.
|
||||
|
||||
## 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:
|
||||
|
||||
bin/gpm install sitemap
|
||||
|
||||
This will install the Sitemap plugin into your `/user/plugins` directory within Grav. Its files can be found under `/your/site/grav/user/plugins/sitemap`.
|
||||
|
||||
## 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).
|
||||
|
||||
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.
|
||||
|
||||
|
||||
# Usage
|
||||
|
||||
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
|
||||
|
||||
```
|
||||
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 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'
|
||||
```
|
||||
@@ -0,0 +1,91 @@
|
||||
name: Sitemap
|
||||
version: 1.9.2
|
||||
description: "Provide automatically generated **XML sitemaps** with this very useful, but simple to configure, Grav plugin."
|
||||
icon: map-marker
|
||||
author:
|
||||
name: Team Grav
|
||||
email: devs@getgrav.org
|
||||
url: http://getgrav.org
|
||||
homepage: https://github.com/getgrav/grav-plugin-sitemap
|
||||
keywords: sitemap, plugin, xml, map, index
|
||||
bugs: https://github.com/getgrav/grav-plugin-sitemap/issues
|
||||
license: MIT
|
||||
|
||||
dependencies:
|
||||
- { name: grav, version: '>=1.1.6' }
|
||||
|
||||
form:
|
||||
validation: strict
|
||||
fields:
|
||||
enabled:
|
||||
type: toggle
|
||||
label: PLUGIN_ADMIN.PLUGIN_STATUS
|
||||
highlight: 1
|
||||
default: 0
|
||||
options:
|
||||
1: PLUGIN_ADMIN.ENABLED
|
||||
0: PLUGIN_ADMIN.DISABLED
|
||||
validate:
|
||||
type: bool
|
||||
|
||||
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
|
||||
|
||||
route:
|
||||
type: text
|
||||
label: PLUGIN_SITEMAP.ROUTE
|
||||
placeholder: /sitemap
|
||||
validate:
|
||||
pattern: "/([a-z\-_]+/?)+"
|
||||
|
||||
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
|
||||
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"
|
||||
@@ -0,0 +1,47 @@
|
||||
form:
|
||||
fields:
|
||||
tabs:
|
||||
fields:
|
||||
options:
|
||||
type: tab
|
||||
|
||||
fields:
|
||||
|
||||
sitemap:
|
||||
type: section
|
||||
title: PLUGIN_SITEMAP.SITEMAP
|
||||
underline: true
|
||||
|
||||
fields:
|
||||
header.sitemap.changefreq:
|
||||
type: select
|
||||
label: PLUGIN_SITEMAP.HEADER_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
|
||||
|
||||
header.sitemap.priority:
|
||||
type: select
|
||||
label: PLUGIN_SITEMAP.HEADER_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
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
namespace Grav\Plugin;
|
||||
|
||||
class SitemapEntry
|
||||
{
|
||||
public $location;
|
||||
public $lastmod;
|
||||
public $changefreq;
|
||||
public $priority;
|
||||
public $image;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"project":"grav-plugin-sitemap",
|
||||
"platforms":{
|
||||
"grav":{
|
||||
"nodes":{
|
||||
"plugin":[
|
||||
{
|
||||
"source":"/",
|
||||
"destination":"/user/plugins/sitemap"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
en:
|
||||
PLUGIN_SITEMAP:
|
||||
SITEMAP: 'Sitemap'
|
||||
HEADER_CHANGEFREQ: 'Sitemap change frequency'
|
||||
HEADER_PRIORITY: 'Sitemap priority'
|
||||
CHANGEFREQ: 'Global - sitemap change frequency'
|
||||
CHANGEFREQ_DEFAULT: 'Use Global (daily)'
|
||||
CHANGEFREQ_ALWAYS: 'Always'
|
||||
CHANGEFREQ_HOURLY: 'Hourly'
|
||||
CHANGEFREQ_DAILY: 'Daily'
|
||||
CHANGEFREQ_WEEKLY: 'Weekly'
|
||||
CHANGEFREQ_MONTHLY: 'Monthly'
|
||||
CHANGEFREQ_YEARLY: 'Yearly'
|
||||
CHANGEFREQ_NEVER: 'Never'
|
||||
PRIORITY: 'Global - sitemap priority'
|
||||
PRIORITY_USE_GLOBAL: 'Use Global (1)'
|
||||
ROUTE: 'Route to sitemap'
|
||||
IGNORES: 'Ignore'
|
||||
IGNORES_HELP: 'URLs to ignore'
|
||||
ADDITIONS: 'Additional URLs'
|
||||
ADDITIONS_HELP: 'Add external URLs to the sitemap'
|
||||
LOCATION: 'The URL location'
|
||||
LASTMOD: 'Last modification e.g. 2017-04-06'
|
||||
|
||||
ru:
|
||||
PLUGIN_SITEMAP:
|
||||
SITEMAP: 'Карта сайта'
|
||||
HEADER_CHANGEFREQ: 'Частота обновления карты сайта'
|
||||
HEADER_PRIORITY: 'Приоритет карты сайта'
|
||||
CHANGEFREQ: 'Глобальное - частота обновления карты сайта'
|
||||
CHANGEFREQ_DEFAULT: 'Использовать глобальное (ежедневно)'
|
||||
CHANGEFREQ_ALWAYS: 'Всегда'
|
||||
CHANGEFREQ_HOURLY: 'Ежечасно'
|
||||
CHANGEFREQ_DAILY: 'Ежедневно'
|
||||
CHANGEFREQ_WEEKLY: 'Еженедельно'
|
||||
CHANGEFREQ_MONTHLY: 'Ежемесячно'
|
||||
CHANGEFREQ_YEARLY: 'Ежегодно'
|
||||
CHANGEFREQ_NEVER: 'Никогда'
|
||||
PRIORITY: 'Глобальное - приоритет карты сайта'
|
||||
PRIORITY_USE_GLOBAL: 'Использовать глобальное (1)'
|
||||
ROUTE: 'Маршрут к карте сайта'
|
||||
IGNORES: 'Игнорировать'
|
||||
IGNORES_HELP: 'URL-адреса для игнорирования'
|
||||
ADDITIONS: 'Дополнительные URL'
|
||||
ADDITIONS_HELP: 'Добавить внешние URL в карту сайта'
|
||||
LOCATION: 'Расположение URL'
|
||||
LASTMOD: 'Последнее изменение, например 2017-04-06'
|
||||
|
||||
uk:
|
||||
PLUGIN_SITEMAP:
|
||||
SITEMAP: 'Карта сайту'
|
||||
HEADER_CHANGEFREQ: 'Частота оновлення карти сайту'
|
||||
HEADER_PRIORITY: 'Пріоритет карти сайту'
|
||||
CHANGEFREQ: 'Глобальне - частота оновлення карти сайту'
|
||||
CHANGEFREQ_DEFAULT: 'Використовувати глобальне (щодня)'
|
||||
CHANGEFREQ_ALWAYS: 'Завжди'
|
||||
CHANGEFREQ_HOURLY: 'Погодинно'
|
||||
CHANGEFREQ_DAILY: 'Щодня'
|
||||
CHANGEFREQ_WEEKLY: 'Щотижня'
|
||||
CHANGEFREQ_MONTHLY: 'Щомісячно'
|
||||
CHANGEFREQ_YEARLY: 'Щорічно'
|
||||
CHANGEFREQ_NEVER: 'Ніколи'
|
||||
PRIORITY: 'Глобальне - пріоритет карта сайту'
|
||||
PRIORITY_USE_GLOBAL: 'Використовувати глобальний (1)'
|
||||
ROUTE: 'Маршрут до карти сайту'
|
||||
IGNORES: 'Ігнорувати'
|
||||
IGNORES_HELP: 'URL-адреси для ігнорування'
|
||||
ADDITIONS: 'Додаткові URL-адреси'
|
||||
ADDITIONS_HELP: 'Додати зовнішні URL-адреси до карти сайту'
|
||||
LOCATION: 'Розташування URL-адреси'
|
||||
LASTMOD: 'Остання модифікація, напр. 2017-04-06'
|
||||
@@ -0,0 +1,3 @@
|
||||
---
|
||||
template_format: xml
|
||||
---
|
||||
@@ -0,0 +1,158 @@
|
||||
<?php
|
||||
namespace Grav\Plugin;
|
||||
|
||||
use Grav\Common\Data;
|
||||
use Grav\Common\Page\Page;
|
||||
use Grav\Common\Plugin;
|
||||
use Grav\Common\Uri;
|
||||
use Grav\Common\Page\Pages;
|
||||
use RocketTheme\Toolbox\Event\Event;
|
||||
|
||||
class SitemapPlugin extends Plugin
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $sitemap = array();
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public static function getSubscribedEvents()
|
||||
{
|
||||
return [
|
||||
'onPluginsInitialized' => ['onPluginsInitialized', 0],
|
||||
'onBlueprintCreated' => ['onBlueprintCreated', 0]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable sitemap only if url matches to the configuration.
|
||||
*/
|
||||
public function onPluginsInitialized()
|
||||
{
|
||||
if ($this->isAdmin()) {
|
||||
$this->active = false;
|
||||
return;
|
||||
}
|
||||
|
||||
/** @var Uri $uri */
|
||||
$uri = $this->grav['uri'];
|
||||
$route = $this->config->get('plugins.sitemap.route');
|
||||
|
||||
if ($route && $route == $uri->path()) {
|
||||
|
||||
$this->enable([
|
||||
'onTwigTemplatePaths' => ['onTwigTemplatePaths', 0],
|
||||
'onPagesInitialized' => ['onPagesInitialized', 0],
|
||||
'onPageInitialized' => ['onPageInitialized', 0],
|
||||
'onTwigSiteVariables' => ['onTwigSiteVariables', 0]
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate data for the sitemap.
|
||||
*/
|
||||
public function onPagesInitialized()
|
||||
{
|
||||
require_once __DIR__ . '/classes/sitemapentry.php';
|
||||
|
||||
/** @var Pages $pages */
|
||||
$pages = $this->grav['pages'];
|
||||
$routes = array_unique($pages->routes());
|
||||
ksort($routes);
|
||||
|
||||
$ignores = (array) $this->config->get('plugins.sitemap.ignores');
|
||||
|
||||
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() && !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
|
||||
$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(true);
|
||||
|
||||
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()
|
||||
{
|
||||
// set a dummy page
|
||||
$page = new Page;
|
||||
$page->init(new \SplFileInfo(__DIR__ . '/pages/sitemap.md'));
|
||||
|
||||
unset($this->grav['page']);
|
||||
$this->grav['page'] = $page;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add current directory to twig lookup paths.
|
||||
*/
|
||||
public function onTwigTemplatePaths()
|
||||
{
|
||||
$this->grav['twig']->twig_paths[] = __DIR__ . '/templates';
|
||||
}
|
||||
|
||||
/**
|
||||
* Set needed variables to display the sitemap.
|
||||
*/
|
||||
public function onTwigSiteVariables()
|
||||
{
|
||||
$twig = $this->grav['twig'];
|
||||
$twig->template = 'sitemap.xml.twig';
|
||||
$twig->twig_vars['sitemap'] = $this->sitemap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extend page blueprints with feed configuration options.
|
||||
*
|
||||
* @param Event $event
|
||||
*/
|
||||
public function onBlueprintCreated(Event $event)
|
||||
{
|
||||
static $inEvent = false;
|
||||
|
||||
/** @var Data\Blueprint $blueprint */
|
||||
$blueprint = $event['blueprint'];
|
||||
if (!$inEvent && $blueprint->get('form/fields/tabs', null, '/')) {
|
||||
$inEvent = true;
|
||||
$blueprints = new Data\Blueprints(__DIR__ . '/blueprints/');
|
||||
$extends = $blueprints->get('sitemap');
|
||||
$blueprint->extend($extends, true);
|
||||
$inEvent = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
<xsl:stylesheet version="1.0"
|
||||
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
||||
xmlns:s="http://www.sitemaps.org/schemas/sitemap/0.9"
|
||||
exclude-result-prefixes="s"
|
||||
>
|
||||
<xsl:template match="/">
|
||||
<html>
|
||||
<head>
|
||||
<meta name="robots" content="noindex" />
|
||||
<title>
|
||||
XML Sitemap
|
||||
</title>
|
||||
<style type="text/css">
|
||||
@import url('//cdn.jsdelivr.net/pure/0.6.0/base-min.css');
|
||||
@import url('//cdn.jsdelivr.net/pure/0.6.0/pure-min.css');
|
||||
@import url('//cdn.jsdelivr.net/pure/0.6.0/grids-responsive-min.css');
|
||||
@import url('//fonts.googleapis.com/css?family=Raleway:100,300,400,700,900,100italic,300italic,400italic,700italic,900italic');
|
||||
.font_smooth {
|
||||
font-smooth: auto;
|
||||
text-shadow: 0 0 1px rgba(0, 0, 0, 0.2);
|
||||
text-rendering: auto;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-webkit-text-size-adjust: 100%
|
||||
}
|
||||
html {
|
||||
font-smooth: auto;
|
||||
text-shadow: 0 0 1px rgba(0, 0, 0, 0.2);
|
||||
text-rendering: auto;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-webkit-text-size-adjust: 100%;
|
||||
background-color: #fff
|
||||
}
|
||||
body {
|
||||
font-family: 'Raleway', sans-serif;
|
||||
font-size: 20px;
|
||||
line-height: 1.8em;
|
||||
letter-spacing: 0;
|
||||
text-align: left;
|
||||
color: #333
|
||||
}
|
||||
body {
|
||||
overflow: auto;
|
||||
padding: 20px
|
||||
}
|
||||
.clear {
|
||||
clear: both;
|
||||
float: none
|
||||
}
|
||||
a,
|
||||
a:link,
|
||||
a:visited {
|
||||
text-decoration: none;
|
||||
border-bottom: dotted 1px #333;
|
||||
color: #333
|
||||
}
|
||||
h1,h2,h3,h4,h5,h6 {
|
||||
font-family: Raleway;
|
||||
font-weight: 300;
|
||||
line-height: 1.2em;
|
||||
letter-spacing: 0px;
|
||||
color: #000
|
||||
}
|
||||
table {
|
||||
margin: 0 auto;
|
||||
}
|
||||
th {
|
||||
border: solid 1px #cbcbcb !important;
|
||||
text-align: center;
|
||||
background: #fff
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<table class="pure-table pure-table-striped" border="0">
|
||||
<thead>
|
||||
<tr>
|
||||
<th colspan="5">Sitemap</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th></th>
|
||||
<th>Location</th>
|
||||
<th>Last Modified</th>
|
||||
<th>Update Frequency</th>
|
||||
<th>Priority</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tfoot>
|
||||
</tfoot>
|
||||
<tbody>
|
||||
<xsl:for-each select="s:urlset/s:url">
|
||||
<xsl:sort select="s:loc" />
|
||||
<tr>
|
||||
<xsl:variable name="loc"><xsl:value-of select="s:loc"/></xsl:variable>
|
||||
<xsl:variable name="pno"><xsl:value-of select="position()"/></xsl:variable>
|
||||
<td><xsl:value-of select="$pno"/></td>
|
||||
<td><a href="{$loc}"><xsl:value-of select="s:loc"/></a></td>
|
||||
<td><xsl:value-of select="s:lastmod"/></td>
|
||||
<td><xsl:value-of select="s:changefreq"/></td>
|
||||
<td><xsl:value-of select="s:priority"/></td>
|
||||
</tr>
|
||||
</xsl:for-each>
|
||||
</tbody>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
</xsl:template>
|
||||
</xsl:stylesheet>
|
||||
@@ -0,0 +1,4 @@
|
||||
enabled: true
|
||||
route: '/sitemap'
|
||||
changefreq: daily
|
||||
priority: !!float 1
|
||||
@@ -0,0 +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" xmlns:xhtml="http://www.w3.org/1999/xhtml">
|
||||
{% 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>
|
||||
Reference in New Issue
Block a user