ic: add meta tags

This commit is contained in:
E. S. 2025-05-16 13:58:08 +03:00
parent c00a6ae955
commit a4306aa176
3 changed files with 26 additions and 4 deletions

View File

@ -12,7 +12,7 @@ class MainHandler
$this->skin->meta->title = lang('meta_index_title');
$this->skin->meta->description = lang('meta_index_description');
$this->skin->meta->url = 'https://'.$_SERVER['HTTP_HOST'].'/';
// $this->skin->meta->image = 'https://'.$config['domain'].'/img/4in1-preview.jpg';
$this->skin->meta->image = 'https://'.$_SERVER['HTTP_HOST'].'/images/simurgh.jpg';
$this->skin->meta->setSocial('og:type', 'website');
$this->skin->options->isIndex = true;
@ -47,6 +47,14 @@ class MainHandler
throw new NotFound();
$title = $tzo->getPartWithDots($part).'_'.$tzo->strings['part_'.$part]['label'];
$html = $tzo->getPartHtml($part);
$this->skin->meta->title = $title.' - '.lang('tzo');
$this->skin->meta->description = TZO::getDescriptionPreviewFromHtml($html, 155);
$this->skin->meta->url = 'https://'.$_SERVER['HTTP_HOST'].'/tbc/'.$part.'/';
$image = TZO::getFirstImageUrlFromHtml($html);
if ($image)
$this->skin->meta->image = 'https://'.$_SERVER['HTTP_HOST'].$image;
$this->skin->title = $title.' - '.lang('tzo');
$this->skin->set([
'tzo' => $tzo,

View File

@ -87,6 +87,19 @@ class TZO
return $html;
}
public static function getDescriptionPreviewFromHtml(string $html, int $len): string {
$text = trim(MarkupUtil::htmlToText($html));
if (mb_strlen($text) >= $len)
return mb_substr($text, 0, $len - 3).'...';
return $text;
}
public static function getFirstImageUrlFromHtml(string $html): ?string {
if (preg_match('/<img[^>]+src=[\'"]([^\'"]+)[\'"]/i', $html, $m))
return $m[1];
return null;
}
protected function getImageSize(string $local_path): array {
list($w, $h) = getimagesize($local_path);
return [$w, $h];

View File

@ -1,10 +1,11 @@
# common
invisible_college: Invisible College
site_title: Invisible College
meta_index_title: ""
meta_index_description: ""
meta_index_title: "Invisible College"
meta_index_description: "Invisible College by idb & friends"
books: Works
tzo: "There Beyond Clouds"
tzo_full_title: "There Beyond Clouds: A Brief Guide"
tzo_brief_guide: "A Brief Guide"
tzo_brief_guide: "A Brief Guide"
tzo_meta_part_description: "There Beyond Clouds, section %s"