mirror of
https://github.com/quartz-community/folder-page.git
synced 2026-07-22 02:50:24 +00:00
refactor: use QuartzPluginData for PageEntry instead of duplicated shape
Replace the hand-written PageEntry type with an intersection of
QuartzPluginData and Record<string, unknown>. This keeps PageEntry
structurally aligned with the upstream contract so future DataMap
additions (e.g. the FullSlug branding that prompted this change) do
not require boundary casts on listProps.allFiles.
Construction sites that build a PageEntry from a plain string slug
now cast with 'as FullSlug' at the natural brand-boundary, matching
how slugs are produced elsewhere in the codebase.
The interface-extends form previously tried in PageList.tsx (removed
in commit e6a5d27 because it broke DTS builds) is not used here; the
intersection type alias inlines cleanly into the generated .d.ts.
This commit is contained in:
parent
0bee9810de
commit
d9fec1c6f7
3 changed files with 8 additions and 11 deletions
2
dist/components/index.js.map
vendored
2
dist/components/index.js.map
vendored
File diff suppressed because one or more lines are too long
2
dist/index.js.map
vendored
2
dist/index.js.map
vendored
File diff suppressed because one or more lines are too long
|
|
@ -1,7 +1,9 @@
|
|||
import type {
|
||||
FullSlug,
|
||||
QuartzComponent,
|
||||
QuartzComponentConstructor,
|
||||
QuartzComponentProps,
|
||||
QuartzPluginData,
|
||||
SortFn,
|
||||
} from "@quartz-community/types";
|
||||
import { PageList } from "./PageList";
|
||||
|
|
@ -31,12 +33,7 @@ interface TrieNode {
|
|||
findNode(path: string[]): TrieNode | undefined;
|
||||
}
|
||||
|
||||
type PageEntry = {
|
||||
slug?: string;
|
||||
unlisted?: boolean;
|
||||
dates?: { created: Date; modified: Date; published: Date };
|
||||
frontmatter?: { title?: string; tags?: string[] };
|
||||
};
|
||||
type PageEntry = QuartzPluginData & Record<string, unknown>;
|
||||
|
||||
function concatenateResources(
|
||||
...resources: (string | string[] | undefined)[]
|
||||
|
|
@ -56,7 +53,7 @@ function pagesFromTrie(folder: TrieNode, showSubfolders: boolean): PageEntry[] {
|
|||
|
||||
if (node.isFolder && showSubfolders) {
|
||||
return {
|
||||
slug: node.slug,
|
||||
slug: node.slug as FullSlug,
|
||||
dates: mostRecentDatesFromChildren(node.children),
|
||||
frontmatter: { title: node.displayName, tags: [] },
|
||||
};
|
||||
|
|
@ -106,7 +103,7 @@ export function pagesFromAllFiles(
|
|||
if (indexFile) continue;
|
||||
|
||||
directChildren.push({
|
||||
slug: `${folderPrefix}${subfolderName}/index`,
|
||||
slug: `${folderPrefix}${subfolderName}/index` as FullSlug,
|
||||
dates: mostRecentDatesFromEntries(files),
|
||||
frontmatter: { title: subfolderName, tags: [] },
|
||||
});
|
||||
|
|
@ -178,7 +175,7 @@ export default ((opts?: Partial<FolderContentOptions>) => {
|
|||
const listProps = {
|
||||
...props,
|
||||
sort: options.sort,
|
||||
allFiles: allPagesInFolder as unknown as QuartzComponentProps["allFiles"],
|
||||
allFiles: allPagesInFolder,
|
||||
};
|
||||
|
||||
const hastRoot = tree as Root;
|
||||
|
|
|
|||
Loading…
Reference in a new issue