mirror of
https://framagit.org/fiat-tux/hat-softwares/lutim.git
synced 2026-05-03 12:02:49 +02:00
Add template for displaying a twitter-card compliant page
This commit is contained in:
17
lib/Lutim.pm
17
lib/Lutim.pm
@@ -202,6 +202,7 @@ sub startup {
|
||||
$r->get('/:short' => sub {
|
||||
my $c = shift;
|
||||
my $short = $c->param('short');
|
||||
my $touit = $c->param('t');
|
||||
my $dl = (defined($c->param('dl'))) ? 'attachment' : 'inline';
|
||||
|
||||
my @images = LutimModel::Lutim->select('WHERE short = ? AND ENABLED = 1 AND path IS NOT NULL', $short);
|
||||
@@ -222,7 +223,21 @@ sub startup {
|
||||
);
|
||||
return $c->redirect_to('/');
|
||||
}
|
||||
if($c->render_file($images[0]->filename, $images[0]->path, $images[0]->mediatype, $dl) != 500) {
|
||||
|
||||
my $test;
|
||||
if (defined($touit)) {
|
||||
$test = 1;
|
||||
$c->render(
|
||||
template => 'twitter',
|
||||
layout => undef,
|
||||
short => $images[0]->short,
|
||||
filename => $images[0]->filename
|
||||
);
|
||||
} else {
|
||||
$test = $c->render_file($images[0]->filename, $images[0]->path, $images[0]->mediatype, $dl);
|
||||
}
|
||||
|
||||
if ($test != 500) {
|
||||
# Update counter and check provisionning
|
||||
$c->on(finish => sub {
|
||||
# Log access
|
||||
|
||||
@@ -24,13 +24,14 @@ my $inf_body = <<EOF;
|
||||
EOF
|
||||
|
||||
our %Lexicon = (
|
||||
'license' => 'License:',
|
||||
'fork-me' => 'Fork me on Github !',
|
||||
'share-twitter' => 'Share on Twitter',
|
||||
'informations' => 'Informations',
|
||||
'license' => 'License:',
|
||||
'fork-me' => 'Fork me on Github !',
|
||||
'share-twitter' => 'Share on Twitter',
|
||||
'informations' => 'Informations',
|
||||
'informations-body' => $inf_body,
|
||||
'view-link' => 'View link:',
|
||||
'download-link' => 'Download link:',
|
||||
'twitter-link' => 'Link for put in a tweet:',
|
||||
'some-bad' => 'Something bad happened',
|
||||
'delete-first' => 'Delete at first view?',
|
||||
'delete-day' => 'Delete after 24 hours?',
|
||||
|
||||
@@ -31,6 +31,7 @@ our %Lexicon = (
|
||||
'informations-body' => $inf_body,
|
||||
'view-link' => 'Lien d\'affichage :',
|
||||
'download-link' => 'Lien de téléchargement :',
|
||||
'twitter-link' => 'Lien pour mettre dans un tweet :',
|
||||
'some-bad' => 'Un problème est survenu',
|
||||
'delete-first' => 'Supprimer au premier accès ?',
|
||||
'delete-day' => 'Supprimer après 24 heures ?',
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
<ul>
|
||||
<li><%=l 'view-link'%><%= link_to url_for('/')->to_abs.flash('short') => begin %><%= url_for('/')->to_abs.flash('short') %><%= end %></li>
|
||||
<li><%=l 'download-link' %> <%= link_to url_for('/')->to_abs.flash('short').'?dl' => begin %><%= url_for('/')->to_abs.flash('short').'?dl' %><%= end %></li>
|
||||
<li><%=l 'twitter-link' %> <%= link_to url_for('/')->to_abs.flash('short').'?t' => begin %><%= url_for('/')->to_abs.flash('short').'?t' %><%= end %></li>
|
||||
</ul>
|
||||
</div>
|
||||
% }
|
||||
@@ -71,8 +72,8 @@
|
||||
|
||||
%= javascript begin
|
||||
function link(url, dl) {
|
||||
if (dl) {
|
||||
url = url+'?dl';
|
||||
if (dl !== '') {
|
||||
url = url+'?'+dl;
|
||||
}
|
||||
return '<a href="<%== url_for('index')->to_abs() %>'+url+'"><%== url_for('index')->to_abs() %>'+url+'</a>';
|
||||
}
|
||||
@@ -80,10 +81,12 @@
|
||||
if(success) {
|
||||
return '<div class="alert alert-success"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button><strong>'
|
||||
+msg.filename
|
||||
+'</strong><ul><li>view link '
|
||||
+link(msg.short, false)
|
||||
+'</a></li><li>download link '
|
||||
+link(msg.short, true)
|
||||
+'</strong><ul><li><%=l 'view-link'%>'
|
||||
+link(msg.short, '')
|
||||
+'</a></li><li><%=l 'download-link' %>'
|
||||
+link(msg.short, 'dl')
|
||||
+'</a></li><li><%=l 'twitter-link' %>'
|
||||
+link(msg.short, 't')
|
||||
+'</li></div>';
|
||||
} else {
|
||||
return '<div class="alert alert-danger"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button><strong><%=l 'some-bad' %></strong><br>'
|
||||
|
||||
17
templates/twitter.html.ep
Normal file
17
templates/twitter.html.ep
Normal file
@@ -0,0 +1,17 @@
|
||||
% # vim:set sw=4 ts=4 sts=4 ft=html.epl expandtab:
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>LUTIm</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta charset="utf-8" />
|
||||
<meta name="twitter:card" content="photo">
|
||||
<meta name="twitter:site" content="@framasky">
|
||||
<meta name="twitter:image:src" content="<%= url_for('/')->to_abs().$short %>">
|
||||
</head>
|
||||
<body>
|
||||
<img src="<%= url_for('/').$short %>" alt="<%= $filename %>">
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user