From a4306aa1769d15ee1be436ca3b3003e123b569e6 Mon Sep 17 00:00:00 2001 From: "E. S." Date: Fri, 16 May 2025 13:58:08 +0300 Subject: [PATCH] ic: add meta tags --- src/handlers/ic/MainHandler.php | 10 +++++++++- src/lib/ic/TZO.php | 13 +++++++++++++ src/strings/ic.yaml | 7 ++++--- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/handlers/ic/MainHandler.php b/src/handlers/ic/MainHandler.php index 71c4436..31c068f 100644 --- a/src/handlers/ic/MainHandler.php +++ b/src/handlers/ic/MainHandler.php @@ -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, diff --git a/src/lib/ic/TZO.php b/src/lib/ic/TZO.php index 4e40604..9b4c3ff 100644 --- a/src/lib/ic/TZO.php +++ b/src/lib/ic/TZO.php @@ -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('/]+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]; diff --git a/src/strings/ic.yaml b/src/strings/ic.yaml index 57f5f92..44cdcfd 100644 --- a/src/strings/ic.yaml +++ b/src/strings/ic.yaml @@ -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" \ No newline at end of file +tzo_brief_guide: "A Brief Guide" +tzo_meta_part_description: "There Beyond Clouds, section %s"