Merge pull request #1205 from ArthurHoaro/feature/opengraph

Add OpenGraph meta tags on permalink page
This commit is contained in:
ArthurHoaro 2018-10-06 13:31:07 +02:00 committed by GitHub
commit e95247d41d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 44 additions and 1 deletions

View file

@ -101,7 +101,7 @@ private function initialize()
'version_hash', 'version_hash',
ApplicationUtils::getVersionHash(SHAARLI_VERSION, $this->conf->get('credentials.salt')) ApplicationUtils::getVersionHash(SHAARLI_VERSION, $this->conf->get('credentials.salt'))
); );
$this->tpl->assign('scripturl', index_url($_SERVER)); $this->tpl->assign('index_url', index_url($_SERVER));
$visibility = ! empty($_SESSION['visibility']) ? $_SESSION['visibility'] : ''; $visibility = ! empty($_SESSION['visibility']) ? $_SESSION['visibility'] : '';
$this->tpl->assign('visibility', $visibility); $this->tpl->assign('visibility', $visibility);
$this->tpl->assign('untaggedonly', !empty($_SESSION['untaggedonly'])); $this->tpl->assign('untaggedonly', !empty($_SESSION['untaggedonly']));

View file

@ -28,6 +28,7 @@ function hook_markdown_render_linklist($data, $conf)
$value = stripNoMarkdownTag($value); $value = stripNoMarkdownTag($value);
continue; continue;
} }
$value['description_src'] = $value['description'];
$value['description'] = process_markdown( $value['description'] = process_markdown(
$value['description'], $value['description'],
$conf->get('security.markdown_escape', true), $conf->get('security.markdown_escape', true),

View file

@ -47,6 +47,8 @@ public function testMarkdownLinklist()
$data = hook_markdown_render_linklist($data, $this->conf); $data = hook_markdown_render_linklist($data, $this->conf);
$this->assertNotFalse(strpos($data['links'][0]['description'], '<h1>')); $this->assertNotFalse(strpos($data['links'][0]['description'], '<h1>'));
$this->assertNotFalse(strpos($data['links'][0]['description'], '<p>')); $this->assertNotFalse(strpos($data['links'][0]['description'], '<p>'));
$this->assertEquals($markdown, $data['links'][0]['description_src']);
} }
/** /**

View file

@ -15,3 +15,23 @@
<link type="text/css" rel="stylesheet" href="data/user.css#" /> <link type="text/css" rel="stylesheet" href="data/user.css#" />
{/if} {/if}
<link rel="search" type="application/opensearchdescription+xml" href="?do=opensearch#" title="Shaarli search - {$shaarlititle}"/> <link rel="search" type="application/opensearchdescription+xml" href="?do=opensearch#" title="Shaarli search - {$shaarlititle}"/>
{if="! empty($links) && count($links) === 1"}
{$link=reset($links)}
<meta property="og:title" content="{$link.title}" />
<meta property="og:type" content="article" />
<meta property="og:url" content="{$index_url}?{$link.shorturl}" />
{$ogDescription=isset($link.description_src) ? $link.description_src : $link.description}
<meta property="og:description" content="{function="substr($ogDescription, 0, 300)"}" />
{if="$link.thumbnail"}
<meta property="og:image" content="{$index_url}{$link.thumbnail}" />
{/if}
{if="!$hide_timestamps || $is_logged_in"}
<meta property="article:published_time" content="{$link.created->format(DateTime::ATOM)}" />
{if="$link.updated"}
<meta property="article:modified_time" content="{$link.updated->format(DateTime::ATOM)}" />
{/if}
{/if}
{loop="link.taglist"}
<meta property="article:tag" content="{$value}" />
{/loop}
{/if}

View file

@ -12,3 +12,23 @@
{/loop} {/loop}
{if="is_file('data/user.css')"}<link type="text/css" rel="stylesheet" href="data/user.css#" />{/if} {if="is_file('data/user.css')"}<link type="text/css" rel="stylesheet" href="data/user.css#" />{/if}
<link rel="search" type="application/opensearchdescription+xml" href="?do=opensearch#" title="Shaarli search - {$shaarlititle|htmlspecialchars}"/> <link rel="search" type="application/opensearchdescription+xml" href="?do=opensearch#" title="Shaarli search - {$shaarlititle|htmlspecialchars}"/>
{if="! empty($links) && count($links) === 1"}
{$link=reset($links)}
<meta property="og:title" content="{$link.title}" />
<meta property="og:type" content="article" />
<meta property="og:url" content="{$index_url}?{$link.shorturl}" />
{$ogDescription=isset($link.description_src) ? $link.description_src : $link.description}
<meta property="og:description" content="{function="mb_substr($ogDescription, 0, 300)"}" />
{if="$link.thumbnail"}
<meta property="og:image" content="{$index_url}{$link.thumbnail}" />
{/if}
{if="!$hide_timestamps || $is_logged_in"}
<meta property="article:published_time" content="{$link.created->format(DateTime::ATOM)}" />
{if="$link.updated"}
<meta property="article:modified_time" content="{$link.updated->format(DateTime::ATOM)}" />
{/if}
{/if}
{loop="link.taglist"}
<meta property="article:tag" content="{$value}" />
{/loop}
{/if}