Skip to content

Commit 9729269

Browse files
committed
docs(website): Better migration guide search behavior
Also add a "real world" example of the custom tests on the writing tests page by linking to my template-rmd repo.
1 parent edd9287 commit 9729269

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed

packages/dev-utils/src/indexer/generate.ts

+7-5
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,7 @@ function getMarkdownForRoute(route: string): string | null {
5656

5757
function getTitleForRoute(route: string): string {
5858
const [name, pkgName] = route.split("/").reverse();
59-
const title = toTitle(name)
60-
.replace("Cdn", "CDN")
61-
.replace("V1", "v1")
62-
.replace("Api", "API")
63-
.replace("Sassdoc", "SassDoc");
59+
const title = toTitle(name);
6460

6561
if (/Demos$/.test(title) && route.includes("form")) {
6662
return title;
@@ -73,6 +69,10 @@ function getTitleForRoute(route: string): string {
7369
return `${toTitle(pkgName, "")} ${title}`;
7470
}
7571

72+
if (pkgName === "migration-guides") {
73+
return `Migrate from ${title}`;
74+
}
75+
7676
return title;
7777
}
7878

@@ -145,6 +145,8 @@ export async function generate(
145145
let pageUrl = route;
146146
if (route.startsWith("/guides")) {
147147
pageUrl = "/guides/[id]";
148+
} else if (route.startsWith("/migration-guides")) {
149+
pageUrl = "/migration-guides/[id]";
148150
} else if (route.startsWith("/blog/")) {
149151
pageUrl = "/blog/[id]";
150152
} else if (route.startsWith("/packages") && !route.endsWith("demos")) {

packages/dev-utils/src/utils/titles.ts

+15-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,21 @@ export function toTitle(s: string, joinWith = " ", capitals = false): string {
3232

3333
return s
3434
.split(capitals ? /(?=[A-Z])/ : "-")
35-
.map(upperFirst)
35+
.map((part) => {
36+
if (/^((v\d+)|(to))$/.test(part)) {
37+
return part;
38+
}
39+
40+
if (/^api$/i.test(part)) {
41+
return "API";
42+
}
43+
44+
if (/^cdn$/i.test(part)) {
45+
return "CDN";
46+
}
47+
48+
return upperFirst(part);
49+
})
3650
.join(joinWith);
3751
}
3852

packages/documentation/src/guides/writing-tests.md

+8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
## Writing Tests
22

3+
> If you want to skip reading all the steps, you can check out my
4+
> [template-rmd](https://github.com/mlaursen/template-rmd) repo for a
5+
> "real-world" example. Check out the
6+
> [src/test-utils.tsx](https://github.com/mlaursen/template-rmd/blob/react-md%40v4.0.3/src/test-utils.tsx)
7+
> and
8+
> [src/components/\_\_tests\_\_/LinkUnstyled.tsx](https://github.com/mlaursen/template-rmd/blob/react-md%40v4.0.3/src/components/__tests__/LinkUnstyled.tsx)
9+
> for example usage.
10+
311
Testing an app with `react-md` components should not require many changes to
412
your normal testing flow. The only times weird issues might occur are when using
513
components that rely on one of the providers included by the [Configuration

0 commit comments

Comments
 (0)