mirror of
https://github.com/quartz-community/folder-page.git
synced 2026-07-22 02:50:24 +00:00
Respect the file.data.unlisted convention in both the folder discovery loop (virtual folder index generation in pageType.generate) and the folder listing itself (pagesFromAllFiles and pagesFromTrie in FolderContent). Unlisted pages no longer contribute folders or subfolders, and no longer appear as entries inside any folder page listing. The foldersWithIndex detection loop also skips unlisted pages so a user-authored unlisted index file does not bypass the filter. Exports pagesFromAllFiles so its filter logic can be tested directly. Adds 5 unit tests covering unlisted exclusion, explicit unlisted: false passthrough, subfolder grouping, and folder-index self-exclusion.
53 lines
2.2 KiB
TypeScript
53 lines
2.2 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { pagesFromAllFiles } from "../src/components/FolderContent";
|
|
|
|
describe("pagesFromAllFiles", () => {
|
|
it("returns direct children of the requested folder", () => {
|
|
const allFiles = [
|
|
{ slug: "notes/a", frontmatter: { title: "A" } },
|
|
{ slug: "notes/b", frontmatter: { title: "B" } },
|
|
{ slug: "other/c", frontmatter: { title: "C" } },
|
|
];
|
|
const result = pagesFromAllFiles(allFiles, "notes/index", true);
|
|
expect(result.map((r) => r.slug).sort()).toEqual(["notes/a", "notes/b"]);
|
|
});
|
|
|
|
it("excludes unlisted pages from folder listings", () => {
|
|
const allFiles = [
|
|
{ slug: "notes/public", frontmatter: { title: "Public" } },
|
|
{ slug: "notes/secret", frontmatter: { title: "Secret" }, unlisted: true },
|
|
{ slug: "notes/another", frontmatter: { title: "Another" } },
|
|
];
|
|
const result = pagesFromAllFiles(allFiles, "notes/index", true);
|
|
const slugs = result.map((r) => r.slug);
|
|
expect(slugs).toContain("notes/public");
|
|
expect(slugs).toContain("notes/another");
|
|
expect(slugs).not.toContain("notes/secret");
|
|
});
|
|
|
|
it("includes explicit unlisted: false pages", () => {
|
|
const allFiles = [{ slug: "notes/forced", frontmatter: { title: "Forced" }, unlisted: false }];
|
|
const result = pagesFromAllFiles(allFiles, "notes/index", true);
|
|
expect(result.map((r) => r.slug)).toEqual(["notes/forced"]);
|
|
});
|
|
|
|
it("groups subfolders when showSubfolders is true", () => {
|
|
const allFiles = [
|
|
{ slug: "notes/top", frontmatter: { title: "Top" } },
|
|
{ slug: "notes/sub/page", frontmatter: { title: "SubPage" } },
|
|
];
|
|
const result = pagesFromAllFiles(allFiles, "notes/index", true);
|
|
const slugs = result.map((r) => r.slug).sort();
|
|
expect(slugs).toContain("notes/top");
|
|
expect(slugs.some((s) => s?.startsWith("notes/sub"))).toBe(true);
|
|
});
|
|
|
|
it("does not include the folder index itself", () => {
|
|
const allFiles = [
|
|
{ slug: "notes/index", frontmatter: { title: "Index" } },
|
|
{ slug: "notes/page", frontmatter: { title: "Page" } },
|
|
];
|
|
const result = pagesFromAllFiles(allFiles, "notes/index", true);
|
|
expect(result.map((r) => r.slug)).toEqual(["notes/page"]);
|
|
});
|
|
});
|