docs: fix algolia cron script (#8701)

This commit is contained in:
Shahed Nasser authored and GitHub committed 2024-08-21 20:01:36 +02:00
1 parent cb6cc79018
commit a3c311126e
1 file changed
+54 -58
+54 -58
View File
@@ -2,7 +2,6 @@ import OpenAPIParser from "@readme/openapi-parser"
import algoliasearch from "algoliasearch" import algoliasearch from "algoliasearch"
import type { ExpandedDocument, Operation } from "../../../types/openapi" import type { ExpandedDocument, Operation } from "../../../types/openapi"
import path from "path" import path from "path"
import getPathsOfTag from "../../../utils/get-paths-of-tag"
import getSectionId from "../../../utils/get-section-id" import getSectionId from "../../../utils/get-section-id"
import { NextResponse } from "next/server" import { NextResponse } from "next/server"
import { JSDOM } from "jsdom" import { JSDOM } from "jsdom"
@@ -50,74 +49,71 @@ export async function GET() {
// find and index tag and operations // find and index tag and operations
const baseSpecs = (await OpenAPIParser.parse( const baseSpecs = (await OpenAPIParser.parse(
path.join(process.cwd(), `specs/${area}/openapi.yaml`) path.join(process.cwd(), `specs/${area}/openapi.full.yaml`)
)) as ExpandedDocument )) as ExpandedDocument
await Promise.all( baseSpecs.tags?.map((tag) => {
baseSpecs.tags?.map(async (tag) => { const tagName = getSectionId([tag.name])
const tagName = getSectionId([tag.name]) const url = getUrl(area, tagName)
const url = getUrl(area, tagName) indices.push({
objectID: getObjectId(area, tagName),
hierarchy: getHierarchy(area, [tag.name]),
type: "lvl1",
content: null,
url,
url_without_variables: url,
url_without_anchor: url,
...defaultIndexData,
})
})
const paths = baseSpecs.paths
Object.values(paths).forEach((path) => {
Object.values(path).forEach((op) => {
const operation = op as Operation
const tag = operation.tags?.[0]
const operationName = getSectionId([tag || "", operation.operationId])
const url = getUrl(area, operationName)
indices.push({ indices.push({
objectID: getObjectId(area, tagName), objectID: getObjectId(area, operationName),
hierarchy: getHierarchy(area, [tag.name]), hierarchy: getHierarchy(area, [tag || "", operation.summary]),
type: "lvl1", type: "content",
content: null, content: operation.summary,
content_camel: operation.summary,
url, url,
url_without_variables: url, url_without_variables: url,
url_without_anchor: url, url_without_anchor: url,
...defaultIndexData, ...defaultIndexData,
}) })
const paths = await getPathsOfTag(tagName, area)
Object.values(paths.paths).forEach((path) => { // index its description
Object.values(path).forEach((op) => { const operationDescriptionId = getSectionId([
const operation = op as Operation tag || "",
const operationName = getSectionId([ operation.operationId,
tag.name, operation.description.substring(
operation.operationId, 0,
]) Math.min(20, operation.description.length)
const url = getUrl(area, operationName) ),
indices.push({ ])
objectID: getObjectId(area, operationName),
hierarchy: getHierarchy(area, [tag.name, operation.summary]),
type: "content",
content: operation.summary,
content_camel: operation.summary,
url,
url_without_variables: url,
url_without_anchor: url,
...defaultIndexData,
})
// index its description indices.push({
const operationDescriptionId = getSectionId([ objectID: getObjectId(area, operationDescriptionId),
tag.name, hierarchy: getHierarchy(area, [
operation.operationId, tag || "",
operation.description.substring( operation.summary,
0, operation.description,
Math.min(20, operation.description.length) ]),
), type: "content",
]) content: operation.description,
content_camel: operation.description,
indices.push({ url,
objectID: getObjectId(area, operationDescriptionId), url_without_variables: url,
hierarchy: getHierarchy(area, [ url_without_anchor: url,
tag.name, ...defaultIndexData,
operation.summary,
operation.description,
]),
type: "content",
content: operation.description,
content_camel: operation.description,
url,
url_without_variables: url,
url_without_anchor: url,
...defaultIndexData,
})
})
}) })
}) || [] })
) })
} }
if (indices.length) { if (indices.length) {