Skip to content

Commit be7b1c4

Browse files
committed
Add default root collection
1 parent 5204dd4 commit be7b1c4

2 files changed

Lines changed: 9 additions & 4 deletions

File tree

ingest/collection.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,15 @@ const collectionMatter = (indexMd: string, slug: string, defaults: Partial<Colle
2424
{ admins: isListOfStrings }
2525
);
2626

27+
const DefaultCollectionContent = `# Notes`;
28+
2729
export const parseCollection = async (pathParts: string[], defaults: CollectedDefaults): Promise<RawCollectionDef> => {
2830
const fullPath = pathParts.join("/");
29-
const indexMd = fs.readFileSync(getMdFile(pathParts, "collection")!, "utf-8");
31+
const mdFile = getMdFile(pathParts, "collection");
32+
if (!mdFile && pathParts.length !== 0) {
33+
throw new Error(`Collection ${fullPath} does not have an index.md(x) file`);
34+
}
35+
const indexMd = mdFile !== null ? fs.readFileSync(mdFile, "utf-8") : DefaultCollectionContent;
3036
const { frontmatter, content } = collectionMatter(indexMd, fullPath, defaultsFor(defaults, fullPath, "collection"));
3137
const mdxContent = parseMd(content);
3238

ingest/updatePaths.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -746,9 +746,8 @@ export const updatePaths = async (
746746
};
747747

748748
export const updateRoot = async (db: Database) => {
749-
const rootCollection =
750-
getMdFile([], "collection") ? await parseCollection([], []) : null;
751-
if (rootCollection?.frontmatter.public) {
749+
const rootCollection = await parseCollection([], []);
750+
if (rootCollection.frontmatter.public) {
752751
const buildId = (await db.get(
753752
`INSERT INTO builds (path) VALUES (?) RETURNING id`,
754753
[""])

0 commit comments

Comments
 (0)