forked from ti-nuage/site
Ajout de la rubrique rencontres.
This commit is contained in:
@@ -9,6 +9,7 @@ module.exports = {
|
||||
hostname,
|
||||
paths: {
|
||||
projectRoot,
|
||||
talksRoot: process.env.PATH_TALKS,
|
||||
/* Nodes */
|
||||
leaflet: join(projectRoot, 'node_modules', 'leaflet', 'dist'),
|
||||
/* Metalsmith */
|
||||
|
||||
@@ -10,10 +10,9 @@ function plugin (options) {
|
||||
|
||||
return function (files, metalsmith, done) {
|
||||
const dest = options.destination
|
||||
const items = options.files.length
|
||||
const promises = []
|
||||
|
||||
const addTask = function (promise) {
|
||||
const addTask = function (items, promise) {
|
||||
promises.push(promise)
|
||||
if (items === promises.length) {
|
||||
debug('Waiting for ' + items + 'copy operations.')
|
||||
@@ -27,8 +26,19 @@ function plugin (options) {
|
||||
}
|
||||
}
|
||||
|
||||
options.files.forEach((filename) => {
|
||||
addTask(new Promise(function (resolve, reject) {
|
||||
const iterateFiles = function (options, action) {
|
||||
if (options.files != null) {
|
||||
options.files.forEach((filename) => action(filename, options.files.length))
|
||||
}
|
||||
if (options.generator != null) {
|
||||
options.generator(documents => {
|
||||
documents.forEach((filename) => action(filename, documents.length))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
iterateFiles(options, (filename, items) => {
|
||||
addTask(items, new Promise(function (resolve, reject) {
|
||||
fs.stat(filename, function (err, stats) {
|
||||
if (err) return reject(err)
|
||||
fs.readFile(filename, function (err, buffer) {
|
||||
|
||||
97
scripts/metalsmith-tinuage-talks.js
Normal file
97
scripts/metalsmith-tinuage-talks.js
Normal file
@@ -0,0 +1,97 @@
|
||||
const { Buffer } = require('node:buffer')
|
||||
const config = require('./config.js')
|
||||
const debug = require('debug')('metalsmith-tinuage-talks')
|
||||
const path = require('path')
|
||||
|
||||
module.exports = plugin
|
||||
|
||||
/**
|
||||
* Un plugin pour Metalsmith qui lit une collection de fichiers PDF la section
|
||||
* rencontres du site.
|
||||
*
|
||||
* @return {Function}
|
||||
*/
|
||||
function plugin () {
|
||||
const IndexCreator = {
|
||||
setup: function (page) {
|
||||
this.page = page
|
||||
this.talks = []
|
||||
},
|
||||
|
||||
add: function (filename) {
|
||||
const basename = path.basename(filename)
|
||||
const names = basename.substring(0, basename.lastIndexOf('.')).split('__')
|
||||
|
||||
if (names.length >= 2) {
|
||||
const name = names[0].replaceAll('_', ' ')
|
||||
const location = names[1].substring(0, names[1].lastIndexOf('_')).replaceAll('_', ' ')
|
||||
const year = names[1].substring(names[1].lastIndexOf('_') + 1)
|
||||
|
||||
const talk = this.getEntry(year, location, name)
|
||||
|
||||
if (names.length === 3 && names[2] === ('notes')) {
|
||||
talk.notes = filename
|
||||
} else {
|
||||
talk.doc = filename
|
||||
}
|
||||
} else {
|
||||
console.log('Ignoring talk ' + filename)
|
||||
}
|
||||
},
|
||||
|
||||
fill: function (files) {
|
||||
let html = ''
|
||||
|
||||
this.talks
|
||||
.reduce(
|
||||
(map, talk) => {
|
||||
(map.get(talk.year) || map.set(talk.year, []).get(talk.year)).push(talk)
|
||||
return map
|
||||
},
|
||||
new Map())
|
||||
.forEach((talks, year) => {
|
||||
html += '<h2>' + year + '</h2>\n'
|
||||
talks
|
||||
.sort((a, b) => a.year - b.year || a.title - b.title)
|
||||
.forEach(talk => {
|
||||
html += '<p>' + talk.title + ', ' + talk.location + ' : <a href="/' + talk.doc + '">Présentation</a>, <a href="/' + talk.notes + '">Notes</a></p>\n'
|
||||
})
|
||||
})
|
||||
|
||||
this.page.contents = Buffer.concat([
|
||||
this.page.contents,
|
||||
Buffer.from(html)
|
||||
])
|
||||
},
|
||||
|
||||
getEntry: function (year, location, title) {
|
||||
let talk = this.talks.find(t => t.year === year && t.location === location && t.title === title)
|
||||
|
||||
if (talk == null) {
|
||||
talk = { location, title, year }
|
||||
this.talks.push(talk)
|
||||
}
|
||||
|
||||
return talk
|
||||
}
|
||||
}
|
||||
|
||||
return function (files, metalsmith, done) {
|
||||
if (config.paths.talksRoot) {
|
||||
const creator = Object.create(IndexCreator)
|
||||
|
||||
creator.setup(files['rencontres/index.html'])
|
||||
|
||||
Object.keys(files).forEach(filename => {
|
||||
if (/^rencontres\/.*\.pdf$/.test(filename)) {
|
||||
debug('Handling', filename)
|
||||
creator.add(filename)
|
||||
}
|
||||
})
|
||||
|
||||
creator.fill()
|
||||
}
|
||||
|
||||
done()
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ const config = require('./config.js')
|
||||
const collections = require('@metalsmith/collections')
|
||||
const copy = require('./metalsmith-copy')
|
||||
const excerpts = require('@metalsmith/excerpts')
|
||||
const fs = require('node:fs')
|
||||
const groff = require('metalsmith-groff')
|
||||
const layouts = require('@metalsmith/layouts')
|
||||
const Metalsmith = require('metalsmith')
|
||||
@@ -15,6 +16,7 @@ const marked = require('marked')
|
||||
const permalinks = require('@metalsmith/permalinks')
|
||||
const rename = require('metalsmith-rename')
|
||||
const services = require('./metalsmith-tinuage-services')
|
||||
const talks = require('./metalsmith-tinuage-talks')
|
||||
const sitemap = require('metalsmith-sitemap')
|
||||
const slug = require('slug')
|
||||
const statistics = require('./metalsmith-statistics-plugin')
|
||||
@@ -77,6 +79,26 @@ module.exports = new Metalsmith(config.paths.projectRoot)
|
||||
files: [join(config.paths.leaflet, 'leaflet.css')],
|
||||
destination: './css'
|
||||
}))
|
||||
.use(copy({
|
||||
generator: (callback) => {
|
||||
if (config.paths.talksRoot != null) {
|
||||
return fs.readdir(config.paths.talksRoot, (err, filenames) => {
|
||||
let documents = []
|
||||
|
||||
if (err) {
|
||||
console.error('%s: %s', config.paths.talksRoot, err)
|
||||
} else {
|
||||
documents = filenames
|
||||
.filter(f => { return f.indexOf('.pdf') !== -1 })
|
||||
.map(f => { return join(config.paths.talksRoot, f) })
|
||||
}
|
||||
|
||||
callback(documents)
|
||||
})
|
||||
}
|
||||
},
|
||||
destination: './rencontres'
|
||||
}))
|
||||
.use(copy({
|
||||
files: [
|
||||
join(config.paths.leaflet, 'images', 'marker-icon.png'),
|
||||
@@ -106,6 +128,7 @@ module.exports = new Metalsmith(config.paths.projectRoot)
|
||||
}))
|
||||
.use(chatons())
|
||||
.use(services())
|
||||
.use(talks())
|
||||
.use(excerpts())
|
||||
.use(permalinks({
|
||||
pattern: 'blog/:date/:title',
|
||||
|
||||
Reference in New Issue
Block a user