Add simple redirect: header option for Page

This commit is contained in:
Andy Miller
2015-09-11 10:21:25 -06:00
parent 572bb429ce
commit bef9e3c5ce
2 changed files with 27 additions and 3 deletions

View File

@@ -42,6 +42,7 @@ class Page
protected $path;
protected $extension;
protected $id;
protected $parent;
protected $template;
protected $expires;
@@ -56,7 +57,7 @@ class Page
protected $routes;
protected $routable;
protected $modified;
protected $id;
protected $redirect;
protected $items;
protected $header;
protected $frontmatter;
@@ -303,6 +304,9 @@ class Page
if (isset($this->header->visible)) {
$this->visible = (bool) $this->header->visible;
}
if (isset($this->header->redirect)) {
$this->redirect = trim($this->header->redirect);
}
if (isset($this->header->order_dir)) {
$this->order_dir = trim($this->header->order_dir);
}
@@ -1393,6 +1397,20 @@ class Page
return $this->modified;
}
/**
* Gets the redirect set in the header.
*
* @param string $var redirect url
* @return array
*/
public function redirect($var = null)
{
if ($var !== null) {
$this->redirect = $var;
}
return $this->redirect;
}
/**
* Gets and sets the option to show the etag header for the page.
*

View File

@@ -271,7 +271,13 @@ class Pages
$page = isset($this->routes[$url]) ? $this->get($this->routes[$url]) : null;
// If the page cannot be reached, look into site wide redirects, routes + wildcards
if (!$all && (!$page || !$page->routable())) {
if (!$all && (!$page || !$page->routable() || $page->redirect())) {
// If the page is a simple redirect, just do it.
if ($page->redirect()) {
$this->grav->redirectLangSafe($page->redirect());
}
/** @var Config $config */
$config = $this->grav['config'];
@@ -289,7 +295,7 @@ class Pages
$this->grav->redirectLangSafe($found);
}
} catch (ErrorException $e) {
$this->grav['log']->error('site.redirects: '. $pattern . '-> ' . $e->getMessage());
$this->grav['log']->error('site.redirects: ' . $pattern . '-> ' . $e->getMessage());
}
}