Skip to content

Commit

Permalink
Add OpenGraph meta tags on permalink page
Browse files Browse the repository at this point in the history
Includes:
  - og:title
  - og:type -> article
  - og:image -> if there is a thumbnail
  - og:url -> permalink
  - og:description -> first 300 chars of raw description
  - article:published_time
  - article:modified_time
  - article:tag -> one OG meta tag for each shaare tag

Fixes shaarli#258
  • Loading branch information
ArthurHoaro committed Aug 13, 2018
1 parent a4f0509 commit a120fb2
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion application/PageBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ private function initialize()
'version_hash',
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'] : '';
$this->tpl->assign('visibility', $visibility);
$this->tpl->assign('untaggedonly', !empty($_SESSION['untaggedonly']));
Expand Down
1 change: 1 addition & 0 deletions plugins/markdown/markdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ function hook_markdown_render_linklist($data, $conf)
$value = stripNoMarkdownTag($value);
continue;
}
$value['description_src'] = $value['description'];
$value['description'] = process_markdown(
$value['description'],
$conf->get('security.markdown_escape', true),
Expand Down
2 changes: 2 additions & 0 deletions tests/plugins/PluginMarkdownTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public function testMarkdownLinklist()
$data = hook_markdown_render_linklist($data, $this->conf);
$this->assertNotFalse(strpos($data['links'][0]['description'], '<h1>'));
$this->assertNotFalse(strpos($data['links'][0]['description'], '<p>'));

$this->assertEquals($markdown, $data['links'][0]['description_src']);
}

/**
Expand Down
20 changes: 20 additions & 0 deletions tpl/default/includes.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,23 @@
<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}"/>
{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}
20 changes: 20 additions & 0 deletions tpl/vintage/includes.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,23 @@
{/loop}
{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}"/>
{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}

0 comments on commit a120fb2

Please sign in to comment.