Don't overwrite OpenGraph tags already set by user

This commit is contained in:
Kijin Sung 2021-03-05 13:56:35 +09:00
parent be1fbc9d65
commit 367e7440be
2 changed files with 40 additions and 23 deletions

View file

@ -2764,6 +2764,7 @@ class Context
public static function setCanonicalURL($url)
{
self::$_instance->canonical_url = escape($url, false);
self::addOpenGraphData('og:url', self::$_instance->canonical_url);
}
/**

View file

@ -457,9 +457,18 @@ class HTMLDisplayHandler
}
}
// Get existing metadata.
$og_data = array();
foreach (Context::getOpenGraphData() as $val)
{
$og_data[$val['property']] = $val['content'];
}
// Add basic metadata.
Context::addOpenGraphData('og:title', $permitted ? Context::getBrowserTitle() : lang('msg_not_permitted'));
Context::addOpenGraphData('og:site_name', Context::getSiteTitle());
if (!isset($og_data['og:description']) || !Context::getMetaTag('description'))
{
if ($page_type === 'article' && $permitted && config('seo.og_extract_description'))
{
$description = trim(utf8_normalize_spaces($oDocument->getContentText(200)));
@ -470,9 +479,15 @@ class HTMLDisplayHandler
}
Context::addOpenGraphData('og:description', $description);
Context::addMetaTag('description', $description);
}
// Add metadata about this page.
if (!isset($og_data['og:type']))
{
Context::addOpenGraphData('og:type', $page_type);
}
if (!isset($og_data['og:url']) || !Context::getCanonicalURL())
{
if ($page_type === 'article')
{
$canonical_url = getFullUrl('', 'mid', $current_module_info->mid, 'document_srl', $document_srl);
@ -491,6 +506,7 @@ class HTMLDisplayHandler
}
Context::addOpenGraphData('og:url', $canonical_url);
Context::setCanonicalURL($canonical_url);
}
// Add metadata about the locale.
$lang_type = Context::getLangType();