Skip to content

Commit 5636abd

Browse files
authored
Merge pull request sveltejs#13 from sveltejs/tut-ex
Tut ex
2 parents a65fbf5 + fa56475 commit 5636abd

File tree

8 files changed

+200
-251
lines changed

8 files changed

+200
-251
lines changed

dist/action.js

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3089,10 +3089,11 @@ function make_session_slug_processor({
30893089

30903090
return function (url, seen_slugs) {
30913091
const slug = processor(url, { separator });
3092-
let count;
3093-
if ((count = seen_slugs.get(slug))) {
3094-
seen_slugs.set(slug, count + 1);
3095-
return `${slug}${separator}${count}`;
3092+
if ((seen_slugs.get(slug))) {
3093+
throw new Error(
3094+
`Found duplicate slug: "${slug}" when slugifying: "${url}".
3095+
Duplicate slugs are not allowed. You need to take yourself outside and have a word with yourself.`
3096+
);
30963097
} else {
30973098
seen_slugs.set(slug, 1);
30983099
return slug;
@@ -28688,7 +28689,7 @@ async function transform_blog(
2868828689
name: doc.data.frontmatter.author,
2868928690
url: doc.data.frontmatter.authorURL,
2869028691
},
28691-
draft: doc.data.frontmatter.draft || false
28692+
draft: doc.data.frontmatter.draft || false,
2869228693
};
2869328694
})
2869428695
.sort((a, b) => (a.date.numeric < b.date.numeric ? 1 : -1));
@@ -28762,17 +28763,18 @@ function process_example(
2876228763
seen_slugs
2876328764
) {
2876428765
let full = [];
28765-
let list = content.map(({ content }) => {
28766+
let list = content.map(({ content, name }) => {
2876628767
if (typeof content === "string")
2876728768
throw new Error("Example contents cannot contain further directories.");
2876828769

2876928770
const [files, meta] = extract_meta(content);
28770-
const slug = make_slug(meta.title, seen_slugs);
28771+
28772+
const [, , _slug] = /^(\d+)-(.+)$/.exec(name);
28773+
const slug = make_slug(_slug, seen_slugs);
2877128774

2877228775
const _example = {
2877328776
name: meta.title,
28774-
slug,
28775-
thumbnail: `examples/thumbnails/${slug}.jpg`,
28777+
slug: slug,
2877628778
};
2877728779

2877828780
full.push({ ..._example, files: files.map(get_files) });
@@ -28789,10 +28791,9 @@ async function transform_examples(
2878928791
// project: string,
2879028792
// dir: string
2879128793
) {
28792-
const seen_slugs = new Map();
28793-
2879428794
const full = [];
28795-
const list = examples.map(({ content }) => {
28795+
const list = examples.map(({ content, name }) => {
28796+
const seen_slugs = new Map();
2879628797
if (typeof content === "string")
2879728798
throw new Error("Example contents cannot contain further directories.");
2879828799

@@ -28817,7 +28818,7 @@ async function process_tutorial(
2881728818
) {
2881828819
let full = [];
2881928820
let list = await Promise.all(
28820-
content.map(async ({ content }) => {
28821+
content.map(async ({ content, name }) => {
2882128822
// TODO: this is backwards, fix
2882228823
if (typeof content === "string")
2882328824
throw new Error("Example contents cannot contain further directories.");
@@ -28833,17 +28834,21 @@ async function process_tutorial(
2883328834
});
2883428835

2883528836
const vfile = await format({
28836-
file: vfileMessage.name,
28837+
file: name,
2883728838
markdown: text,
2883828839
docs_type: "tutorials",
2883928840
project,
2884028841
dir: "tutorial",
2884128842
level: 3,
2884228843
});
2884328844

28845+
const [, , _slug] = /^(\d+)-(.+)$/.exec(name);
28846+
const slug = make_slug(_slug, seen_slugs);
28847+
2884428848
const _example = {
2884528849
name: vfile.data.section_title,
28846-
slug: make_slug(`${cat_title} ${vfile.data.section_slug}`, seen_slugs),
28850+
slug: slug,
28851+
2884728852
};
2884828853

2884928854
full.push({

dist/cli.js

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1852,10 +1852,11 @@ function make_session_slug_processor({
18521852

18531853
return function (url, seen_slugs) {
18541854
const slug = processor(url, { separator });
1855-
let count;
1856-
if ((count = seen_slugs.get(slug))) {
1857-
seen_slugs.set(slug, count + 1);
1858-
return `${slug}${separator}${count}`;
1855+
if ((seen_slugs.get(slug))) {
1856+
throw new Error(
1857+
`Found duplicate slug: "${slug}" when slugifying: "${url}".
1858+
Duplicate slugs are not allowed. You need to take yourself outside and have a word with yourself.`
1859+
);
18591860
} else {
18601861
seen_slugs.set(slug, 1);
18611862
return slug;
@@ -27451,7 +27452,7 @@ async function transform_blog(
2745127452
name: doc.data.frontmatter.author,
2745227453
url: doc.data.frontmatter.authorURL,
2745327454
},
27454-
draft: doc.data.frontmatter.draft || false
27455+
draft: doc.data.frontmatter.draft || false,
2745527456
};
2745627457
})
2745727458
.sort((a, b) => (a.date.numeric < b.date.numeric ? 1 : -1));
@@ -27525,17 +27526,18 @@ function process_example(
2752527526
seen_slugs
2752627527
) {
2752727528
let full = [];
27528-
let list = content.map(({ content }) => {
27529+
let list = content.map(({ content, name }) => {
2752927530
if (typeof content === "string")
2753027531
throw new Error("Example contents cannot contain further directories.");
2753127532

2753227533
const [files, meta] = extract_meta(content);
27533-
const slug = make_slug(meta.title, seen_slugs);
27534+
27535+
const [, , _slug] = /^(\d+)-(.+)$/.exec(name);
27536+
const slug = make_slug(_slug, seen_slugs);
2753427537

2753527538
const _example = {
2753627539
name: meta.title,
27537-
slug,
27538-
thumbnail: `examples/thumbnails/${slug}.jpg`,
27540+
slug: slug,
2753927541
};
2754027542

2754127543
full.push({ ..._example, files: files.map(get_files) });
@@ -27552,10 +27554,9 @@ async function transform_examples(
2755227554
// project: string,
2755327555
// dir: string
2755427556
) {
27555-
const seen_slugs = new Map();
27556-
2755727557
const full = [];
27558-
const list = examples.map(({ content }) => {
27558+
const list = examples.map(({ content, name }) => {
27559+
const seen_slugs = new Map();
2755927560
if (typeof content === "string")
2756027561
throw new Error("Example contents cannot contain further directories.");
2756127562

@@ -27580,7 +27581,7 @@ async function process_tutorial(
2758027581
) {
2758127582
let full = [];
2758227583
let list = await Promise.all(
27583-
content.map(async ({ content }) => {
27584+
content.map(async ({ content, name }) => {
2758427585
// TODO: this is backwards, fix
2758527586
if (typeof content === "string")
2758627587
throw new Error("Example contents cannot contain further directories.");
@@ -27596,17 +27597,21 @@ async function process_tutorial(
2759627597
});
2759727598

2759827599
const vfile = await format({
27599-
file: vfileMessage.name,
27600+
file: name,
2760027601
markdown: text,
2760127602
docs_type: "tutorials",
2760227603
project,
2760327604
dir: "tutorial",
2760427605
level: 3,
2760527606
});
2760627607

27608+
const [, , _slug] = /^(\d+)-(.+)$/.exec(name);
27609+
const slug = make_slug(_slug, seen_slugs);
27610+
2760727611
const _example = {
2760827612
name: vfile.data.section_title,
27609-
slug: make_slug(`${cat_title} ${vfile.data.section_slug}`, seen_slugs),
27613+
slug: slug,
27614+
2761027615
};
2761127616

2761227617
full.push({

src/format/slug.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,10 @@ export function make_session_slug_processor({
9797
const slug = processor(url, { separator });
9898
let count;
9999
if ((count = seen_slugs.get(slug))) {
100-
seen_slugs.set(slug, count + 1);
101-
return `${slug}${separator}${count}`;
100+
throw new Error(
101+
`Found duplicate slug: "${slug}" when slugifying: "${url}".
102+
Duplicate slugs are not allowed. You need to take yourself outside and have a word with yourself.`
103+
);
102104
} else {
103105
seen_slugs.set(slug, 1);
104106
return slug;

src/transform/docs.ts

Lines changed: 14 additions & 10 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,9 +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),
252+
slug: slug,
253+
250254
};
251255

252256
full.push({

0 commit comments

Comments
 (0)