Files
opencloud/services/groupware/apidoc-postprocess-html.ts
Pascal Bleser 0cce8f5df3 docs(groupware): OpenAPI improvements
* refactor some pkg/jmap and groupware methods to make more sense from
   an API point-of-view

 * add path parameter documentation, but automate it by injecting their
   definition into the OpenAPI YAML tree that is extracted from the
   source code using go-swagger as it is too cumbersome, repetitive and
   error-prine to document them in the source code; wrote a TypeScript
   file apidoc-process.ts to do so

 * add generating an offline HTML file for the OpenAPI documentation
   using redocly, and injecting a favicon into the resulting HTML; wrote
   a TypeScript file apidoc-postprocess-html.ts to do so
2026-01-22 09:42:22 +01:00

26 lines
675 B
TypeScript

import * as fs from 'fs'
import * as cheerio from 'cheerio'
const faviconFile = process.argv[2]
const favicon = fs.readFileSync(faviconFile).toString('base64')
let html = ''
process.stdin.on('data', (chunk) => {
html += chunk.toString()
})
process.stdin.on('end', () => {
try {
const $ = cheerio.load(html)
$('head').append(`<link rel="icon" href="data:image/png;base64,${favicon}">`)
process.stdout.write($.html())
process.stdout.write("\n")
} catch (error) {
if (error instanceof Error) {
console.error(`Error occured while post-processing HTML: ${error.message}`)
} else {
console.error("Unknown error occurred")
}
}
});