Fix design validation, canonical routes, media headers and favicon
This commit is contained in:
@@ -4,11 +4,14 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Content\Assets;
|
||||
use App\Content\Html;
|
||||
use App\Content\Repository;
|
||||
use App\Content\View;
|
||||
use FastRoute\Dispatcher;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
use Webman\Route;
|
||||
|
||||
final class SiteController
|
||||
{
|
||||
@@ -215,14 +218,21 @@ final class SiteController
|
||||
"User-agent: *\nAllow: /\nDisallow: /admin\nSitemap: " . View::absolute('/sitemap.xml') . "\n");
|
||||
}
|
||||
|
||||
public function favicon(Request $request): Response
|
||||
{
|
||||
return View::redirect(Assets::DEFAULT_ICON, 301);
|
||||
}
|
||||
|
||||
public function missing(Request $request): Response
|
||||
{
|
||||
$path = $request->path();
|
||||
if ($request->method() === 'GET' && strlen($path) > 1 && str_ends_with($path, '/')) {
|
||||
if (in_array($request->method(), ['GET', 'HEAD'], true) && strlen($path) > 1 && str_ends_with($path, '/')) {
|
||||
$normal = rtrim($path, '/');
|
||||
$entry = preg_match('~^/(?:admin|account)(?:/|$)~D', $normal)
|
||||
&& Route::dispatch($request->method(), $normal)[0] === Dispatcher::FOUND;
|
||||
$single = preg_match('~^/[a-z0-9-]+$~D', $normal);
|
||||
$known = $single && ((new Repository())->page(substr($normal, 1))['status'] ?? null) === 'published' && $normal !== '/home';
|
||||
if ($known || preg_match('~^/articles(?:/[a-z0-9-]+){1,2}$~D', $normal)) {
|
||||
if ($entry || ($single && $normal !== '/home' && ((new Repository())->page(substr($normal, 1))['status'] ?? null) === 'published')
|
||||
|| preg_match('~^/articles(?:/[a-z0-9-]+){1,2}$~D', $normal)) {
|
||||
$query = $request->queryString();
|
||||
|
||||
return View::redirect($normal . ($query !== '' ? '?' . $query : ''), 301);
|
||||
|
||||
Reference in New Issue
Block a user