mirror of
https://github.com/lovell/sharp.git
synced 2025-12-19 07:15:08 +01:00
Docs: migrate to Astro Starlight
This commit is contained in:
42
docs/build.mjs
Normal file
42
docs/build.mjs
Normal file
@@ -0,0 +1,42 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
import fs from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
import jsdoc2md from 'jsdoc-to-markdown';
|
||||
|
||||
const pages = {
|
||||
constructor: 'Constructor',
|
||||
input: 'Input metadata',
|
||||
resize: 'Resizing images',
|
||||
composite: 'Compositing images',
|
||||
operation: 'Image operations',
|
||||
colour: 'Colour manipulation',
|
||||
channel: 'Channel manipulation',
|
||||
output: 'Output options',
|
||||
utility: 'Global properties'
|
||||
};
|
||||
|
||||
Object.keys(pages).forEach(async (m) => {
|
||||
const input = path.join('lib', `${m}.js`);
|
||||
const output = path.join('docs', 'src', 'content', 'docs', `api-${m}.md`);
|
||||
|
||||
const ast = await jsdoc2md.getTemplateData({ files: input });
|
||||
const markdown = await jsdoc2md.render({
|
||||
data: ast,
|
||||
'global-index-format': 'none',
|
||||
'module-index-format': 'none'
|
||||
});
|
||||
|
||||
const cleanMarkdown =
|
||||
`---\ntitle: ${pages[m]}\n---\n\n` +
|
||||
markdown
|
||||
.replace(/(## )([A-Za-z0-9]+)([^\n]*)/g, '$1$2\n> $2$3\n') // simplify headings
|
||||
.replace(/<a name="[A-Za-z0-9+]+"><\/a>/g, '') // remove anchors
|
||||
.replace(/\*\*Kind\*\*: global[^\n]+/g, '') // remove all "global" Kind labels (requires JSDoc refactoring)
|
||||
.trim();
|
||||
|
||||
await fs.writeFile(output, cleanMarkdown);
|
||||
});
|
||||
Reference in New Issue
Block a user