getfilepress 0.1.30 → 0.1.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "getfilepress",
3
- "version": "0.1.30",
3
+ "version": "0.1.32",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "FilePress — file-based Markdown blog engine. Link this package from a content-only site (config + posts), then run `filepress build`.",
@@ -1,4 +1,4 @@
1
- import { readdirSync, readFileSync } from 'node:fs';
1
+ import { existsSync, readdirSync, readFileSync } from 'node:fs';
2
2
  import { isAbsolute, join, resolve } from 'node:path';
3
3
  import type { PostMeta, PostSource, RenderedPost } from './types';
4
4
  import { assertUniqueSlugs, ContentError, normalizeTag, parsePost } from './parse';
@@ -27,6 +27,7 @@ export interface ContentApi {
27
27
  }
28
28
 
29
29
  export interface CreateContentOptions {
30
+ /** Absolute or cwd-relative path to `posts/`. Missing dir → no posts (ok). */
30
31
  contentDir: string;
31
32
  /** Override draft listing. Default: on in Vite DEV, or when FILEPRESS_SHOW_DRAFTS is 1/true. */
32
33
  listDrafts?: boolean;
@@ -47,6 +48,8 @@ export function resolveListDrafts(override?: boolean): boolean {
47
48
  /**
48
49
  * Build a content API bound to one content directory. This is the seam a site
49
50
  * wires up in a server-only module: `createContent({ contentDir: 'posts' })`.
51
+ * Absent `posts/` is fine — returns empty lists. Product sites do not need a
52
+ * dummy folder.
50
53
  *
51
54
  * Reads the filesystem, so it must only be imported from server code
52
55
  * (`+page.server.ts`, `+server.ts`, or a `*.server.ts` lib module). The pure
@@ -65,6 +68,11 @@ export function createContent(opts: CreateContentOptions): ContentApi {
65
68
  function loadPostSources(): PostSource[] {
66
69
  if (cache && import.meta.env.PROD) return cache;
67
70
 
71
+ if (!existsSync(dir)) {
72
+ cache = [];
73
+ return cache;
74
+ }
75
+
68
76
  let filenames: string[];
69
77
  try {
70
78
  filenames = readdirSync(dir).filter((f) => f.toLowerCase().endsWith('.md'));