Skip to content

Commit

Permalink
display 404 page on invalid URL (#196)
Browse files Browse the repository at this point in the history
display 404 page on invalid URL

Signed-off-by: Jurj-Bogdan <[email protected]>
  • Loading branch information
Jurj-Bogdan authored Sep 7, 2024
1 parent ddabd86 commit ecc1f56
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions templates/partials/navigation.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ declare(strict_types=1);
/**
* @var League\Plates\Template\Template $this
*/
$currentUrl = rtrim(parse_url($this->serverurl(), PHP_URL_PATH), '/');

$isCurrentRoute = function (string $routeName) use ($currentUrl): bool {
$routeUrl = rtrim($this->url($routeName), '/');
return $currentUrl === $routeUrl;
};

$isRouteSubpath = function (string $routeName) use ($currentUrl): bool {
$routeUrl = rtrim($this->url($routeName), '/') . '/';
$currentUrl .= '/';
return str_starts_with($currentUrl, $routeUrl);
};
?>
<nav class="navbar navbar-expand-sm navbar-light bg-white fixed-top shadow">
<div class="container">
Expand All @@ -19,40 +31,37 @@ declare(strict_types=1);
<div class="collapse navbar-collapse" id="navbarCollapse">
<ul class="navbar-nav ml-auto">
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle<?= str_starts_with($this->url(), $this->url('about.overview')) || str_starts_with($this->url(), $this->url('security')) ? ' active' : '' ?>"
<a class="nav-link dropdown-toggle<?= $isRouteSubpath('about.overview') || $isRouteSubpath('security') ? ' active' : '' ?>"
href="#"
data-toggle="dropdown"
aria-expanded="false">About</a>
<div class="dropdown-menu">
<a class="dropdown-item<?= $this->url() === $this->url('about.overview') ? ' active' : '' ?>" href="<?= $this->url('about.overview') ?>">Overview</a>
<a class="dropdown-item<?= $this->url() === $this->url('about.tsc') || $this->url() === $this->url('about.join') ? ' active' : '' ?>" href="<?= $this->url('about.tsc') ?>">Technical Steering Committee</a>
<a class="dropdown-item<?= $this->url() === $this->url('about.foundation') ? ' active' : '' ?>" href="<?= $this->url('about.foundation') ?>">About the Foundation</a>
<a class="dropdown-item<?= str_starts_with($this->url(), $this->url('security')) ? ' active' : '' ?>" href="<?= $this->url('security') ?>">Security</a>
<a class="dropdown-item<?= $isCurrentRoute('about.overview') ? ' active' : '' ?>" href="<?= $this->url('about.overview') ?>">Overview</a>
<a class="dropdown-item<?= $isCurrentRoute('about.tsc') || $isCurrentRoute('about.join') ? ' active' : '' ?>" href="<?= $this->url('about.tsc') ?>">Technical Steering Committee</a>
<a class="dropdown-item<?= $isCurrentRoute('about.foundation') ? ' active' : '' ?>" href="<?= $this->url('about.foundation') ?>">About the Foundation</a>
<a class="dropdown-item<?= $isRouteSubpath('security') ? ' active' : '' ?>" href="<?= $this->url('security') ?>">Security</a>
</div>
</li>
<li class="nav-item">
<a class="nav-link<?= str_starts_with($this->url(), $this->url('blog')) ? ' active' : '' ?>"
href="<?= $this->url('blog') ?>"
<a class="nav-link<?= $isRouteSubpath('blog') ? ' active' : '' ?>"
href="<?= $this->url('blog') ?>">Blog</a>
</li>
<li class="nav-item">
<a class="nav-link" href="https://docs.laminas.dev">Docs</a>
</li>
<li class="nav-item">
<a class="nav-link<?= str_starts_with($this->url(), $this->url('community.participate')) ? ' active' : '' ?>"
href="<?= $this->url('community.participate') ?>"
<a class="nav-link<?= $isRouteSubpath('community.participate') ? ' active' : '' ?>"
href="<?= $this->url('community.participate') ?>">Community</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle<?= str_starts_with($this->url(), $this->url('app.support')) || str_starts_with($this->url(), $this->url('app.commercial-vendor-program')) ? ' active' : '' ?>"
<a class="nav-link dropdown-toggle<?= $isRouteSubpath('app.support') || $isRouteSubpath('app.commercial-vendor-program') ? ' active' : '' ?>"
href="<?= $this->url('app.support') ?>"
href="#"
data-toggle="dropdown"
aria-expanded="false">Support Laminas</a>
<div class="dropdown-menu">
<a class="dropdown-item<?= $this->url() === $this->url('app.support') ? ' active' : '' ?>" href="<?= $this->url('app.support') ?>">Overview</a>
<a class="dropdown-item<?= $isCurrentRoute('app.support') ? ' active' : '' ?>" href="<?= $this->url('app.support') ?>">Overview</a>
<a class="dropdown-item" href="https://crowdfunding.lfx.linuxfoundation.org/projects/laminas-project" target="_blank">Sponsor Laminas Development <i class="bi-box-arrow-up-right"></i></a>
<a class="dropdown-item<?= $this->url() === $this->url('app.commercial-vendor-program') ? ' active' : '' ?>" href="<?= $this->url('app.commercial-vendor-program') ?>">Commercial Vendor Program</a>
<a class="dropdown-item<?= $isCurrentRoute('app.commercial-vendor-program') ? ' active' : '' ?>" href="<?= $this->url('app.commercial-vendor-program') ?>">Commercial Vendor Program</a>
</div>
</li>
</ul>
Expand Down

0 comments on commit ecc1f56

Please sign in to comment.