cremeaux/scripts/directus-to-markdown/index.js

73 lines
2.3 KiB
JavaScript
Raw Normal View History

2022-02-02 17:38:21 +01:00
import DirectusToMarkdown from '@resilien/directus-to-markdown'
import urlslug from 'url-slug'
2022-12-12 10:55:19 +01:00
const filterDraft = process.env.DRAFT && process.env.DRAFT == 'true' ? '' : { draft: { _eq: 'false' } }
const filterAssociation = process.env.DRAFT && process.env.DRAFT == 'true' ? '' : { display_website: { _eq: 'true' } }
2022-02-02 17:38:21 +01:00
const config = {
collections: {
actualites: {
2022-02-23 11:43:36 +01:00
readByQueryOption: {
2022-02-02 17:38:21 +01:00
fields: ['title', 'date', 'image', 'image_credit', 'description', 'auteur', 'draft', 'content'],
2022-12-12 10:55:19 +01:00
filterDraft
2022-02-02 17:38:21 +01:00
},
pathBuilder: (article) => {
const [year, month, day] = article.date.split("-")
return `./content/actualites/${year}/${month}/${day}-${urlslug(article.title, { remove: /\./g })}`;
}
2022-12-02 08:54:45 +01:00
},
Association: {
readByQueryOption: {
fields: [
'denomination',
'title',
'description',
'mail',
'telephone',
'site',
'facebook',
'bureau.sort',
'bureau.Contact_id.*',
'content',
2022-12-12 10:55:19 +01:00
],
filterAssociation
2022-12-02 08:54:45 +01:00
},
pathBuilder: (association) => {
if (!association.title) {
association.title = association.denomination
}
2022-12-12 10:55:19 +01:00
console.log("Import de l'association « " + association.title + " »")
if (association.bureau && association.bureau.length > 0) {
const bureau = []
for (const contact of association.bureau) {
const detail = contact.Contact_id
if (detail) {
let c = {
denomination: detail.denomination,
prenom: detail.prenom,
nom: detail.nom,
}
if (detail.mail && detail.display_mail) {
c.mail = detail.mail
}
if (detail.telephone && detail.display_telephone) {
c.telephone = detail.telephone
}
bureau.push(c)
} else {
console.log("problème sur un contact")
}
2022-12-02 08:54:45 +01:00
}
association.bureau = bureau
} else {
delete association.bureau
2022-12-02 08:54:45 +01:00
}
return `./content/associations/${urlslug(association.denomination)}`;
},
},
2022-02-02 17:38:21 +01:00
}
}
new DirectusToMarkdown(config).export();