From 4268a1509b77ef22f6ae111aef6cb38951ddad00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleksi=20K=C3=A4=C3=A4ri=C3=A4inen?= Date: Mon, 18 Dec 2023 13:58:22 +0200 Subject: [PATCH 1/2] script writes only the description part of the bundle files --- scripts/generateDocs.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/scripts/generateDocs.js b/scripts/generateDocs.js index f91727b..1efd009 100644 --- a/scripts/generateDocs.js +++ b/scripts/generateDocs.js @@ -97,9 +97,20 @@ const generateFlattenedFile = (filter, filename, fileHeading) => { ), 'utf-8' ); + + const headingEnd = fileContent.indexOf('\n'); + // Write bundle heading fs.appendFileSync( flattenedFileName, - `# ${fileHeading}.${sectionHeadingNumber}${fileContent.slice(1, fileContent.length)}\n` + `# ${fileHeading}.${sectionHeadingNumber}${fileContent.slice(1, headingEnd)}\n` + ); + + const descriptionStart = fileContent.indexOf("## Description"); + const descriptionEnd = fileContent.indexOf("## ", descriptionStart + 1); + // Write bundle description + fs.appendFileSync( + flattenedFileName, + `\n${fileContent.slice(descriptionStart, descriptionEnd - 1)}` ); sectionHeadingNumber++; } From 33edadcce9a4cb1d9ef0f892f117f8f26751047e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleksi=20K=C3=A4=C3=A4ri=C3=A4inen?= Date: Mon, 18 Dec 2023 15:30:45 +0200 Subject: [PATCH 2/2] Add linking from requests and events to bundles --- scripts/generateDocs.js | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/scripts/generateDocs.js b/scripts/generateDocs.js index 1efd009..b4f1d57 100644 --- a/scripts/generateDocs.js +++ b/scripts/generateDocs.js @@ -73,7 +73,7 @@ for (const [sectionTitle, frontendPath] of Object.entries(filesToHandle)) { * filename: the filename to be generated * fileHeading: the section number of the file, i.e. 2.3, 2.4 etc. */ -const generateFlattenedFile = (filter, filename, fileHeading) => { +const generateFlattenedFile = (filter, filename, fileHeading, includeLinks) => { // Get wanted filenames by reading all files in frontend/api and applying filter to result const files = fs.readdirSync( path.join(pathToFrontendRepository, "api/"), @@ -102,21 +102,41 @@ const generateFlattenedFile = (filter, filename, fileHeading) => { // Write bundle heading fs.appendFileSync( flattenedFileName, - `# ${fileHeading}.${sectionHeadingNumber}${fileContent.slice(1, headingEnd)}\n` + `# ${fileHeading}.${sectionHeadingNumber}${fileContent.slice(1, headingEnd)}` ); - const descriptionStart = fileContent.indexOf("## Description"); - const descriptionEnd = fileContent.indexOf("## ", descriptionStart + 1); - // Write bundle description + const searchKey = "## Description" + let descriptionStart = fileContent.indexOf(searchKey); + let descriptionEnd = 0; + + // If file does not contain the description subheading, append the whole file except the heading + if (descriptionStart == -1) { + descriptionStart = headingEnd; + descriptionEnd = fileContent.length; + } else { + descriptionEnd = fileContent.indexOf("## ", descriptionStart + 1); + descriptionStart = descriptionStart + searchKey.length; + } + fs.appendFileSync( flattenedFileName, - `\n${fileContent.slice(descriptionStart, descriptionEnd - 1)}` + `${fileContent.slice(descriptionStart, descriptionEnd)}\n` ); + + // Append links to oskari.org documentation for each request/event + if (includeLinks) { + const bundleName = path.dirname(dirent.path).split("api")[1].replaceAll('\\', '/'); + fs.appendFileSync( + flattenedFileName, + `\n\nIncluded in bundle: [${bundleName}](https://oskari.org/api/bundles#${version}${bundleName})\n\n` + ); + } + sectionHeadingNumber++; } ); } -generateFlattenedFile(dirent => dirent.name === "bundle.md", "Bundles", "2.3"); -generateFlattenedFile(dirent => dirent.name.toLowerCase().includes("request.md"), "Bundle requests", "2.4"); -generateFlattenedFile(dirent => dirent.name.toLowerCase().includes("event.md"), "Bundle events", "2.5"); \ No newline at end of file +generateFlattenedFile(dirent => dirent.name === "bundle.md", "Bundles", "2.3", false); +generateFlattenedFile(dirent => dirent.name.toLowerCase().includes("request.md"), "Bundle requests", "2.4", true); +generateFlattenedFile(dirent => dirent.name.toLowerCase().includes("event.md"), "Bundle events", "2.5", true); \ No newline at end of file