Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Require Docusaurus-friendly section index pages #500

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions server/pages-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,8 @@ const sortByTitle = (a, b) => {
}
};

// categoryPagePathForDir looks for a category page at the same directory level
// as its associated directory OR within the associated directory. Throws an
// error if there is no category page for the directory.
// categoryPagePathForDir looks for a category page within the associated
// directory. Throws an error if there is no category page for the directory.
const categoryPagePathForDir = (fs, dirPath) => {
const { name } = parse(dirPath);

Expand All @@ -103,17 +102,19 @@ const categoryPagePathForDir = (fs, dirPath) => {

if (outerExists && innerExists) {
throw new Error(
`cannot generate the docs navigation sidebar due to an ambiguous category page: must have a page named ${outerCategoryPage} or ${innerCategoryPage}, not not both`
`cannot generate the docs navigation sidebar due to an ambiguous category page: remove ${outerCategoryPage} and keep ${innerCategoryPage}`
);
}
if (outerExists) {
return outerCategoryPage;
throw new Error(
`subdirectory in generated sidebar section ${dirPath} needs a page called ${innerCategoryPage}. Move ${outerCategoryPage}`
);
}
if (innerExists) {
return innerCategoryPage;
}
throw new Error(
`subdirectory in generated sidebar section ${dirPath} has no category page ${innerCategoryPage} or ${outerCategoryPage}`
`subdirectory in generated sidebar section ${dirPath} has no category page ${innerCategoryPage}`
);
};

Expand Down
79 changes: 23 additions & 56 deletions uvu-tests/config-docs.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Redirect } from "next/dist/lib/load-custom-routes";

Check failure on line 1 in uvu-tests/config-docs.test.ts

View workflow job for this annotation

GitHub Actions / Lint code base

Duplicate identifier 'Redirect'.
import { suite } from "uvu";
import * as assert from "uvu/assert";
import {
Expand All @@ -11,7 +11,7 @@
import { randomUUID } from "crypto";
import { join } from "path";
import { Volume, createFsFromVolume } from "memfs";
import type { Redirect } from "next/dist/lib/load-custom-routes";

Check failure on line 14 in uvu-tests/config-docs.test.ts

View workflow job for this annotation

GitHub Actions / Lint code base

Duplicate identifier 'Redirect'.

const Suite = suite("server/config-docs");

Expand Down Expand Up @@ -295,6 +295,29 @@
}
);

Suite(
"generateNavPaths throws if there is a category page at an incorrect location",
() => {
const files = {
"/docs/pages/database-access/guides/postgres.mdx": `---
title: Postgres Guide
---`,
"/docs/pages/database-access/guides/mysql.mdx": `---
title: MySQL Guide
---`,
"/docs/pages/database-access/guides.mdx": `---
title: "Database Access Guides"
---`,
};

const vol = Volume.fromJSON(files);
const fs = createFsFromVolume(vol);
assert.throws(() => {
generateNavPaths(fs, "/docs/pages/database-access");
}, "database-access/guides/guides.mdx");
}
);

Suite("generateNavPaths shows third-level pages on the sidebar", () => {
const files = {
"/docs/pages/database-access/guides/guides.mdx": `---
Expand Down Expand Up @@ -347,61 +370,6 @@
assert.equal(actual, expected);
});

Suite(
"allows category pages in the same directory as the associated subdirectory",
() => {
const files = {
"/docs/pages/database-access/guides.mdx": `---
title: Database Access Guides
---`,
"/docs/pages/database-access/guides/postgres.mdx": `---
title: Postgres Guide
---`,
"/docs/pages/database-access/guides/mysql.mdx": `---
title: MySQL Guide
---`,
"/docs/pages/database-access/guides/rbac.mdx": `---
title: Database Access RBAC
---`,
"/docs/pages/database-access/guides/rbac/get-started.mdx": `---
title: Get Started with DB RBAC
---`,
};

const expected = [
{
title: "Database Access Guides",
slug: "/database-access/guides/",
entries: [
{
title: "Database Access RBAC",
slug: "/database-access/guides/rbac/",
entries: [
{
title: "Get Started with DB RBAC",
slug: "/database-access/guides/rbac/get-started/",
},
],
},
{
title: "MySQL Guide",
slug: "/database-access/guides/mysql/",
},
{
title: "Postgres Guide",
slug: "/database-access/guides/postgres/",
},
],
},
];

const vol = Volume.fromJSON(files);
const fs = createFsFromVolume(vol);
let actual = generateNavPaths(fs, "/docs/pages/database-access");
assert.equal(actual, expected);
}
);

Suite("generates four levels of the sidebar", () => {
const files = {
"/docs/pages/database-access/guides/guides.mdx": `---
Expand Down Expand Up @@ -458,7 +426,6 @@
assert.throws(
() => {
const actual = generateNavPaths(fs, "/docs/pages/database-access");
console.log(actual);
},
"database-access/deployment/deployment.mdx",
"database-access/deployment.mdx"
Expand Down
2 changes: 1 addition & 1 deletion uvu-tests/remark-includes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ Suite("Throws an error if a variable is unresolved and has no default", () => {
assert.equal(out.messages.length, 1);
assert.equal(
out.messages[0].reason,
"The following partial parameters were not assigned and have no default value: {{ unsupported }}"
"install-version.mdx: the following partial parameters were not assigned and have no default value: {{ unsupported }}"
);
});

Expand Down
Loading