mirror of
https://github.com/getgrav/grav.git
synced 2026-02-10 16:47:49 +01:00
Add simple redirect: header option for Page
This commit is contained in:
@@ -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.
|
||||
*
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user