Skip to content
Snippets Groups Projects
Commit 76142fda authored by Emmanuel Salomon's avatar Emmanuel Salomon :fist:
Browse files

config: move hooks and icons to separate libs

parent 3af9c816
No related branches found
No related tags found
No related merge requests found
export default {
'content:file:beforeParse': (file) => {
// Netlifycms cannot create array in json file at root level and nuxt-content need an array. So, ressources.json is parsed to fetch 'ressources' key.
if (file.extension === '.json' && /.*ressources.json$/.test(file.path)) {
file.data = JSON.stringify(JSON.parse(file.data).ressources)
}
// Split md file with `---`. Used for flat plan.
if (file.extension === '.md' && /^---.*layout:.*---/s.test(file.data)) {
let t = 0
const data = file.data.replace(/---/g, (match) => {
++t
if (t === 2) return '---\n<section>'
if (t > 2) return '</section>\n<section>'
return match
})
file.data = data + '\n</section>'
}
},
async 'content:file:beforeInsert'(document) {
// Routes all /pages/_slug to /_slug
if (document.path.startsWith('/pages/')) {
document.dir = '/'
document.path = document.path.replace('/pages/', '/')
}
if (document.extension === '.md') {
/*
* Add reading time
*/
document.readingTime = require('reading-time')(document.text)
/*
* Add lexique terms and check if terms exist
*/
// Search lexique terms
const lexiqueTerms = [
...document.text.matchAll(
/<lexique[>]([^<]*)<\/|<lexique\s+title="(.*)"/g
),
].map((match) => {
return (match[2] || match[1]).toLowerCase() // Priority for term in title=""
})
if (lexiqueTerms.length) {
// Add terms to document
document.lexiqueTerms = [...new Set(lexiqueTerms)] // remove duplicate
const { $content } = require('@nuxt/content')
// Check if term exists
if ($content) {
for (let i = 0; i < document.lexiqueTerms.length; i++) {
const term = document.lexiqueTerms[i]
const lexique = await $content('lexique')
.where({
$or: [
{ title: { $regex: [`^${term}$`, 'i'] } }, // case insensitive
{ synonyms: { $contains: term } }, // search in synonyms
],
})
.limit(1)
.fetch()
if (!lexique.length) {
// eslint-disable-next-line no-console
console.warn(
`Term "${term}" in file ${
document.path + document.extension
} doesn't exist`
)
}
}
}
}
}
},
}
export default {
regular: ['faClock'],
solid: [
'faHome',
'faSearch',
'faSkullCrossbones',
'faChevronLeft',
'faChevronRight',
'faArrowLeft',
'faArrowRight',
'faSun',
'faMoon',
'faHeart',
'faInfoCircle',
'faCheckCircle',
'faCheck',
'faExclamationCircle',
'faExclamationTriangle',
'faExternalLinkAlt',
'faBars',
'faUserCircle',
'faGlobe',
'faAngry',
'faCompressArrowsAlt',
'faExpandArrowsAlt',
'faFont',
'faWheelchair',
'faCaretDown',
],
brands: [
'faCreativeCommonsNcEu',
'faDiaspora',
'faDiscourse',
'faGithub',
'faGitlab',
'faYoutube',
'faRocketchat',
'faFacebook',
'faTwitter',
'faDiscord',
'faApple',
'faAndroid',
'faBitcoin',
'faChrome',
'faFirefox',
'faCodepen',
'faDev',
'faDocker',
'faDropbox',
'faMastodon',
'faMedium',
'faNpm',
'faReddit',
'faSlack',
'faSoundcloud',
'faSpotify',
'faSteam',
'faTeamspeak',
'faTelegram',
'faTrello',
'faVimeo',
'faWhatsapp',
'faWikipediaW',
'faWordpress',
],
}
import i18n from './plugins/i18n.js' import i18n from './plugins/i18n.js'
import config from './static/settings/globals.json' import config from './static/settings/globals.json'
import hooks from './libs/hooks.js'
import icons from './libs/icons.js'
export default { export default {
target: 'static', target: 'static',
...@@ -66,72 +68,7 @@ export default { ...@@ -66,72 +68,7 @@ export default {
{ {
component: 'fa', // component name component: 'fa', // component name
addCss: false, addCss: false,
icons: { icons,
regular: ['faClock'],
solid: [
'faHome',
'faSearch',
'faSkullCrossbones',
'faChevronLeft',
'faChevronRight',
'faArrowLeft',
'faArrowRight',
'faSun',
'faMoon',
'faHeart',
'faInfoCircle',
'faCheckCircle',
'faCheck',
'faExclamationCircle',
'faExclamationTriangle',
'faExternalLinkAlt',
'faBars',
'faUserCircle',
'faGlobe',
'faAngry',
'faCompressArrowsAlt',
'faExpandArrowsAlt',
'faFont',
'faWheelchair',
'faCaretDown',
],
brands: [
'faCreativeCommonsNcEu',
'faDiaspora',
'faDiscourse',
'faGithub',
'faGitlab',
'faYoutube',
'faRocketchat',
'faFacebook',
'faTwitter',
'faDiscord',
'faApple',
'faAndroid',
'faBitcoin',
'faChrome',
'faFirefox',
'faCodepen',
'faDev',
'faDocker',
'faDropbox',
'faMastodon',
'faMedium',
'faNpm',
'faReddit',
'faSlack',
'faSoundcloud',
'faSpotify',
'faSteam',
'faTeamspeak',
'faTelegram',
'faTrello',
'faVimeo',
'faWhatsapp',
'faWikipediaW',
'faWordpress',
],
},
}, },
], ],
], ],
...@@ -180,11 +117,6 @@ export default { ...@@ -180,11 +117,6 @@ export default {
}, },
}, },
// https://github.com/Chantouch/nuxt-clipboard
clipboard: {
autoSetContainer: true,
},
// https://content.nuxtjs.org/fr/configuration // https://content.nuxtjs.org/fr/configuration
content: { content: {
markdown: { markdown: {
...@@ -199,80 +131,16 @@ export default { ...@@ -199,80 +131,16 @@ export default {
classSuffix: '', classSuffix: '',
}, },
// https://github.com/Chantouch/nuxt-clipboard
clipboard: {
autoSetContainer: true,
},
/** /**
* Nuxt hooks * Nuxt hooks
* https://nuxtjs.org/docs/2.x/configuration-glossary/configuration-hooks * https://nuxtjs.org/docs/2.x/configuration-glossary/configuration-hooks
*/ */
hooks: { hooks,
// Netlifycms cannot create array in json file at root level and nuxt-content need an array. So, ressources.json is parsed to fetch 'ressources' key.
'content:file:beforeParse': (file) => {
if (file.extension === '.json' && /.*ressources.json$/.test(file.path)) {
file.data = JSON.stringify(JSON.parse(file.data).ressources)
} else if (file.extension === '.md') {
if (/^---.*layout:.*---/s.test(file.data)) {
let t = 0
const data = file.data.replace(/---/g, (match) => {
++t
if (t === 2) return '---\n<section>'
if (t > 2) return '</section>\n<section>'
return match
})
file.data = data + '\n</section>'
}
}
},
async 'content:file:beforeInsert'(document) {
if (document.extension === '.md') {
/*
* Add reading time
*/
document.readingTime = require('reading-time')(document.text)
/*
* Add lexique terms and check if terms exist
*/
// Search lexique terms
const lexiqueTerms = [
...document.text.matchAll(
/<lexique[>]([^<]*)<\/|<lexique\s+title="(.*)"/g
),
].map((match) => {
return (match[2] || match[1]).toLowerCase() // Priority for term in title=""
})
if (lexiqueTerms.length) {
// Add terms to document
document.lexiqueTerms = [...new Set(lexiqueTerms)] // remove duplicate
const { $content } = require('@nuxt/content')
// Check if term exists
if ($content) {
for (let i = 0; i < document.lexiqueTerms.length; i++) {
const term = document.lexiqueTerms[i]
const lexique = await $content('lexique')
.where({
$or: [
{ title: { $regex: [`^${term}$`, 'i'] } }, // case insensitive
{ synonyms: { $contains: term } }, // search in synonyms
],
})
.limit(1)
.fetch()
if (!lexique.length) {
// eslint-disable-next-line no-console
console.warn(
`Term "${term}" in file ${
document.path + document.extension
} doesn't exist`
)
}
}
}
}
}
},
},
/** /**
* Build configuration * Build configuration
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment