From b438d9113fab9f6461502a8947949ef047cba569 Mon Sep 17 00:00:00 2001 From: David Soulayrol Date: Sun, 19 Feb 2023 14:52:24 +0100 Subject: [PATCH] =?UTF-8?q?Nouvelle=20cha=C3=AEne=20de=20traitement=20de?= =?UTF-8?q?=20statistiques.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ceci marque le début du support des fichiers propriétés pour la fourniture de statistiques à https://stats.chatons.org. Les fichiers sont traitées au moment de la génération du site pour compléter les informations pouvant être obtenues automatiquement. --- .../production/images/logo-tinuage-square.svg | 98 ++++++++++++++++ .../chatonsinfos/tinuage.properties | 45 +++++++ content/.well-known/security.txt | 3 + package.json | 2 +- scripts/metalsmith-tinuage-chatons.js | 111 ++++++++++++++++++ scripts/metalsmith.js | 2 + 6 files changed, 260 insertions(+), 1 deletion(-) create mode 100644 assets/production/images/logo-tinuage-square.svg create mode 100644 content/.well-known/chatonsinfos/tinuage.properties create mode 100644 content/.well-known/security.txt create mode 100644 scripts/metalsmith-tinuage-chatons.js diff --git a/assets/production/images/logo-tinuage-square.svg b/assets/production/images/logo-tinuage-square.svg new file mode 100644 index 0000000..4de1cb1 --- /dev/null +++ b/assets/production/images/logo-tinuage-square.svg @@ -0,0 +1,98 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + diff --git a/content/.well-known/chatonsinfos/tinuage.properties b/content/.well-known/chatonsinfos/tinuage.properties new file mode 100644 index 0000000..7ed7823 --- /dev/null +++ b/content/.well-known/chatonsinfos/tinuage.properties @@ -0,0 +1,45 @@ +# [File] +file.class = organization +file.protocol = ChatonsInfos-0.5 +file.datetime = +file.generator = + +# [Organisation] +organization.name = Ti Nuage +organization.country.code = FR +organization.country.name = France +organization.description = Hébergeur associatif, transparent, éthique, militant et solidaire dans le Trégor. +organization.type = ASSOCIATION +organization.website = https://www.ti-nuage.fr + +organization.chatrooms.xmpp = ti-nuage@muc.ti-nuage.fr +organization.contact.url = https://www.ti-nuage.fr/mentions_legales.html +organization.contact.email = contact@ti-nuage.fr + +organization.funding.helloasso = https://www.helloasso.com/associations/ti-nuage/adhesions/adhesion-1 + +organization.geolocation.address = Mairie, 11 places aux Chevaux, 22420 Le Vieux Marché +organization.geolocation.latitude = 48.60736 +organization.geolocation.longitude = -3.45054 + +organization.guide.technical = https://wiki.ti-nuage.fr/fr/Administration/Infrastructure +organization.guide.user = https://wiki.ti-nuage.fr/ + +organization.legal.url = https://www.ti-nuage.fr/mentions_legales.html +organization.logo = https://www.ti-nuage.fr/images/logo-tinuage-square.svg + +organization.memberof.chatons.startdate = 21/12/2022 +organization.memberof.chatons.status.level = ACTIVE +organization.memberof.chatons.status.description = + +organization.socialnetworks.mastodon = https://hostux.social/@tinuage +organization.socialnetworks.peertube = https://video.tedomum.net/a/tinunu/video-channels + +organization.startdate = 15/10/2021 +organization.status.description = +organization.status.level = ACTIVE + +# [Subs] +subs.foo1 = + +# [Metrics] diff --git a/content/.well-known/security.txt b/content/.well-known/security.txt new file mode 100644 index 0000000..e598cf1 --- /dev/null +++ b/content/.well-known/security.txt @@ -0,0 +1,3 @@ +Contact: mailto:contact@ti-nuage.fr +Expires: Sun, 31 Dec 2023 23:59 +0200 +Preferred-Languages: fr, en diff --git a/package.json b/package.json index 9418465..1e56bfa 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "clean": "rimraf dist", "dev": "npm run build && nodemon scripts/run.js serve", "server": "npm run build && http-server dist", - "deploy": "npm run build:prod && cd dist && rsync -v -rlptz --relative -e \"ssh -p $SERVER_PORT\" * $SERVER_PATH", + "deploy": "npm run build:prod && cd dist && rsync -v -rlptz --relative -e \"ssh -p $SERVER_PORT\" ./ $SERVER_PATH", "lint": "npm run lint:js && npm run lint:css", "lint:js": "eslint scripts", "lint:css": "stylelint assets/**/*.css", diff --git a/scripts/metalsmith-tinuage-chatons.js b/scripts/metalsmith-tinuage-chatons.js new file mode 100644 index 0000000..3029e79 --- /dev/null +++ b/scripts/metalsmith-tinuage-chatons.js @@ -0,0 +1,111 @@ +// const { Buffer } = require('node:buffer') +const debug = require('debug')('metalsmith-tinuage-chatons') +const config = require('./config.js') +const fs = require('node:fs') +const path = require('path') + +module.exports = plugin + +/** + * Un plugin pour Metalsmith qui traite des fichiers de propriétés + * pour StatoolInfos. + * + * @return {Function} + */ +function plugin () { + const Filler = { + + init: function (properties) { + this.handlers = { + 'file.datetime': this.datetime, + 'file.generator': this.generator + } + this.properties = properties + }, + + complete: function () { + Object.entries(this.properties).forEach(([key, value]) => { + if (value.length === 0) { + if (Object.keys(this.handlers).includes(key)) { + this.properties[key] = this.handlers[key]() + } + } + }) + }, + + export: function () { + return Object + .entries(this.properties) + .filter(([key, value]) => !key.startsWith('meta')) + .map(([key, value]) => key + ' = ' + value) + .reduce((acc, value) => acc + value + '\n', '') + }, + + datetime: function () { + /* Statools n'attend pas de l'ISO8-601, + * mais le strict format YYYY-MM-DDThh:mm:ss + */ + const d = new Date() + const pad = function (value) { return value.toString().padStart(2, '0') } + const date = [d.getFullYear(), pad(d.getMonth() + 1), pad(d.getDate())] + const time = [d.getHours(), d.getMinutes(), d.getSeconds()] + + return date.join('-') + 'T' + time.join(':') + }, + + generator: function () { + return 'Metalsmith' + } + } + + function loadProperties (root, filenames) { + const promises = filenames + .filter(f => { return f.indexOf('.properties') !== -1 }) + .map(function (f) { + debug('Loading ' + f) + return fs.promises + .readFile(path.join(root, f), 'utf8') + .then(data => { + const properties = Object.fromEntries(data + .toString() + .split(/(?:\r\n|\r|\n)/g) + .filter(line => line.length > 1 && line[0] !== '#') + .map(line => line.split(/\s*=\s*/, 2))) + + properties['meta.filename'] = f + return properties + }) + }) + + return Promise.all(promises) + } + + return function (files, metalsmith, done) { + const directory = path.join('.well-known', 'chatonsinfos') + const root = path.join(config.paths.projectRoot, config.paths.metalsmithSource, directory) + + debug('Looking for properties files in ' + root) + fs.readdir(root, (err, filenames) => { + if (err) { + console.error('%s: %s', root, err) + } else { + loadProperties(root, filenames) + .then(function (sets) { + sets.forEach(properties => { + const data = files[path.join(directory, properties['meta.filename'])] + const filler = Object.create(Filler) + + filler.init(properties) + filler.complete() + + data.contents = Buffer.from(filler.export()) + }) + done() + }) + .catch(function (err) { + console.log(err) + }) + } + }) + } +} diff --git a/scripts/metalsmith.js b/scripts/metalsmith.js index 77ad854..cad6708 100644 --- a/scripts/metalsmith.js +++ b/scripts/metalsmith.js @@ -2,6 +2,7 @@ const assets = require('metalsmith-assets') const browserify = require('metalsmith-browserify') const cleanCSS = require('metalsmith-clean-css') +const chatons = require('./metalsmith-tinuage-chatons') const config = require('./config.js') const collections = require('@metalsmith/collections') const excerpts = require('@metalsmith/excerpts') @@ -83,6 +84,7 @@ module.exports = new Metalsmith(config.paths.projectRoot) smartypants: true, xhtml: true })) + .use(chatons()) .use(services()) .use(excerpts()) .use(permalinks({