import DirectusToMarkdown from '@resilien/directus-to-markdown' import urlslug from 'url-slug' 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' } } const config = { collections: { actualites: { readByQueryOption: { fields: ['title', 'date', 'image', 'image_credit', 'description', 'auteur', 'draft', 'content'], filterDraft }, pathBuilder: (article) => { const [year, month, day] = article.date.split("-") return `./content/actualites/${year}/${month}/${day}-${urlslug(article.title, { remove: /\./g })}`; } }, Association: { readByQueryOption: { fields: [ 'denomination', 'title', 'description', 'mail', 'telephone', 'site', 'facebook', 'bureau.sort', 'bureau.Contact_id.*', 'content', ], filterAssociation }, pathBuilder: (association) => { if (!association.title) { association.title = association.denomination } 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") } } association.bureau = bureau } else { delete association.bureau } return `./content/associations/${urlslug(association.denomination)}`; }, }, } } new DirectusToMarkdown(config).export();