add open graph and twitter card support

add canonical link
This commit is contained in:
joyqi 2023-12-29 14:31:39 +08:00
parent 7edd3f9659
commit 005951ee4d
2 changed files with 39 additions and 16 deletions

View File

@ -951,6 +951,7 @@ class Archive extends Contents
'rss1' => $this->archiveFeedRssUrl,
'commentReply' => 1,
'antiSpam' => 1,
'social' => 1,
'atom' => $this->archiveFeedAtomUrl
];
@ -965,22 +966,7 @@ class Archive extends Contents
$allows = self::pluginHandle()->call('headerOptions', $allows, $this);
$title = (empty($this->archiveTitle) ? '' : $this->archiveTitle . ' » ') . $this->options->title;
$header = '';
if (!empty($allows['description'])) {
$header .= '<meta name="description" content="' . $allows['description'] . '" />' . "\n";
}
if (!empty($allows['keywords'])) {
$header .= '<meta name="keywords" content="' . $allows['keywords'] . '" />' . "\n";
}
if (!empty($allows['generator'])) {
$header .= '<meta name="generator" content="' . $allows['generator'] . '" />' . "\n";
}
if (!empty($allows['template'])) {
$header .= '<meta name="template" content="' . $allows['template'] . '" />' . "\n";
}
$header = '<link rel="canonical" href="' . $this->archiveUrl . '" />' . "\n";
if (!empty($allows['pingback']) && 2 == $this->options->allowXmlRpc) {
$header .= '<link rel="pingback" href="' . $allows['pingback'] . '" />' . "\n";
@ -1011,6 +997,34 @@ class Archive extends Contents
. $title . ' &raquo; ATOM 1.0" href="' . $allows['atom'] . '" />' . "\n";
}
if (!empty($allows['description'])) {
$header .= '<meta name="description" content="' . $allows['description'] . '" />' . "\n";
}
if (!empty($allows['keywords'])) {
$header .= '<meta name="keywords" content="' . $allows['keywords'] . '" />' . "\n";
}
if (!empty($allows['generator'])) {
$header .= '<meta name="generator" content="' . $allows['generator'] . '" />' . "\n";
}
if (!empty($allows['template'])) {
$header .= '<meta name="template" content="' . $allows['template'] . '" />' . "\n";
}
if (!empty($allows['social'])) {
$header .= '<meta property="og:type" content="' . ($this->is('single') ? 'article' : 'website') . '" />' . "\n";
$header .= '<meta property="og:url" content="' . $this->archiveUrl . '" />' . "\n";
$header .= '<meta name="twitter:title" property="og:title" itemprop="name" content="'
. htmlspecialchars($this->archiveTitle ?? $this->options->title) . '" />' . "\n";
$header .= '<meta name="twitter:description" property="og:description" itemprop="description" content="'
. htmlspecialchars($this->archiveDescription ?? $this->options->description) . '" />' . "\n";
$header .= '<meta property="og:site_name" content="' . htmlspecialchars($this->options->title) . '" />' . "\n";
$header .= '<meta name="twitter:card" content="summary" />' . "\n";
$header .= '<meta name="twitter:domain" content="' . $this->options->siteDomain . '" />' . "\n";
}
if ($this->options->commentsThreaded && $this->is('single')) {
if ('' != $allows['commentReply']) {
if (1 == $allows['commentReply']) {

View File

@ -29,6 +29,7 @@ if (!defined('__TYPECHO_ROOT_DIR__')) {
* @property string $xmlRpcUrl
* @property string $index
* @property string $siteUrl
* @property string $siteDomain
* @property array $routingTable
* @property string $rootUrl
* @property string $pluginUrl
@ -453,6 +454,14 @@ class Options extends Base
return $siteUrl;
}
/**
* @return string
*/
protected function ___siteDomain(): string
{
return parse_url($this->siteUrl, PHP_URL_HOST);
}
/**
* RSS2.0
*