import fs from 'fs';
import path from 'path';
import typedocConfig from '../typedoc.json' with {type: 'json'};
import packageJson from '../package.json' with {type: 'json'};
import {get} from 'https';
import sharp from 'sharp';
import EXAMPLE_CATEGORY_GROUPS from '../docs/example-categories.json' with {type: 'json'};
type HtmlDoc = {
title: string;
description: string;
mdFileName: string;
isNew: boolean;
category: string;
order: number;
};
/**
* Reads the `content` of the `` tag with the given `property`, e.g. `og:description`.
*/
function extractMetaContent(htmlContentLines: string[], property: string): string | undefined {
const line = htmlContentLines.find(l => l.includes(property));
return line?.match(/content=(["'])(.*?)\1/)?.[2];
}
function generateAPIIntroMarkdown(lines: string[]): string {
let intro = `# Intro
This file is intended as a reference for the important and public classes of this API.
We recommend looking at the [examples](../examples/index.md) as they will help you the most to start with MapLibre.
Most of the classes written here have an "Options" object for initialization, it is recommended to check which options exist.
It is recommended to import what you need and then use it. Some examples for classes assume you did that.
For example, import the \`Map\` class like this:
\`\`\`ts
import {Map} from 'maplibre-gl';
const map = new Map(...)
\`\`\`
Import declarations are omitted from the examples for brevity.
`;
intro += lines.map(l => l.replace('../', './')).join('\n');
return intro;
}
function isNewExample(htmlContentLines: string[]): boolean {
const createdLine = htmlContentLines.find(l => l.includes('og:created'));
if (!createdLine) return false;
const match = createdLine.match(/content=["'](\d{4}-\d{2}-\d{2})["']/);
if (!match) return false;
const createdDate = new Date(match[1]);
const sixMonthsAgo = new Date();
sixMonthsAgo.setMonth(sixMonthsAgo.getMonth() - 6);
return createdDate >= sixMonthsAgo;
}
function extractJsFromHtml(htmlContent: string): string | null {
const scriptRegex = /