UNPKG

@graphql-markdown/docusaurus

Version:

Docusaurus plugin for generating Markdown documentation from a GraphQL schema.

36 lines (35 loc) 1.56 kB
"use strict"; /** * @module mdx * This module provides utilities for generating MDX index files in Docusaurus format. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.generateIndexMetafile = void 0; const node_path_1 = require("node:path"); const utils_1 = require("@graphql-markdown/utils"); const CATEGORY_YAML = "_category_.yml"; var SidebarPosition; (function (SidebarPosition) { SidebarPosition[SidebarPosition["FIRST"] = 1] = "FIRST"; SidebarPosition[SidebarPosition["LAST"] = 999] = "LAST"; })(SidebarPosition || (SidebarPosition = {})); const generateIndexMetafile = async (dirPath, category, options) => { const filePath = (0, node_path_1.join)(dirPath, CATEGORY_YAML); if (await (0, utils_1.fileExists)(filePath)) { return; } const label = (0, utils_1.startCase)(category); const link = options?.index !== true ? "null" : `\n type: generated-index\n title: '${label} overview'`; const className = typeof options?.styleClass === "string" ? `className: ${options.styleClass}\n` : ""; const position = typeof options?.sidebarPosition === "number" ? options.sidebarPosition : SidebarPosition.FIRST; const content = `label: ${label}\nposition: ${position}\n${className}link: ${link}\ncollapsible: ${options?.collapsible ?? true}\ncollapsed: ${options?.collapsed ?? true}\n`; await (0, utils_1.ensureDir)(dirPath); await (0, utils_1.saveFile)(filePath, content); }; exports.generateIndexMetafile = generateIndexMetafile;