mirror of
https://github.com/getgrav/grav.git
synced 2026-07-19 21:41:14 +02:00
added a default route alias - particularly useful for multilane switching
This commit is contained in:
@@ -47,6 +47,7 @@ class Page
|
||||
protected $unpublish_date;
|
||||
protected $slug;
|
||||
protected $route;
|
||||
protected $raw_route;
|
||||
protected $url;
|
||||
protected $routes;
|
||||
protected $routable;
|
||||
@@ -115,8 +116,6 @@ class Page
|
||||
$this->header();
|
||||
$this->date();
|
||||
$this->metadata();
|
||||
$this->slug();
|
||||
$this->route();
|
||||
$this->url();
|
||||
$this->visible();
|
||||
$this->modularTwig($this->slug[0] == '_');
|
||||
@@ -1174,7 +1173,6 @@ class Page
|
||||
}
|
||||
|
||||
if (empty($this->route)) {
|
||||
|
||||
// calculate route based on parent slugs
|
||||
$baseRoute = $this->parent ? (string) $this->parent()->route() : null;
|
||||
$this->route = isset($baseRoute) ? $baseRoute . '/'. $this->slug() : null;
|
||||
@@ -1189,6 +1187,24 @@ class Page
|
||||
return $this->route;
|
||||
}
|
||||
|
||||
public function rawRoute($var = null)
|
||||
{
|
||||
if ($var !== null) {
|
||||
$this->raw_route = $var;
|
||||
}
|
||||
|
||||
if (empty($this->raw_route)) {
|
||||
$baseRoute = $this->parent ? (string) $this->parent()->rawRoute() : null;
|
||||
|
||||
$regex = '/^[0-9]+\./u';
|
||||
$slug = preg_replace($regex, '', $this->folder);
|
||||
|
||||
$this->raw_route = isset($baseRoute) ? $baseRoute . '/'. $slug : null;
|
||||
}
|
||||
|
||||
return $this->raw_route;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the route aliases for the page based on page headers.
|
||||
*
|
||||
|
||||
@@ -696,21 +696,29 @@ class Pages
|
||||
// process taxonomy
|
||||
$taxonomy->addTaxonomy($page);
|
||||
|
||||
// add route
|
||||
$route = $page->route();
|
||||
$this->routes[$route] = $page->path();
|
||||
$raw_route = $page->rawRoute();
|
||||
$page_path = $page->path();
|
||||
|
||||
// add canonical
|
||||
// add regular route
|
||||
$this->routes[$route] = $page_path;
|
||||
|
||||
// add raw route
|
||||
if ($raw_route != $route) {
|
||||
$this->routes[$raw_route] = $page_path;
|
||||
}
|
||||
|
||||
// add canonical route
|
||||
$route_canonical = $page->routeCanonical();
|
||||
if ($route_canonical && ($route !== $route_canonical)) {
|
||||
$this->routes[$route_canonical] = $page->path();
|
||||
$this->routes[$route_canonical] = $page_path;
|
||||
}
|
||||
|
||||
// add aliases to routes list if they are provided
|
||||
$route_aliases = $page->routeAliases();
|
||||
if ($route_aliases) {
|
||||
foreach ($route_aliases as $alias) {
|
||||
$this->routes[$alias] = $page->path();
|
||||
$this->routes[$alias] = $page_path;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user