first commit
This commit is contained in:
81
scripts/directus-to-markdown/index.js
Normal file
81
scripts/directus-to-markdown/index.js
Normal file
@ -0,0 +1,81 @@
|
||||
import DirectusToMarkdown from '@resilien/directus-to-markdown'
|
||||
import urlslug from 'url-slug'
|
||||
|
||||
const getTranslation = (translations, lang, field) => {
|
||||
const match = translations.filter(translation => translation.languages_code == lang || translation.languages_id == lang)
|
||||
return match.length > 0 ? match[0][field] : undefined
|
||||
}
|
||||
|
||||
const formatQuestions = (questions, lang) => {
|
||||
|
||||
const formated = []
|
||||
for (const [i, question] of questions.entries()) {
|
||||
formated.push({
|
||||
id: question.questions_id.id,
|
||||
sort: question.sort,
|
||||
title: getTranslation(question.questions_id.translations, lang, 'title'),
|
||||
answers: formatAnswers(question.questions_id.answers, lang)
|
||||
})
|
||||
}
|
||||
|
||||
return formated
|
||||
}
|
||||
|
||||
const formatAnswers = (answers, lang) => {
|
||||
const formated = []
|
||||
for (const [i, answer] of answers.entries()) {
|
||||
formated.push({
|
||||
id: answer.answers_id.id,
|
||||
sort: answer.sort,
|
||||
title: getTranslation(answer.answers_id.translations, lang, 'title'),
|
||||
weight: answer.answers_id.weight
|
||||
})
|
||||
}
|
||||
|
||||
return formated
|
||||
}
|
||||
|
||||
const formatScore = (score, lang) => {
|
||||
score.title = getTranslation(score.translations, lang, 'title')
|
||||
delete score.translations
|
||||
|
||||
return score
|
||||
}
|
||||
|
||||
const formatResults = (results, lang) => {
|
||||
const formated = []
|
||||
for (const [i, result] of results.entries()) {
|
||||
formated.push({
|
||||
id: result.results_id.id,
|
||||
sort: result.sort,
|
||||
min: result.results_id.min,
|
||||
max: result.results_id.max,
|
||||
facteur: getTranslation(result.results_id.translations, lang, 'facteur'),
|
||||
effets: getTranslation(result.results_id.translations, lang, 'effets'),
|
||||
pde: getTranslation(result.results_id.translations, lang, 'pde'),
|
||||
pde_qtra: result.results_id.pde_qtra,
|
||||
})
|
||||
}
|
||||
|
||||
return formated
|
||||
}
|
||||
|
||||
const config = {
|
||||
collections: {
|
||||
scores: {
|
||||
readByQueryOption: {
|
||||
fields: ['*', 'translations.*', 'questions.sort', 'questions.questions_id.*', 'questions.questions_id.translations.*', 'questions.questions_id.answers.*', 'questions.questions_id.answers.answers_id.*', 'questions.questions_id.answers.answers_id.translations.*', 'results.*', 'results.results_id.*', 'results.results_id.translations.*']
|
||||
},
|
||||
pathBuilder: (score) => {
|
||||
const lang = 'fr-FR'
|
||||
score = formatScore(score, lang)
|
||||
score.questions = formatQuestions(score.questions, lang)
|
||||
score.results = formatResults(score.results, lang)
|
||||
return `./content`;
|
||||
},
|
||||
deleteFields: ['path']
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
new DirectusToMarkdown(config).export();
|
1
scripts/directus-to-markdown/node_modules/@resilien/directus-to-markdown
generated
vendored
Symbolic link
1
scripts/directus-to-markdown/node_modules/@resilien/directus-to-markdown
generated
vendored
Symbolic link
@ -0,0 +1 @@
|
||||
../../../../themes/hugo-theme-lowtech/node_modules/@resilien/directus-to-markdown
|
1
scripts/directus-to-markdown/node_modules/url-slug
generated
vendored
Symbolic link
1
scripts/directus-to-markdown/node_modules/url-slug
generated
vendored
Symbolic link
@ -0,0 +1 @@
|
||||
../../../themes/hugo-theme-lowtech/node_modules/url-slug
|
11
scripts/directus-to-markdown/package.json
Normal file
11
scripts/directus-to-markdown/package.json
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"name": "directus-to-markdown",
|
||||
"version": "0.0.0",
|
||||
"description": "Translates content from Directus.io to gohugo.io",
|
||||
"main": "index.js",
|
||||
"type": "module",
|
||||
"dependencies": {
|
||||
"@resilien/directus-to-markdown": "file:../../themes/hugo-theme-lowtech/node_modules/@resilien/directus-to-markdown",
|
||||
"url-slug": "file:../../themes/hugo-theme-lowtech/node_modules/url-slug"
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user