137 lines
4.7 KiB
JavaScript
137 lines
4.7 KiB
JavaScript
import DirectusToMarkdown from '@resilien/directus-to-markdown'
|
|
import urlslug from 'url-slug'
|
|
|
|
var lastDate = new Date();
|
|
lastDate.setMonth(lastDate.getMonth() - 3);
|
|
lastDate.setFullYear(lastDate.getFullYear() - 10);
|
|
console.log(lastDate)
|
|
|
|
const filterDraft = process.env.DRAFT && process.env.DRAFT == 'true' ? { date: { _gt: lastDate } } : { draft: { _eq: 'false' }, date: { _gt: lastDate } }
|
|
const filterAssociation = process.env.DRAFT && process.env.DRAFT == 'true' ? '' : { display_website: { _eq: 'true' } }
|
|
|
|
const config = {
|
|
collections: {
|
|
Pages: {
|
|
readByQueryOption: {
|
|
fields: ['title', 'description', 'slug', 'image', 'image_credit', 'content', 'menu_display', 'sort', 'identifier', 'menu_title', 'parent', 'layout', 'aliases', 'draft'],
|
|
filterDraft
|
|
},
|
|
pathBuilder: (page) => {
|
|
page.path = page.parent ? 'index.md' : '_index.md'
|
|
if (!page.layout) delete page.layout
|
|
if (!page.image) delete page.image
|
|
if (!page.image_credit) delete page.image_credit
|
|
if (!page.aliases) delete page.aliases
|
|
|
|
if (page.menu_display) {
|
|
page.menu = {
|
|
main: {
|
|
name: page.menu_title,
|
|
weight: page.sort
|
|
}
|
|
}
|
|
if (page.identifier) {
|
|
page.menu.main.identifier = page.identifier
|
|
}
|
|
if (page.parent) {
|
|
page.menu.main.parent = page.parent
|
|
}
|
|
}
|
|
return `./content${page.slug}`;
|
|
},
|
|
deleteFields: ['path', 'slug', 'menu_display', 'sort', 'identifier', 'menu_title', 'parent'],
|
|
},
|
|
actualites: {
|
|
readByQueryOption: {
|
|
fields: ['title', 'date', 'image', 'image_credit', 'vignette', 'vignette_credit', 'description', 'auteur', 'draft', 'content', 'event', 'authors.Association_id.denomination'],
|
|
filter: filterDraft,
|
|
limit: 1000
|
|
},
|
|
pathBuilder: (article) => {
|
|
if (!article.image) delete article.image
|
|
if (!article.image_credit) delete article.image_credit
|
|
if (!article.vignette) delete article.vignette
|
|
if (!article.vignette_credit) delete article.vignette_credit
|
|
if (!article.auteur) delete article.auteur
|
|
|
|
if (!article.authors || article.authors.length == 0) {
|
|
delete article.authors
|
|
} else {
|
|
article.authors = article.authors.map(a => `/associations/${urlslug(a.Association_id.denomination)}`)
|
|
}
|
|
const [year, month, day] = article.date.split("-")
|
|
|
|
console.log(article.date + ' - ' + article.title)
|
|
|
|
return `./content/actualites/${year}/${month}/${day}-${urlslug(article.title, { remove: /\./g })}`;
|
|
},
|
|
deleteFields: [],
|
|
},
|
|
Association: {
|
|
readByQueryOption: {
|
|
fields: [
|
|
'denomination',
|
|
'title',
|
|
'description',
|
|
'mail',
|
|
'telephone',
|
|
'site',
|
|
'facebook',
|
|
'bureau.sort',
|
|
'bureau.Contact_id.*',
|
|
'content',
|
|
'actualites.actualites_id.date',
|
|
'actualites.actualites_id.title',
|
|
],
|
|
filter: 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
|
|
}
|
|
|
|
if (!association.actualites || association.actualites.length == 0) {
|
|
delete association.actualites
|
|
} else {
|
|
association.actualites = association.actualites.map(a => {
|
|
const [year, month, day] = a.actualites_id.date.split("-")
|
|
|
|
return `/actualites/${year}/${month}/${day}-${urlslug(a.actualites_id.title, { remove: /\./g })}`
|
|
})
|
|
}
|
|
|
|
return `./content/associations/${urlslug(association.denomination)}`;
|
|
},
|
|
deleteFields: [],
|
|
},
|
|
}
|
|
}
|
|
|
|
new DirectusToMarkdown(config).export();
|