From 571afda202ab2aaca445e22bd7bae7cf576dc056 Mon Sep 17 00:00:00 2001 From: Simon C Date: Thu, 13 Jul 2023 00:25:35 +0200 Subject: [PATCH] feat: Affichage des modifications des associations sur staging --- .drone.yml | 2 +- .gitignore | 1 - scripts/directus-to-markdown/staging.js | 108 ++++++++++++++++++++++++ 3 files changed, 109 insertions(+), 2 deletions(-) create mode 100644 scripts/directus-to-markdown/staging.js diff --git a/.drone.yml b/.drone.yml index 799d4c3..d0a2741 100644 --- a/.drone.yml +++ b/.drone.yml @@ -127,7 +127,7 @@ steps: from_secret: DIRECTUS_TOKEN commands: - (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 image: klakegg/hugo:0.101.0-ext-debian-ci diff --git a/.gitignore b/.gitignore index 3e6c7d2..d56b5df 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,3 @@ resources public backups .hugo_build.lock -content/associations/* \ No newline at end of file diff --git a/scripts/directus-to-markdown/staging.js b/scripts/directus-to-markdown/staging.js new file mode 100644 index 0000000..705e67c --- /dev/null +++ b/scripts/directus-to-markdown/staging.js @@ -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();