feat: Affichage des modifications des associations sur staging
continuous-integration/drone/push Build is passing Details
continuous-integration/drone Build is passing Details

This commit is contained in:
Simon 2023-07-13 00:25:35 +02:00
parent 33bc1bd3cf
commit 571afda202
3 changed files with 109 additions and 2 deletions

View File

@ -127,7 +127,7 @@ steps:
from_secret: DIRECTUS_TOKEN from_secret: DIRECTUS_TOKEN
commands: commands:
- (cd themes/hugo-theme-lowtech && npm i) - (cd themes/hugo-theme-lowtech && npm i)
- DRAFT=true node scripts/directus-to-markdown/index.js - DRAFT=true node scripts/directus-to-markdown/staging.js
- name: build website - name: build website
image: klakegg/hugo:0.101.0-ext-debian-ci image: klakegg/hugo:0.101.0-ext-debian-ci

1
.gitignore vendored
View File

@ -2,4 +2,3 @@ resources
public public
backups backups
.hugo_build.lock .hugo_build.lock
content/associations/*

View File

@ -0,0 +1,108 @@
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: {
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'],
filterDraft
},
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
const [year, month, day] = article.date.split("-")
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',
],
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)}`;
},
deleteFields: [],
},
}
}
new DirectusToMarkdown(config).export();