add alternate hreflang meta links

This commit is contained in:
2022-12-26 16:10:14 +01:00
parent 14ef9100d5
commit 76673842b7
4 changed files with 26 additions and 0 deletions

View File

@ -170,3 +170,23 @@ function set_curl_options($ch): void
curl_setopt($ch, CURLOPT_TIMEOUT, 120);
curl_setopt($ch, CURLOPT_ENCODING, '');
}
function alt_links(): void
{
global $language;
$canonical_query = [];
if(isset($_REQUEST['cat'])) {
$canonical_query['cat'] = $_REQUEST['cat'];
}
if(isset($_REQUEST['pg'])) {
$canonical_query['pg'] = $_REQUEST['pg'];
}
foreach(LANGUAGES as $lang => $data) {
if($lang === $language){
continue;
}
$canonical_query['lang'] = $lang;
$link = CANONICAL_URL . $_SERVER['SCRIPT_NAME'] . '?' . http_build_query($canonical_query);
echo '<link rel="alternate" href="'.$link.'" hreflang="'.$lang.'" />';
}
}

View File

@ -19,6 +19,8 @@ asort($categories);
<meta name=viewport content="width=device-width, initial-scale=1">
<meta name="robots" content="noindex">
<link rel="canonical" href="<?php echo CANONICAL_URL . $_SERVER['SCRIPT_NAME']; ?>">
<link rel="alternate" href="<?php echo CANONICAL_URL . $_SERVER['SCRIPT_NAME']; ?>" hreflang="x-default">
<?php alt_links(); ?>
<style><?php echo $style; ?></style>
</head><body><main>
<h1><?php echo _('Admin interface'); ?></h1>

View File

@ -122,6 +122,8 @@ function send_html(): void
echo '<meta name="viewport" content="width=device-width, initial-scale=1">';
echo '<meta name="description" content="Huge link list of Tor hidden service onions. All the darknet links you need in one place.">';
echo '<link rel="canonical" href="' . CANONICAL_URL . $_SERVER['SCRIPT_NAME'] . (empty($canonical_query) ? '' : '?' . http_build_query($canonical_query)) . '">';
echo '<link rel="alternate" href="' . CANONICAL_URL . $_SERVER['SCRIPT_NAME'] . (empty($canonical_query) ? '' : '?' . http_build_query($canonical_query)) . '" hreflang="x-default">';
alt_links();
echo '<style>'.$style.'</style>';
echo '<base target="_blank">';
echo '</head><body><main>';

View File

@ -10,6 +10,8 @@ echo '<meta name="author" content="Daniel Winzen">';
echo '<meta name="viewport" content="width=device-width, initial-scale=1">';
echo '<meta name="description" content="Test whether a Tor hidden service onion is online or offline">';
echo '<link rel="canonical" href="' . CANONICAL_URL . $_SERVER['SCRIPT_NAME'] . '">';
echo '<link rel="alternate" href="' . CANONICAL_URL . $_SERVER['SCRIPT_NAME'] . '" hreflang="x-default">';
alt_links();
echo '<style>'.$style.'</style>';
echo '</head><body><main>';
echo "<h1>"._('Online-Test')."</h1>";