docs: add starlight (#1859)
Co-authored-by: uncenter <[email protected]> Co-authored-by: Hammy <[email protected]> Co-authored-by: WalkQuackBack <[email protected]>
This commit is contained in:
46 files changed
+5967
-522
No files matched your search
@@ -2,12 +2,10 @@ import * as path from "@std/path";
|
||||
import { REPO_ROOT } from "@/constants.ts";
|
||||
|
||||
import { syncIssueLabels } from "@/generate/labels.ts";
|
||||
import { generateMainReadme } from "@/generate/readme-repo.ts";
|
||||
import { generateStyleReadmes } from "@/generate/readme-styles.ts";
|
||||
import { writeWithPreamble } from "@/generate/utils.ts";
|
||||
import {
|
||||
getAuthenticatedOctokit,
|
||||
getCategoriesData,
|
||||
getUserstylesData,
|
||||
getUserstylesTeamMembers,
|
||||
} from "@/utils.ts";
|
||||
@@ -19,12 +17,7 @@ if (!Deno.env.get("CI")) {
|
||||
}
|
||||
|
||||
const userstylesData = getUserstylesData();
|
||||
const categoriesData = await getCategoriesData();
|
||||
|
||||
/**
|
||||
* Generate the main README.md, listing all ports as a table of contents
|
||||
*/
|
||||
await generateMainReadme(userstylesData.userstyles, categoriesData);
|
||||
/**
|
||||
* Generate README.md files for each style
|
||||
*/
|
||||
|
||||
@@ -1,98 +0,0 @@
|
||||
import type { CategoriesSchema, UserstylesSchema } from "@/types/mod.ts";
|
||||
import { REPO_ROOT } from "@/constants.ts";
|
||||
|
||||
import * as path from "@std/path";
|
||||
import Handlebars from "handlebars";
|
||||
|
||||
import { updateReadme } from "@/generate/utils.ts";
|
||||
|
||||
type MappedPorts = {
|
||||
[k: string]: (
|
||||
UserstylesSchema.Userstyle & { path: string }
|
||||
)[];
|
||||
};
|
||||
|
||||
export async function generateMainReadme(
|
||||
userstyles: UserstylesSchema.Userstyles,
|
||||
categoriesData: CategoriesSchema.CategoryDefinitions,
|
||||
) {
|
||||
if (!categoriesData) throw ("Categories data is missing categories");
|
||||
|
||||
const categorized = Object.entries(userstyles)
|
||||
.reduce((acc, [slug, { categories, supports, ...userstyle }]) => {
|
||||
// initialize category array if it doesn't exist
|
||||
// only care about the first (primary) category in the categories array
|
||||
acc[categories[0]] ??= [];
|
||||
|
||||
const baseUserstyle = {
|
||||
path: `styles/${slug}`,
|
||||
categories,
|
||||
...userstyle,
|
||||
};
|
||||
|
||||
acc[categories[0]].push(
|
||||
baseUserstyle,
|
||||
// supported websites themed by the userstyle are added as their own entries for the README
|
||||
...(Object.values(supports ?? {}).map(({ name, link }) => ({
|
||||
...baseUserstyle,
|
||||
name,
|
||||
link,
|
||||
}))),
|
||||
);
|
||||
|
||||
// sort by name
|
||||
acc[categories[0]].sort((a, b) => a.name.localeCompare(b.name));
|
||||
|
||||
return acc;
|
||||
}, {} as MappedPorts);
|
||||
|
||||
const portListData = categoriesData
|
||||
.filter((category) => categorized[category.key] !== undefined)
|
||||
.map((category) => {
|
||||
return { meta: category, ports: categorized[category.key] };
|
||||
});
|
||||
|
||||
const portContent = Handlebars.compile(`{{#each category}}
|
||||
<details open>
|
||||
<summary>{{emoji}} {{name}}</summary>
|
||||
|
||||
{{#each ports}}
|
||||
- {{#unless maintained}}❤️🩹 {{/unless}}[{{ name }}]({{ path }})
|
||||
{{/each}}
|
||||
|
||||
</details>
|
||||
{{/each}}
|
||||
`)({
|
||||
category: portListData.map(({ meta, ports }) => {
|
||||
return {
|
||||
emoji: meta.emoji,
|
||||
name: meta.name,
|
||||
ports: ports.map(
|
||||
(
|
||||
{
|
||||
name,
|
||||
path,
|
||||
"current-maintainers": currentMaintainers,
|
||||
},
|
||||
) => {
|
||||
return {
|
||||
name,
|
||||
maintained: currentMaintainers.length > 0,
|
||||
path,
|
||||
};
|
||||
},
|
||||
),
|
||||
};
|
||||
}),
|
||||
});
|
||||
|
||||
const readmePath = path.join(REPO_ROOT, "README.md");
|
||||
await Deno.writeTextFile(
|
||||
readmePath,
|
||||
updateReadme({
|
||||
readme: Deno.readTextFileSync(readmePath),
|
||||
section: "userstyles",
|
||||
newContent: portContent,
|
||||
}),
|
||||
).catch((e) => console.error(e));
|
||||
}
|
||||
@@ -21,7 +21,7 @@
|
||||
|
||||
{{/if~}}
|
||||
|
||||
See [the userstyle usage instructions](../../docs/USAGE.md).
|
||||
See [the userstyle usage instructions](https://userstyles.catppuccin.com/getting-started/usage/).
|
||||
|
||||
{{#if note}}
|
||||
> [!NOTE]
|
||||
@@ -55,4 +55,4 @@ This userstyle currently lacks maintainers, and may not work correctly. Please f
|
||||
Copyright © 2021-present <a href="https://github.com/catppuccin" target="_blank">Catppuccin Org</a>
|
||||
</p>
|
||||
|
||||
<!-- AUTOGEN:README END -->
|
||||
<!-- AUTOGEN:README END -->
|
||||
@@ -7,27 +7,3 @@ export function writeWithPreamble(
|
||||
"# THIS FILE IS AUTOGENERATED. DO NOT EDIT IT BY HAND.\n" + fileContent,
|
||||
);
|
||||
}
|
||||
|
||||
export function updateReadme({
|
||||
readme,
|
||||
section,
|
||||
newContent,
|
||||
}: {
|
||||
readme: string;
|
||||
section: string;
|
||||
newContent: string;
|
||||
}): string {
|
||||
const preamble =
|
||||
"<!-- The following section is auto-generated, do not edit. -->";
|
||||
const startMarker = `<!-- AUTOGEN:${section.toUpperCase()} START -->`;
|
||||
const endMarker = `<!-- AUTOGEN:${section.toUpperCase()} END -->`;
|
||||
const wrapped = `${startMarker}\n${preamble}\n${newContent}\n${endMarker}`;
|
||||
|
||||
if (!(readme.includes(startMarker) && readme.includes(endMarker))) {
|
||||
throw new Error("Markers not found in README.md");
|
||||
}
|
||||
|
||||
const pre = readme.split(startMarker)[0];
|
||||
const end = readme.split(endMarker)[1];
|
||||
return pre + wrapped + end;
|
||||
}
|
||||
Reference in new issue
Block a user