Verified Commit 794cc7b6 authored by Thibaut Broggi's avatar Thibaut Broggi

Merge branch 'preprod'

parents c4d63d10 005c1457
Pipeline #1708 passed with stages
in 1 minute and 49 seconds
stages:
- test
- deploy
unit tests:
variables:
BASE_PATH: /srv/generateur-slogans
stage: test
tags: [preprod]
script:
- rsync -ruvC ./ $BASE_PATH
- cd $BASE_PATH
- rm -rf node_modules/
- npm install
- cp config.json.default config.json
- npm test
deploy preprod:
variables:
BASE_PATH: /srv/generateur-slogans
stage: deploy
tags: [preprod]
script:
script:
- rsync -ruvC ./ $BASE_PATH
- cd $BASE_PATH
- rm -rf node_modules/
......@@ -22,11 +36,11 @@ deploy prod:
BASE_PATH: /srv/soutien/generateur-slogans
stage: deploy
tags: [prod]
script:
script:
- rsync -ruvC ./ $BASE_PATH
- cd $BASE_PATH
- rm -rf node_modules/
- npm install
- npm install --production
- cp config.json.default config.json
- sudo /usr/bin/pm2 restart slogan
- sudo /usr/bin/pm2 show slogan
......
{
"name": "generateur-slogans",
"version": "1.0.0",
"description": "Ce projet est le générateur de slogan et d'image utilisé par LQDN pour la campagne de dons 2017-2018.",
"description": "This project is the slogan generator used by LQDN for the donation compaign of years 2017-2018.",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"test": "./node_modules/nodeunit/bin/nodeunit tests/run.js",
"start": "./srv.js"
},
"repository": {
......@@ -15,5 +15,8 @@
"canvas": "2.0.0-alpha.5",
"express": "^4.16.1",
"pug": "^2.0.0-rc.4"
},
"devDependencies": {
"nodeunit": "^0.11.2"
}
}
const querystring = require('querystring');
module.exports = function(req) {
let _req = req;
let _ = req.i18n._;
let _lqdnName = "@laquadrature";
this.getUrl = function() {
return _req.protocol + '://'
+ _req.headers.host + '/'
+ (global.config.subdir || '')
+ '?'
+ querystring.stringify(_req.args)
+ '&lang=' + _req.i18n.getLocale();
}
this.getTitle = function() {
return (_req.args.signature ? _('Faites comme ') + encodeURIComponent(_req.args.signature) + ', s' : 'S')
+ _('outenez ')
+ _lqdnName + ' ! #LQDoN';
}
this.getContent = function() {
return _req.protocol + "://" + _req.headers.host;
}
this.getTwitterLink = function() {
_lqdnName = "@laquadrature";
return 'https://twitter.com/intent/tweet?text='
+ encodeURIComponent(this.getTitle()
+ ' ' + this.getContent()
+ ' ' + this.getUrl());
}
this.getFacebookLink = function() {
_lqdnName = "@laquadrature";
return 'https://www.facebook.com/sharer/sharer.php?u='
+ encodeURIComponent(this.getUrl());
}
this.getDiasporaLink = function() {
_lqdnName = "La Quadrature du Net";
return 'https://share.diasporafoundation.org/?title='
+ encodeURIComponent(this.getTitle() + ' ' + this.getContent())
+ '&url=' + encodeURIComponent(this.getUrl());
}
this.getMastodonLink = function() {
_lqdnName = "@laquadrature";
return 'https://mamot.fr/share?text='
+ encodeURIComponent(this.getTitle()
+ ' ' + this.getContent()
+ ' ' + this.getUrl());
}
}
......@@ -6,8 +6,9 @@ const express = require('express');
const Canvas = require('canvas');
const Image = Canvas.Image;
const app = express();
const config = require('./config.json');
global.config = require('./config.json');
const i18n = require('./i18n.js');
const ShareMessage = require('./shareMessage.js');
app.set('trust proxy', true);
app.set('x-powered-by', false);
......@@ -83,57 +84,6 @@ for (let i in fonts) {
}
Canvas.registerFont('./static/fonts/FiraSans-Bold.otf', {family: 'FiraSans', weight: 'bold'});
function ShareMessage(req) {
let _req = req;
let _ = req.i18n._;
let _lqdnName = "@laquadrature";
this.getUrl = function() {
return _req.protocol + '://'
+ _req.headers.host + '/'
+ (config.subdir || '')
+ '?'
+ querystring.stringify(_req.args)
+ '&lang=' + _req.i18n.getLocale();
}
this.getTitle = function() {
return (_req.args.signature ? _('Faites comme ') + encodeURIComponent(_req.args.signature) + ', s' : 'S')
+ _('outenez ')
+ _lqdnName + ' ! #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() {
_lqdnName = "La Quadrature du Net";
return 'https://share.diasporafoundation.org/?title='
+ encodeURIComponent(this.getTitle() + ' ' + this.getContent())
+ '&url=' + encodeURIComponent(this.getUrl());
}
this.getMastodonLink = function() {
return 'https://mamot.fr/share?text='
+ encodeURIComponent(this.getTitle()
+ ' ' + this.getContent()
+ ' ' + this.getUrl());
}
}
app.get('/generate.png', function (req, res) {
let _ = req.i18n._;
......
#!/usr/bin/env nodeunit
global.config = {};
const I18n = require('../i18n.js');
const ShareMessage = require('../shareMessage.js');
const i18n = new I18n();
exports.i18n = {
defaultLocale: function(test) {
test.strictEqual(i18n.getLocale(), 'en');
test.done();
},
changeLocale: function(test) {
i18n.setLocale('fr');
test.strictEqual(i18n.getLocale(), 'fr');
test.done();
},
testTranslation: {
enLocale: function(test) {
i18n.setLocale('en');
test.strictEqual(i18n._('Français'), 'French');
test.done();
},
frLocale: function(test) {
i18n.setLocale('fr');
test.strictEqual(i18n._('Français'), 'Français');
test.done();
},
noLocale: function(test) {
i18n.setLocale(undefined);
test.strictEqual(i18n._('Français'), 'Français');
test.done();
},
otherLocale: function(test) {
i18n.setLocale('ru');
test.strictEqual(i18n._('Français'), 'Français');
test.done();
}
}
};
exports.shareMessage = {
default: function(test) {
let req = {
protocol: 'https',
headers: {
host: 'localhost'
},
i18n: i18n,
args: {
bgColor: '#f54358',
fgColor: '#ffd201',
text: 'démocratie',
font: 'lineal',
icon: 1,
signature: ''
}
};
let msg = new ShareMessage(req);
i18n.setLocale('fr');
test.strictEqual(msg.getUrl(), 'https://localhost/?bgColor=%23f54358&fgColor=%23ffd201&text=d%C3%A9mocratie&font=lineal&icon=1&signature=&lang=fr');
test.strictEqual(msg.getTitle(), 'Soutenez @laquadrature ! #LQDoN');
test.strictEqual(msg.getContent(), 'https://localhost');
test.strictEqual(msg.getTwitterLink(), 'https://twitter.com/intent/tweet?text=Soutenez%20%40laquadrature%20!%20%23LQDoN%20https%3A%2F%2Flocalhost%20https%3A%2F%2Flocalhost%2F%3FbgColor%3D%2523f54358%26fgColor%3D%2523ffd201%26text%3Dd%25C3%25A9mocratie%26font%3Dlineal%26icon%3D1%26signature%3D%26lang%3Dfr');
test.strictEqual(msg.getFacebookLink(), 'https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Flocalhost%2F%3FbgColor%3D%2523f54358%26fgColor%3D%2523ffd201%26text%3Dd%25C3%25A9mocratie%26font%3Dlineal%26icon%3D1%26signature%3D%26lang%3Dfr');
test.strictEqual(msg.getDiasporaLink(), 'https://share.diasporafoundation.org/?title=Soutenez%20La%20Quadrature%20du%20Net%20!%20%23LQDoN%20https%3A%2F%2Flocalhost&url=https%3A%2F%2Flocalhost%2F%3FbgColor%3D%2523f54358%26fgColor%3D%2523ffd201%26text%3Dd%25C3%25A9mocratie%26font%3Dlineal%26icon%3D1%26signature%3D%26lang%3Dfr');
test.strictEqual(msg.getMastodonLink(), 'https://mamot.fr/share?text=Soutenez%20%40laquadrature%20!%20%23LQDoN%20https%3A%2F%2Flocalhost%20https%3A%2F%2Flocalhost%2F%3FbgColor%3D%2523f54358%26fgColor%3D%2523ffd201%26text%3Dd%25C3%25A9mocratie%26font%3Dlineal%26icon%3D1%26signature%3D%26lang%3Dfr');
test.done();
}
}
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