Add button "share on Diaspora*"

    Sharing URL management has been rewritten has a class
parent 322cdc91
Pipeline #1675 passed with stage
in 42 seconds
...@@ -83,34 +83,60 @@ for (let i in fonts) { ...@@ -83,34 +83,60 @@ for (let i in fonts) {
} }
Canvas.registerFont('./static/fonts/FiraSans-Bold.otf', {family: 'FiraSans', weight: 'bold'}); Canvas.registerFont('./static/fonts/FiraSans-Bold.otf', {family: 'FiraSans', weight: 'bold'});
function buildUrl(req) { function ShareMessage(req) {
return req.protocol + '://' let _req = req;
+ req.headers.host + '/'
+ (config.subdir || '')
+ '?'
+ querystring.stringify(req.args)
+ '&lang=' + req.i18n.getLocale();
}
function tweetMessage(req) {
let _ = req.i18n._; let _ = req.i18n._;
return (req.args.signature ? _('Faites comme ') + encodeURIComponent(req.args.signature) + ', s' : 'S') this.getUrl = function() {
+ _('outenez ') return _req.protocol + '://'
+ encodeURIComponent('La Quadrature du Net ! #LQDoN ') + _req.headers.host + '/'
+ encodeURIComponent(req.protocol + "://" + req.headers.host) + (config.subdir || '')
+ ' ' + '?'
+ encodeURIComponent(buildUrl(req)); + querystring.stringify(_req.args)
+ '&lang=' + _req.i18n.getLocale();
}
this.getTitle = function() {
return (_req.args.signature ? _('Faites comme ') + encodeURIComponent(_req.args.signature) + ', s' : 'S')
+ _('outenez ')
+ 'La Quadrature du Net ! #LQDoN';
}
this.getContent = function() {
return _req.protocol + "://" + _req.headers.host;
}
this.getTwitterLink = function() {
return 'https://twitter.com/intent/tweet?text='
+ encodeURIComponent(this.getTitle()
+ ' ' + this.getContent()
+ ' ' + this.getUrl());
}
this.getFacebookLink = function() {
return 'https://www.facebook.com/sharer/sharer.php?u='
+ encodeURIComponent(this.getUrl());
}
this.getDiasporaLink = function() {
return 'https://share.diasporafoundation.org/?title='
+ encodeURIComponent(this.getTitle() + ' ' + this.getContent())
+ '&url=' + encodeURIComponent(this.getUrl());
}
} }
app.get('/generate.png', function (req, res) { app.get('/generate.png', function (req, res) {
let _ = req.i18n._; let _ = req.i18n._;
if (req.query.target === 'facebook') { let message = new ShareMessage(req);
return res.redirect('https://www.facebook.com/sharer/sharer.php?u=' + encodeURIComponent(buildUrl(req))); if (req.query.target === 'diaspora') {
return res.redirect(message.getDiasporaLink())
}
else if (req.query.target === 'facebook') {
return res.redirect(message.getFacebookLink());
} }
else if (req.query.target === 'twitter') { else if (req.query.target === 'twitter') {
return res.redirect('https://twitter.com/intent/tweet?text=' + tweetMessage(req)); return res.redirect(message.getTwitterLink());
} }
else if (req.query.target === 'download') { else if (req.query.target === 'download') {
res.set("Content-Disposition", "attachment;filename=lqdn_slogan.png"); res.set("Content-Disposition", "attachment;filename=lqdn_slogan.png");
......
...@@ -123,6 +123,9 @@ html(lang=locale) ...@@ -123,6 +123,9 @@ html(lang=locale)
span.fa.fa-refresh span.fa.fa-refresh
button(type="submit" name="target" value="randomize" formaction="" formtarget="_self").randomize.white-button button(type="submit" name="target" value="randomize" formaction="" formtarget="_self").randomize.white-button
span.fa.fa-random span.fa.fa-random
button(type="submit" name="target" value="diaspora").white-button
span.text
=_('Diaspora*') + ' '
button(type="submit" name="target" value="twitter")#tweet-button.blue-button button(type="submit" name="target" value="twitter")#tweet-button.blue-button
span.text span.text
=_('Tweet') + ' ' =_('Tweet') + ' '
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment