Skip to content

Commit 4e0f64e

Browse files
committed
feat: update examples + tutorials schema
1 parent 4d49ac9 commit 4e0f64e

File tree

5 files changed

+120
-394
lines changed

5 files changed

+120
-394
lines changed

src/transform/docs.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export async function transform_blog(
9191
name: doc.data.frontmatter.author,
9292
url: doc.data.frontmatter.authorURL,
9393
},
94-
draft: doc.data.frontmatter.draft || false
94+
draft: doc.data.frontmatter.draft || false,
9595
};
9696
})
9797
.sort((a, b) => (a.date.numeric < b.date.numeric ? 1 : -1));
@@ -165,17 +165,18 @@ function process_example(
165165
seen_slugs: Map<string, number>
166166
): [Example[], ExampleMeta[]] {
167167
let full: Example[] = [];
168-
let list = content.map(({ content }) => {
168+
let list = content.map(({ content, name }) => {
169169
if (typeof content === "string")
170170
throw new Error("Example contents cannot contain further directories.");
171171

172172
const [files, meta] = extract_meta(content);
173-
const slug = make_slug(meta.title, seen_slugs);
173+
174+
const [, , _slug] = /^(\d+)-(.+)$/.exec(name);
175+
const slug = make_slug(_slug, seen_slugs);
174176

175177
const _example = {
176178
name: meta.title,
177-
slug,
178-
thumbnail: `examples/thumbnails/${slug}.jpg`,
179+
slug: slug,
179180
};
180181

181182
full.push({ ..._example, files: files.map(get_files) });
@@ -192,10 +193,9 @@ export async function transform_examples(
192193
// project: string,
193194
// dir: string
194195
): Promise<{ full: Example[]; list: ExampleCategory[] }> {
195-
const seen_slugs = new Map();
196-
197196
const full: Example[] = [];
198-
const list = examples.map(({ content }) => {
197+
const list = examples.map(({ content, name }) => {
198+
const seen_slugs = new Map();
199199
if (typeof content === "string")
200200
throw new Error("Example contents cannot contain further directories.");
201201

@@ -220,7 +220,7 @@ async function process_tutorial(
220220
): Promise<[Tutorial[], TutorialMeta[]]> {
221221
let full: Tutorial[] = [];
222222
let list = await Promise.all(
223-
content.map(async ({ content }) => {
223+
content.map(async ({ content, name }) => {
224224
// TODO: this is backwards, fix
225225
if (typeof content === "string")
226226
throw new Error("Example contents cannot contain further directories.");
@@ -244,11 +244,13 @@ async function process_tutorial(
244244
level: 3,
245245
});
246246

247+
const [, , _slug] = /^(\d+)-(.+)$/.exec(name);
248+
const slug = make_slug(_slug, seen_slugs);
249+
247250
const _example = {
248251
name: vfile.data.section_title,
249-
slug: make_slug(`${cat_title} ${vfile.data.section_slug}`, seen_slugs),
250-
section_slug: make_slug(cat_title, new Map()),
251-
article_slug: vfile.data.section_slug
252+
slug: slug,
253+
252254
};
253255

254256
full.push({

0 commit comments

Comments
 (0)