added a default route alias - particularly useful for multilane switching

This commit is contained in:
Andy Miller
2015-07-04 10:11:40 -06:00
parent 740ea2e86d
commit 79f5aaa032
2 changed files with 32 additions and 8 deletions

View File

@@ -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.
*

View File

@@ -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;
}
}
}