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

split from beforeParse hook

parent 755251ee
No related branches found
No related tags found
No related merge requests found
......@@ -206,9 +206,20 @@ export default {
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))
return
file.data = JSON.stringify(JSON.parse(file.data).ressources)
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') {
......
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