-
Notifications
You must be signed in to change notification settings - Fork 86
Expand file tree
/
Copy pathllmstxt.ts
More file actions
147 lines (133 loc) · 4.02 KB
/
Copy pathllmstxt.ts
File metadata and controls
147 lines (133 loc) · 4.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import { populateTopicDocs, type DocEntry, type TopicProps } from "@typespec/astro-utils/llmstxt";
import { getCollection } from "astro:content";
import { getSampleStructure } from "src/utils/samples";
export type LlmsDocsDetails = {
docs: DocEntry[];
libraryNames: Set<string>;
};
export async function collectLlmsDocs() {
const libraryNames = new Set<string>();
const docs = await getCollection("docs", (entry) => {
if (!entry.data.llmstxt) return false;
const libraryName = getLibraryName(entry.id);
if (libraryName) {
libraryNames.add(libraryName);
}
return true;
});
const sampleDocs = await collectLlmsSampleDocs();
return {
docs: [...docs, ...sampleDocs],
libraryNames,
};
}
export type GenerateLlmsTopicsProps = {
libraryNames: Set<string>;
} & (
| {
docs: DocEntry[];
skipPopulateDocs?: boolean;
}
| {
docs?: never;
skipPopulateDocs: true;
}
);
export function generateLlmsTopics(
props: {
libraryNames: Set<string>;
} & {
docs: DocEntry[];
skipPopulateDocs?: boolean;
},
): TopicProps[];
export function generateLlmsTopics(
props: {
libraryNames: Set<string>;
} & {
docs?: never;
skipPopulateDocs: true;
},
): Omit<TopicProps, "docs">[];
export function generateLlmsTopics({
libraryNames,
docs,
skipPopulateDocs,
}: GenerateLlmsTopicsProps): TopicProps[] | Omit<TopicProps, "docs">[] {
const topics = [
{
title: "Getting Started - ARM",
id: "typespec-azure-resource-manager-getting-started",
description: "Overview of writing Azure Resource Manager (ARM) services in TypeSpec",
pathPrefix: "docs/getstarted/azure-resource-manager/",
},
{
title: "Getting Started - Azure Data Plane",
id: "typespec-azure-data-plane-getting-started",
description: "Overview of writing Azure Data Plane services in TypeSpec",
pathPrefix: "docs/getstarted/azure-core/",
},
{
title: "How Tos - ARM",
id: "typespec-azure-resource-manager-how-tos",
description: "Explanations of how to do common ARM-related tasks in TypeSpec",
pathPrefix: "docs/howtos/arm/",
},
{
title: "How Tos - Azure Data Plane",
id: "typespec-azure-data-plane-how-tos",
description: "Explanations of how to do common Azure Data Plane-related tasks in TypeSpec",
pathPrefix: "docs/howtos/azure-core/",
},
{
title: "How Tos - Generate Client Libraries",
id: "typespec-azure-clients-how-tos",
description: "Explanations of how to generate client libraries for Azure services",
pathPrefix: "docs/howtos/generate-client-libraries/",
},
{
title: "How Tos - Versioning",
id: "typespec-azure-versioning-how-tos",
description: "Explanations of how to version Azure services",
pathPrefix: "docs/howtos/versioning/",
},
{
title: "Samples",
id: "typespec-azure-samples",
description: "Sample TypeSpec Azure specifications.",
pathPrefix: "docs/samples/",
},
];
for (const libraryName of libraryNames) {
const typespecLibraryName = libraryName.startsWith("typespec")
? libraryName
: `typespec-${libraryName}`;
topics.push({
title: `@azure-tools/${typespecLibraryName}`,
id: `${typespecLibraryName}-library`,
description: `Documentation for the @azure-tools/${typespecLibraryName} library.`,
pathPrefix: `docs/libraries/${libraryName}/`,
});
}
if (skipPopulateDocs) {
return topics;
}
return populateTopicDocs(topics, docs);
}
function getLibraryName(id: string): string | undefined {
const match = id.match(/docs\/libraries\/([^/]+)\//);
return match ? match[1] : undefined;
}
async function collectLlmsSampleDocs(): Promise<DocEntry[]> {
const { samples } = await getSampleStructure();
return samples
.filter((sample) => sample.llmstxt)
.map((sample) => ({
id: `docs/samples/${sample.id}`,
data: {
title: sample.title,
description: sample.description,
llmstxt: true,
},
}));
}