refactor: docs (#10126)

This commit is contained in:
Noel
2024-02-29 04:37:52 +01:00
committed by GitHub
parent 0f9017ef95
commit 18cce83d80
192 changed files with 8116 additions and 6321 deletions

View File

@@ -52,10 +52,15 @@ try {
await Promise.all(
indices.map(async (index) => {
console.log(`Uploading ${index.index}...`);
let task;
try {
await client.createIndex(index.index);
task = await client.createIndex(index.index);
} catch {}
if (task) {
await client.waitForTask(task.taskUid);
}
await client.index(index.index).addDocuments(index.data);
}),
);

View File

@@ -1,33 +1,22 @@
import { readFile } from 'node:fs/promises';
import { basename } from 'node:path';
import process from 'node:process';
import { getInput, setFailed } from '@actions/core';
import { getInput } from '@actions/core';
import { create } from '@actions/glob';
import { put } from '@vercel/blob';
import { createPool } from '@vercel/postgres';
if (!process.env.DATABASE_URL) {
setFailed('DATABASE_URL is not set');
}
const pkg = getInput('package') || '*';
const version = getInput('version') || 'main';
const pool = createPool({
connectionString: process.env.DATABASE_URL,
});
const globber = await create(`packages/${pkg}/docs/split/main.*.*.api.json`);
const globber = await create(`packages/${pkg}/docs/${pkg}/split/*.api.json`);
for await (const file of globber.globGenerator()) {
const data = await readFile(file, 'utf8');
try {
console.log(`Uploading ${file} with ${version}...`);
const name = basename(file).replace('main.', '');
const { url } = await put(`${version}.${name}`, data, {
await put(`rewrite/${pkg}/${version}.${name}`, data, {
access: 'public',
addRandomSuffix: false,
});
await pool.sql`insert into documentation (name, version, url) values (${name}, ${version}, ${url}) on conflict (name, version) do update set url = EXCLUDED.url`;
} catch (error) {
console.log(error);
}