Add SEO metadata and git repo link to admin pages
Makes login page indexable with description/OG/canonical options, keeps authenticated dashboard noindex, and adds a footer link to the source repository.
This commit is contained in:
parent
eff95ad8a6
commit
a67ca468ef
2 changed files with 28 additions and 5 deletions
26
lib.php
26
lib.php
|
|
@ -326,20 +326,24 @@ function admin_redirect(string $url): never
|
|||
exit;
|
||||
}
|
||||
|
||||
function admin_page(string $title, string $active, callable $body): void
|
||||
function admin_page(string $title, string $active, callable $body, array $opts = []): void
|
||||
{
|
||||
$user = admin_current_user();
|
||||
$flashes = admin_flashes();
|
||||
$site = (string) admin_cfg('site_name', 'Oscar Admin');
|
||||
$shared = (string) admin_cfg('shared_style_path', 'assets/style.css');
|
||||
$sharedHref = file_exists(__DIR__ . '/' . ltrim($shared, '/')) ? $shared : $shared;
|
||||
$indexable = !empty($opts['indexable']);
|
||||
$desc = trim((string) ($opts['description'] ?? ($indexable ? 'Oscar Admin is a standalone web admin dashboard for Open OSCAR Server. Manage users, sessions, rooms, BART, buddy lists, and more.' : '')));
|
||||
$canonical = trim((string) ($opts['canonical'] ?? ''));
|
||||
$repoUrl = trim((string) ($opts['repo_url'] ?? 'https://git.claytonia.net/Clarth/oscar-admin'));
|
||||
|
||||
if (!headers_sent()) {
|
||||
header('X-Frame-Options: DENY');
|
||||
header('X-Content-Type-Options: nosniff');
|
||||
header('Referrer-Policy: no-referrer');
|
||||
header('Permissions-Policy: camera=(), microphone=(), geolocation=()');
|
||||
header('X-Robots-Tag: noindex, nofollow');
|
||||
header('X-Robots-Tag: ' . ($indexable ? 'index, follow' : 'noindex, nofollow'));
|
||||
header("Content-Security-Policy: default-src 'self'; base-uri 'self'; object-src 'none'; frame-ancestors 'none'; img-src 'self' data: blob:; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline'; connect-src 'self'; form-action 'self'");
|
||||
}
|
||||
?>
|
||||
|
|
@ -348,7 +352,18 @@ function admin_page(string $title, string $active, callable $body): void
|
|||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta name="robots" content="noindex,nofollow">
|
||||
<meta name="robots" content="<?= $indexable ? 'index,follow' : 'noindex,nofollow' ?>">
|
||||
<?php if ($desc !== ''): ?><meta name="description" content="<?= h($desc) ?>"><?php endif; ?>
|
||||
<?php if ($canonical !== ''): ?><link rel="canonical" href="<?= h($canonical) ?>"><?php endif; ?>
|
||||
<?php if ($indexable): ?>
|
||||
<meta property="og:type" content="website">
|
||||
<meta property="og:title" content="<?= h($title . ' - ' . $site) ?>">
|
||||
<?php if ($desc !== ''): ?><meta property="og:description" content="<?= h($desc) ?>"><?php endif; ?>
|
||||
<?php if ($canonical !== ''): ?><meta property="og:url" content="<?= h($canonical) ?>"><?php endif; ?>
|
||||
<meta name="twitter:card" content="summary">
|
||||
<meta name="twitter:title" content="<?= h($title . ' - ' . $site) ?>">
|
||||
<?php if ($desc !== ''): ?><meta name="twitter:description" content="<?= h($desc) ?>"><?php endif; ?>
|
||||
<?php endif; ?>
|
||||
<title><?= h($title) ?> - <?= h($site) ?></title>
|
||||
<link rel="stylesheet" href="<?= h($sharedHref) ?>">
|
||||
<link rel="stylesheet" href="admin.css">
|
||||
|
|
@ -399,6 +414,11 @@ function admin_page(string $title, string $active, callable $body): void
|
|||
<?php endforeach; ?>
|
||||
<?php $body(); ?>
|
||||
</main>
|
||||
<footer class="site-footer" style="padding:1rem 1.25rem;text-align:center;font-size:.85rem;opacity:.9">
|
||||
<span class="muted">Oscar Admin · Open source</span>
|
||||
<span class="muted"> · </span>
|
||||
<a href="<?= h($repoUrl) ?>" rel="noopener noreferrer">Source code / Git repo</a>
|
||||
</footer>
|
||||
<script>
|
||||
window.ADMIN_CSRF = <?= json_encode(admin_csrf_token(), JSON_UNESCAPED_SLASHES) ?>;
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -32,7 +32,6 @@ if (!headers_sent()) {
|
|||
header('X-Content-Type-Options: nosniff');
|
||||
header('Referrer-Policy: no-referrer');
|
||||
header('Permissions-Policy: camera=(), microphone=(), geolocation=()');
|
||||
header('X-Robots-Tag: noindex, nofollow');
|
||||
header("Content-Security-Policy: default-src 'self'; base-uri 'self'; object-src 'none'; frame-ancestors 'none'; img-src 'self' data:; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline'; connect-src 'self'; form-action 'self'");
|
||||
}
|
||||
|
||||
|
|
@ -298,4 +297,8 @@ admin_page('Login', 'login', function () use ($error, $notice, $pending, $stage,
|
|||
</div>
|
||||
</section>
|
||||
<?php
|
||||
});
|
||||
}, [
|
||||
'indexable' => true,
|
||||
'description' => 'Oscar Admin is a standalone open-source web dashboard for managing Open OSCAR Server: users, sessions, chat rooms, BART assets, buddy lists, and more.',
|
||||
'repo_url' => 'https://git.claytonia.net/Clarth/oscar-admin',
|
||||
]);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue