docs-util: add support for workflows in markdown theme (#8485)

* add template for workflows

* initial changes

* added support for parallel steps

* added support for when

* added merge options

* fix merge options

* fix to tooltip

* clean up

* remove redirects

* fixes

* theme fixes + added merge options

* generate hook examples + fixes

* changed namespaces

* add custom autogenerator

* change type of additional data
This commit is contained in:
Shahed Nasser
2024-08-09 16:35:52 +03:00
committed by GitHub
parent 79b49c1288
commit a19c562bec
58 changed files with 2098 additions and 328 deletions

View File

@@ -0,0 +1,88 @@
import { getSidebarItemLink, ItemsToAdd } from "build-scripts"
import { existsSync, readdirSync } from "fs"
import path from "path"
export default async function getCoreFlowsRefSidebarChildren(): Promise<
ItemsToAdd[]
> {
const projPath = path.resolve()
const basePath = path.join(projPath, "references", "core_flows")
const directories = readdirSync(basePath, {
withFileTypes: true,
})
const sidebarItems: ItemsToAdd[] = []
for (const directory of directories) {
if (
!directory.isDirectory() ||
directory.name.startsWith("core_flows.") ||
directory.name === "types" ||
directory.name === "interfaces"
) {
continue
}
const namespaceBasePath = path.join(basePath, directory.name, "functions")
if (!existsSync(namespaceBasePath)) {
continue
}
const childDirs = readdirSync(namespaceBasePath, {
withFileTypes: true,
})
const workflowItems: ItemsToAdd[] = []
const stepItems: ItemsToAdd[] = []
for (const childDir of childDirs) {
if (!childDir.isDirectory()) {
continue
}
const childDirPath = path.join(namespaceBasePath, childDir.name)
const childFile = readdirSync(childDirPath)
const sidebarItem = await getSidebarItemLink({
filePath: path.join(childDirPath, childFile[0]),
basePath: projPath,
fileBasename: childFile[0],
})
if (sidebarItem) {
if (childDir.name.endsWith("Workflow")) {
workflowItems.push(sidebarItem)
} else {
stepItems.push(sidebarItem)
}
}
}
if (workflowItems.length || stepItems.length) {
const item: ItemsToAdd = {
title: directory.name.replaceAll("_", " "),
children: [],
}
if (workflowItems.length) {
item.children!.push({
title: "Workflows",
children: workflowItems,
})
}
if (stepItems.length) {
item.children!.push({
title: "Steps",
children: stepItems,
})
}
sidebarItems.push(item)
}
}
return sidebarItems
}

View File

@@ -0,0 +1,42 @@
import { getFrontMatterUtil } from "remark-rehype-plugins"
import { ItemsToAdd, sidebarAttachHrefCommonOptions } from "../index.js"
import { readFileSync } from "fs"
import findMetadataTitle from "./find-metadata-title.js"
import findPageHeading from "./find-page-heading.js"
export async function getSidebarItemLink({
filePath,
basePath,
fileBasename,
}: {
filePath: string
basePath: string
fileBasename: string
}): Promise<ItemsToAdd | undefined> {
const frontmatter = await getFrontMatterUtil(filePath)
if (frontmatter.sidebar_autogenerate_exclude) {
return
}
const fileContent = frontmatter.sidebar_label
? ""
: readFileSync(filePath, "utf-8")
const newItem = sidebarAttachHrefCommonOptions([
{
path:
frontmatter.slug ||
filePath.replace(basePath, "").replace(`/${fileBasename}`, ""),
title:
frontmatter.sidebar_label ||
findMetadataTitle(fileContent) ||
findPageHeading(fileContent) ||
"",
},
])[0]
return {
...newItem,
sidebar_position: frontmatter.sidebar_position,
}
}