This commit is contained in:
Roman Pyrih
2025-06-17 16:04:45 +02:00
parent d769033d66
commit e594e5bc1b
2 changed files with 49 additions and 1 deletions

View File

@@ -2,16 +2,26 @@
namespace front\factory; namespace front\factory;
class Articles class Articles
{ {
static private function slugify($text) {
$text = strtolower($text);
$text = preg_replace('/[^\p{L}\p{Nd}]+/u', '-', $text);
$text = trim($text, '-');
return $text;
}
static public function generateTableOfContents($content) { static public function generateTableOfContents($content) {
$result = ''; $result = '';
$currentLevel = []; $currentLevel = [];
preg_match_all('/<(h[1-6])([^>]*)>(.*?)<\/\1>/', $content, $matches, PREG_SET_ORDER); preg_match_all('/<(h[1-6])([^>]*)>(.*?)<\/\1>/', $content, $matches, PREG_SET_ORDER);
// preg_match_all('/<(h[1-6])[^>]*>(.*?)<\/\1>/', $content, $matches, PREG_SET_ORDER);
$firstLevel = true; $firstLevel = true;
foreach ($matches as $match) { foreach ($matches as $match) {
$level = intval(substr($match[1], 1)); $level = intval(substr($match[1], 1));
$headingText = strip_tags($match[2]);
$slug = self::slugify($headingText);
while ($level < count($currentLevel)) { while ($level < count($currentLevel)) {
$result .= '</li></ol>'; $result .= '</li></ol>';
@@ -41,6 +51,11 @@ class Articles
urlencode(strtolower($id)), urlencode(strtolower($id)),
$match[3] $match[3]
); );
// $result .= sprintf(
// '<a href="#%s">%s</a>',
// $slug,
// $headingText
// );
} }
while (!empty($currentLevel)) { while (!empty($currentLevel)) {

View File

@@ -340,3 +340,36 @@ $text = \front\factory\Articles::generateHeadersIds( $text );
<? endif;?> <? endif;?>
}); });
</script> </script>
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "BlogPosting",
"headline": "<?php echo $this -> article['language']['title']; ?>",
"description": "<?php echo $this -> article['language']['entry']; ?>",
"author": {
"@type": "Person",
"name": "<?php echo $author['author'];?>",
"jobTitle": "<?php echo $author['author_position'];?>",
},
"publisher": {
"@type": "Organization",
"name": "Zaufane.pl",
"logo": {
"@type": "ImageObject",
"url": "https://zaufane.pl/cache/upload/filemanager/images/logo.png.webp"
}
},
"datePublished": "<?php echo $this -> article[ 'date_add' ]; ?>",
"mainEntityOfPage": {
"@type": "WebPage",
"url": "https://zaufane.pl/certyfikat-zaufanepl-klucz-do-zaufania-klientow-w-twojej-firmie"
},
"articleSection": [
"Zaufanie klientów",
"Marketing opinii",
"Opinie w sklepie internetowym"
],
"image": "https://zaufane.pl/<?php echo $this -> article['language']['main_image']; ?>",
}
</script>