Skip to content
Snippets Groups Projects
Commit 1c6379a4 authored by Mark Kane's avatar Mark Kane
Browse files

planning#367 improve parser to handle 3 levels,

create initial import of FAQ data
parent 135d6877
No related branches found
No related tags found
1 merge request!160fit-connect/planning#320 Erweiterung FAQ
...@@ -2,13 +2,7 @@ const fs = require('fs'); ...@@ -2,13 +2,7 @@ const fs = require('fs');
const readline = require('readline'); const readline = require('readline');
const faq = { const faq = {
groups: [ groups: []
{
name: 'FAQs',
anchor: "general",
subgroups: []
}
]
}; };
async function parseFaq() { async function parseFaq() {
...@@ -27,7 +21,16 @@ async function parseFaq() { ...@@ -27,7 +21,16 @@ async function parseFaq() {
if (line.startsWith('# ')) { if (line.startsWith('# ')) {
const name = line.substring(2); const name = line.substring(2);
// new subgroup (should be group, but as of 22-03-22 there is only 1 group in most of md doc) lastSubgroup = 0;
faq
.groups
.push({ name, anchor: slugify(name), subgroups: [] });
lastGroup = faq.groups.length - 1;
console.log('group, index, subgroups: ', faq.groups[lastGroup], lastGroup, lastSubgroup);
} else if (line.startsWith('## ')) {
const name = line.substring(3);
lastItem = 0; lastItem = 0;
faq faq
.groups[lastGroup] .groups[lastGroup]
...@@ -35,9 +38,7 @@ async function parseFaq() { ...@@ -35,9 +38,7 @@ async function parseFaq() {
.push({ name, anchor: slugify(name), items: [] }); .push({ name, anchor: slugify(name), items: [] });
lastSubgroup = faq.groups[lastGroup].subgroups.length - 1; lastSubgroup = faq.groups[lastGroup].subgroups.length - 1;
// console.log('subgroup, item: ', lastSubgroup, lastItem); console.log('subgroup, item: ', lastSubgroup, lastItem);
} else if (line.startsWith('## ')) {
// should be subgroup, but as of 22-03-22 there is only 1 group in most of md doc)
} else if (line.startsWith('### ')) { } else if (line.startsWith('### ')) {
const title = line.substring(4); const title = line.substring(4);
...@@ -52,38 +53,49 @@ async function parseFaq() { ...@@ -52,38 +53,49 @@ async function parseFaq() {
// console.log('subgroup, item: ', lastSubgroup, lastItem); // console.log('subgroup, item: ', lastSubgroup, lastItem);
} else if (!line.startsWith('[')) { } else if (!line.startsWith('[')) {
let newLine = line; let newLine = line;
if (newLine.length > 0) {
// look for markdown URLs // look for markdown URLs
const mdRegex = /\[([^\[]+)\]\((.*?)\)/; const mdRegex = /\[([^\[]+)\]\((.*?)\)/;
const mdUrl = line.match(mdRegex); const mdUrl = line.match(mdRegex);
if (mdUrl) { if (mdUrl) {
console.log('mdUrl: ', mdUrl); // console.log('mdUrl: ', mdUrl);
newLine = newLine.replace(mdUrl[0], newLine = newLine.replace(mdUrl[0],
` <Link to={'${mdUrl[2]}'}>${mdUrl[1]}</Link> `); ` <Link to={'${mdUrl[2]}'}>${mdUrl[1]}</Link> `);
} else { } else {
// look for raw URLs // look for raw URLs
const urlRegex = /(https?:\/\/[^ ]*)/; const urlRegex = /(https?:\/\/[^ ]*)/;
const url = newLine.match(urlRegex); const url = newLine.match(urlRegex);
if (url) { if (url) {
newLine = newLine.replace(url[1], newLine = newLine.replace(url[1],
` <Link to={'${url[1]}'}>${url[1]}</Link> `); ` <Link to={'${url[1]}'}>${url[1]}</Link> `);
}
} }
}
// everything else is text of the last item
let item = faq.groups[lastGroup].subgroups[lastSubgroup].items[lastItem];
faq
.groups[lastGroup]
.subgroups[lastSubgroup]
.items[lastItem]
.content = item.content + newLine;
}
} else if (line.indexOf('[not ready]') >= 0) {
// everything else is text of the last item // everything else is text of the last item
let item = faq.groups[lastGroup].subgroups[lastSubgroup].items[lastItem]; let item = faq.groups[lastGroup].subgroups[lastSubgroup].items[lastItem];
// console.log('item: ', item); item.notReady = true;
faq
.groups[lastGroup]
.subgroups[lastSubgroup]
.items[lastItem]
.content = item.content + newLine;
} }
} }
// remove notReady items
faq.groups.forEach(g => {
g.subgroups.forEach(sg => {
sg.items = sg.items.filter(i => i.notReady !== true && i.content.length > 0)
})
})
// console.log(faq.groups[0]); // console.log(faq.groups[0]);
let data = JSON.stringify(faq, null, 2); let data = JSON.stringify(faq, null, 2);
fs.writeFileSync('scripts/faq.json', data); fs.writeFileSync('src/data/faq-parsed.json', data);
} }
function slugify(value) { function slugify(value) {
......
This diff is collapsed.
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