fix: use docs structure to resolve doc path
This commit is contained in:
+36
-17
@@ -8,20 +8,23 @@ import { Doc, DocSection } from './../types/types';
|
|||||||
|
|
||||||
const DOCS_PATH = path.join(process.cwd(), 'src/docs');
|
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) {
|
if (doc.copy === undefined) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
return path.join(
|
return path.join(DOCS_PATH, version, docPath, doc.copy);
|
||||||
DOCS_PATH,
|
|
||||||
version,
|
|
||||||
doc.folder,
|
|
||||||
doc.copy
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getExamplePath(version: string, doc: Doc): string {
|
function getExamplePath(
|
||||||
|
version: string,
|
||||||
|
doc: Doc,
|
||||||
|
docPath: string
|
||||||
|
): string {
|
||||||
if (doc.example === undefined) {
|
if (doc.example === undefined) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
@@ -29,7 +32,7 @@ function getExamplePath(version: string, doc: Doc): string {
|
|||||||
return path.join(
|
return path.join(
|
||||||
DOCS_PATH,
|
DOCS_PATH,
|
||||||
version,
|
version,
|
||||||
doc.folder,
|
docPath,
|
||||||
doc.example
|
doc.example
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -80,32 +83,48 @@ function parseMarkdown(sourcePath: string): ReactNode {
|
|||||||
return children;
|
return children;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getCopyChild(version: string, doc: Doc) {
|
function getCopyChild(
|
||||||
const copyPath = getCopyPath(version, doc);
|
version: string,
|
||||||
|
doc: Doc,
|
||||||
|
docPath: string
|
||||||
|
) {
|
||||||
|
const copyPath = getCopyPath(version, doc, docPath);
|
||||||
return parseMarkdown(copyPath);
|
return parseMarkdown(copyPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getExampleChild(version: string, doc: Doc) {
|
function getExampleChild(
|
||||||
const examplePath = getExamplePath(version, doc);
|
version: string,
|
||||||
|
doc: Doc,
|
||||||
|
docPath: string
|
||||||
|
) {
|
||||||
|
const examplePath = getExamplePath(version, doc, docPath);
|
||||||
return parseMarkdown(examplePath);
|
return parseMarkdown(examplePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function loadSections(
|
export function loadSections(
|
||||||
version: string,
|
version: string,
|
||||||
docs: Doc[],
|
docs: Doc[],
|
||||||
sections: DocSection[] = []
|
sections: DocSection[] = [],
|
||||||
|
docPath: string = ''
|
||||||
): DocSection[] {
|
): DocSection[] {
|
||||||
for (const doc of docs) {
|
for (const doc of docs) {
|
||||||
|
const sourcePath = path.join(docPath, doc.folder);
|
||||||
|
|
||||||
if (doc.copy && doc.example) {
|
if (doc.copy && doc.example) {
|
||||||
sections.push({
|
sections.push({
|
||||||
title: doc.title,
|
title: doc.title,
|
||||||
copy: getCopyChild(version, doc),
|
copy: getCopyChild(version, doc, sourcePath),
|
||||||
example: getExampleChild(version, doc),
|
example: getExampleChild(version, doc, sourcePath),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (doc.children && doc.children.length > 0) {
|
if (doc.children && doc.children.length > 0) {
|
||||||
loadSections(version, doc.children, sections);
|
loadSections(
|
||||||
|
version,
|
||||||
|
doc.children,
|
||||||
|
sections,
|
||||||
|
sourcePath
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -42,7 +42,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "TimeSpan",
|
"type": "TimeSpan",
|
||||||
"fieldId": 4810,
|
"fieldId": 4810, // TimeSpan Field
|
||||||
"value": {
|
"value": {
|
||||||
"quantity": 11,
|
"quantity": 11,
|
||||||
"increment": "Seconds",
|
"increment": "Seconds",
|
||||||
|
|||||||
@@ -38,20 +38,19 @@ export const versionTwo: DocsStructure = {
|
|||||||
children: [
|
children: [
|
||||||
{
|
{
|
||||||
title: 'Records',
|
title: 'Records',
|
||||||
folder: 'resources/records',
|
folder: 'records',
|
||||||
copy: 'copy.md',
|
copy: 'copy.md',
|
||||||
example: 'example.md',
|
example: 'example.md',
|
||||||
children: [
|
children: [
|
||||||
{
|
{
|
||||||
title: 'Field Values',
|
title: 'Field Values',
|
||||||
folder: 'resources/records/field_values',
|
folder: 'field_values',
|
||||||
copy: 'copy.md',
|
copy: 'copy.md',
|
||||||
example: 'example.md',
|
example: 'example.md',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'Get Records by App',
|
title: 'Get Records by App',
|
||||||
folder:
|
folder: 'get_records_by_app',
|
||||||
'resources/records/get_records_by_app',
|
|
||||||
copy: 'copy.md',
|
copy: 'copy.md',
|
||||||
example: 'example.md',
|
example: 'example.md',
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user