1
0
mirror of https://github.com/typemill/typemill.git synced 2025-08-07 22:56:32 +02:00

Set meta tags with assets with assets.renderMeta

This commit is contained in:
trendschau
2021-12-17 15:41:30 +01:00
parent cfa7b7be32
commit 627aa4da67
6 changed files with 58 additions and 157 deletions

View File

@@ -19,6 +19,7 @@ class Assets
$this->editorCSS = array();
$this->editorInlineJS = array();
$this->svgSymbols = array();
$this->meta = array();
$this->imageUrl = false;
$this->imageFolder = 'original';
}
@@ -211,21 +212,6 @@ class Assets
$this->svgSymbols[] = $symbol;
}
public function renderCSS()
{
return implode("\n", $this->CSS) . implode("\n", $this->inlineCSS);
}
public function renderJS()
{
return implode("\n", $this->JS) . implode("\n", $this->inlineJS);
}
public function renderSvg()
{
return implode('', $this->svgSymbols);
}
# add JS to enhance the blox-editor in author area
public function addEditorJS($JS)
{
@@ -252,6 +238,11 @@ class Assets
}
}
public function addMeta($key,$meta)
{
$this->meta[$key] = $meta;
}
public function renderEditorJS()
{
return implode("\n", $this->editorJS) . implode("\n", $this->editorInlineJS);
@@ -262,6 +253,31 @@ class Assets
return implode("\n", $this->editorCSS);
}
public function renderCSS()
{
return implode("\n", $this->CSS) . implode("\n", $this->inlineCSS);
}
public function renderJS()
{
return implode("\n", $this->JS) . implode("\n", $this->inlineJS);
}
public function renderSvg()
{
return implode('', $this->svgSymbols);
}
public function renderMeta()
{
$metaLines = '';
foreach($this->meta as $meta)
{
$metaLines .= "\n";
$metaLines .= $meta;
}
return $metaLines;
}
/**
* Checks, if a string is a valid internal or external ressource like js-file or css-file
* @params $path string

View File

@@ -87,7 +87,15 @@ class ControllerFrontendWebsite extends ControllerShared
if(isset($this->settings['favicon']) && $this->settings['favicon'] != '')
{
$favicon = true;
}
$this->c->assets->addMeta('tilecolor','<meta name="msapplication-TileColor" content="#F9F8F6" />');
$this->c->assets->addMeta('tileimage','<meta name="msapplication-TileImage" content="' . $this->base_url . '/media/files/favicon-144.png" />');
$this->c->assets->addMeta('icon16','<link rel="icon" type="image/png" href="' . $this->base_url . '/media/files/favicon-16.png" sizes="16x16" />');
$this->c->assets->addMeta('icon32','<link rel="icon" type="image/png" href="' . $this->base_url . '/media/files/favicon-32.png" sizes="32x32" />');
$this->c->assets->addMeta('icon72','<link rel="apple-touch-icon" sizes="72x72" href="' . $this->base_url . '/media/files/favicon-72.png" />');
$this->c->assets->addMeta('icon114','<link rel="apple-touch-icon" sizes="114x114" href="' . $this->base_url . '/media/files/favicon-114.png" />');
$this->c->assets->addMeta('icon144','<link rel="apple-touch-icon" sizes="144x144" href="' . $this->base_url . '/media/files/favicon-144.png" />');
$this->c->assets->addMeta('icon180','<link rel="apple-touch-icon" sizes="180x180" href="' . $this->base_url . '/media/files/favicon-180.png" />');
}
# the navigation is a copy of the structure without the hidden pages
# hint: if the navigation has been deleted from the cache, then we do not recreate it here to save performace. Instead you have to recreate cache in admin or change a page (publish/unpublish/delete/move)
@@ -219,6 +227,18 @@ class ControllerFrontendWebsite extends ControllerShared
# makes sure that you always have the full meta with title, description and all the rest.
$metatabs = $writeMeta->completePageMeta($contentMD, $this->settings, $item);
# write meta
if(isset($metatabs['meta']['noindex']) && $metatabs['meta']['noindex'])
{
$this->c->assets->addMeta('noindex','<meta name="robots" content="noindex">');
}
$this->c->assets->addMeta('og_site_name','<meta property="og:site_name" content="' . $this->settings['title'] . '">');
$this->c->assets->addMeta('og_title','<meta property="og:title" content="' . $metatabs['meta']['title'] . '">');
$this->c->assets->addMeta('og_description','<meta property="og:description" content="' . $metatabs['meta']['description'] . '">');
$this->c->assets->addMeta('og_type','<meta property="og:type" content="article">');
$this->c->assets->addMeta('og_url','<meta property="og:url" content="' . $item->urlAbs . '">');
# dispatch meta
$metatabs = $this->c->dispatcher->dispatch('onMetaLoaded', new OnMetaLoaded($metatabs))->getData();
@@ -320,6 +340,10 @@ class ControllerFrontendWebsite extends ControllerShared
if($img_url)
{
$firstImage = array('img_url' => $this->base_url . '/' . $img_url, 'img_alt' => $img_alt);
$this->c->assets->addMeta('og_image','<meta property="og:image" content="' . $img_url . '">');
$this->c->assets->addMeta('twitter_image_alt','<meta name="twitter:image:alt" content="' . $img_alt. '">');
$this->c->assets->addMeta('twitter_card','<meta name="twitter:card" content="summary_large_image">');
}
$route = empty($args) && isset($this->settings['themes'][$theme]['cover']) ? '/cover.twig' : '/index.twig';