Skip to content

Commit

Permalink
docs(website): Better migration guide search behavior
Browse files Browse the repository at this point in the history
Also add a "real world" example of the custom tests on the writing tests
page by linking to my template-rmd repo.
  • Loading branch information
mlaursen committed Jan 18, 2022
1 parent edd9287 commit 9729269
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
12 changes: 7 additions & 5 deletions packages/dev-utils/src/indexer/generate.ts
Expand Up @@ -56,11 +56,7 @@ function getMarkdownForRoute(route: string): string | null {

function getTitleForRoute(route: string): string {
const [name, pkgName] = route.split("/").reverse();
const title = toTitle(name)
.replace("Cdn", "CDN")
.replace("V1", "v1")
.replace("Api", "API")
.replace("Sassdoc", "SassDoc");
const title = toTitle(name);

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

if (pkgName === "migration-guides") {
return `Migrate from ${title}`;
}

return title;
}

Expand Down Expand Up @@ -145,6 +145,8 @@ export async function generate(
let pageUrl = route;
if (route.startsWith("/guides")) {
pageUrl = "/guides/[id]";
} else if (route.startsWith("/migration-guides")) {
pageUrl = "/migration-guides/[id]";
} else if (route.startsWith("/blog/")) {
pageUrl = "/blog/[id]";
} else if (route.startsWith("/packages") && !route.endsWith("demos")) {
Expand Down
16 changes: 15 additions & 1 deletion packages/dev-utils/src/utils/titles.ts
Expand Up @@ -32,7 +32,21 @@ export function toTitle(s: string, joinWith = " ", capitals = false): string {

return s
.split(capitals ? /(?=[A-Z])/ : "-")
.map(upperFirst)
.map((part) => {
if (/^((v\d+)|(to))$/.test(part)) {
return part;
}

if (/^api$/i.test(part)) {
return "API";
}

if (/^cdn$/i.test(part)) {
return "CDN";
}

return upperFirst(part);
})
.join(joinWith);
}

Expand Down
8 changes: 8 additions & 0 deletions packages/documentation/src/guides/writing-tests.md
@@ -1,5 +1,13 @@
## Writing Tests

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

0 comments on commit 9729269

Please sign in to comment.