fix: use docs structure to resolve doc path

This commit is contained in:
Stevan Freeborn
2023-04-13 20:29:27 -05:00
parent d456ddfad6
commit 25d7a70f4e
5 changed files with 40 additions and 22 deletions
+36 -17
View File
@@ -8,20 +8,23 @@ import { Doc, DocSection } from './../types/types';
const DOCS_PATH = path.join(process.cwd(), 'src/docs');
function getCopyPath(version: string, doc: Doc): string {
function getCopyPath(
version: string,
doc: Doc,
docPath: string
): string {
if (doc.copy === undefined) {
return '';
}
return path.join(
DOCS_PATH,
version,
doc.folder,
doc.copy
);
return path.join(DOCS_PATH, version, docPath, doc.copy);
}
function getExamplePath(version: string, doc: Doc): string {
function getExamplePath(
version: string,
doc: Doc,
docPath: string
): string {
if (doc.example === undefined) {
return '';
}
@@ -29,7 +32,7 @@ function getExamplePath(version: string, doc: Doc): string {
return path.join(
DOCS_PATH,
version,
doc.folder,
docPath,
doc.example
);
}
@@ -80,32 +83,48 @@ function parseMarkdown(sourcePath: string): ReactNode {
return children;
}
function getCopyChild(version: string, doc: Doc) {
const copyPath = getCopyPath(version, doc);
function getCopyChild(
version: string,
doc: Doc,
docPath: string
) {
const copyPath = getCopyPath(version, doc, docPath);
return parseMarkdown(copyPath);
}
function getExampleChild(version: string, doc: Doc) {
const examplePath = getExamplePath(version, doc);
function getExampleChild(
version: string,
doc: Doc,
docPath: string
) {
const examplePath = getExamplePath(version, doc, docPath);
return parseMarkdown(examplePath);
}
export function loadSections(
version: string,
docs: Doc[],
sections: DocSection[] = []
sections: DocSection[] = [],
docPath: string = ''
): DocSection[] {
for (const doc of docs) {
const sourcePath = path.join(docPath, doc.folder);
if (doc.copy && doc.example) {
sections.push({
title: doc.title,
copy: getCopyChild(version, doc),
example: getExampleChild(version, doc),
copy: getCopyChild(version, doc, sourcePath),
example: getExampleChild(version, doc, sourcePath),
});
}
if (doc.children && doc.children.length > 0) {
loadSections(version, doc.children, sections);
loadSections(
version,
doc.children,
sections,
sourcePath
);
}
}
+1 -1
View File
@@ -42,7 +42,7 @@
},
{
"type": "TimeSpan",
"fieldId": 4810,
"fieldId": 4810, // TimeSpan Field
"value": {
"quantity": 11,
"increment": "Seconds",
+3 -4
View File
@@ -38,20 +38,19 @@ export const versionTwo: DocsStructure = {
children: [
{
title: 'Records',
folder: 'resources/records',
folder: 'records',
copy: 'copy.md',
example: 'example.md',
children: [
{
title: 'Field Values',
folder: 'resources/records/field_values',
folder: 'field_values',
copy: 'copy.md',
example: 'example.md',
},
{
title: 'Get Records by App',
folder:
'resources/records/get_records_by_app',
folder: 'get_records_by_app',
copy: 'copy.md',
example: 'example.md',
},