@sprig-and-prose/tutorial-svelte 0.1.0 → 0.1.1

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": "@sprig-and-prose/tutorial-svelte",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "type": "module",
5
5
  "description": "A calm SvelteKit package that transforms markdown files into paged tutorial routes",
6
6
  "main": "src/index.js",
@@ -9,6 +9,7 @@
9
9
  ".": "./src/index.js",
10
10
  "./kit": {
11
11
  "types": "./src/kit/index.d.ts",
12
+ "import": "./src/kit/index.js",
12
13
  "default": "./src/kit/index.js"
13
14
  },
14
15
  "./kit/Tutorial.svelte": "./src/kit/Tutorial.svelte"
@@ -15,7 +15,32 @@ export function createTutorialEntries({ routeBase, modules, enableDirectoryIndex
15
15
 
16
16
  return async () => {
17
17
  const entries = generateEntries(modules, routeBase, enableDirectoryIndex);
18
- return entries;
18
+ // Ensure we always return an array, even if empty
19
+ if (!Array.isArray(entries)) {
20
+ console.warn('[tutorial-svelte] generateEntries did not return an array:', entries);
21
+ return [];
22
+ }
23
+ // Ensure all entries have the correct structure
24
+ // For catch-all routes, SvelteKit expects { path: "..." } not { params: { path: "..." } }
25
+ const validEntries = entries.filter((entry) => {
26
+ if (!entry || typeof entry !== 'object') {
27
+ return false;
28
+ }
29
+ // CRITICAL: For catch-all routes, path must be directly on the entry object
30
+ if (!('path' in entry)) {
31
+ return false;
32
+ }
33
+ const path = entry.path;
34
+ if (typeof path !== 'string' || path.length === 0) {
35
+ return false;
36
+ }
37
+ // SvelteKit doesn't allow paths starting or ending with /
38
+ if (path.startsWith('/') || path.endsWith('/')) {
39
+ return false;
40
+ }
41
+ return true;
42
+ });
43
+ return validEntries;
19
44
  };
20
45
  }
21
46
 
package/src/lib/routes.js CHANGED
@@ -79,7 +79,7 @@ export function resolveRoute(pathArray, modules, routeBase) {
79
79
  * @param {Record<string, any>} modules - Modules from import.meta.glob()
80
80
  * @param {string} routeBase - Base route path
81
81
  * @param {boolean} enableDirectoryIndex - Whether to generate directory index entries
82
- * @returns {Array<{ path: string[] }>}
82
+ * @returns {Array<{ path: string }>}
83
83
  */
84
84
  export function generateEntries(modules, routeBase, enableDirectoryIndex) {
85
85
  const entries = [];
@@ -87,6 +87,11 @@ export function generateEntries(modules, routeBase, enableDirectoryIndex) {
87
87
 
88
88
  // Generate entries for all pages of all segments
89
89
  for (const item of discovered) {
90
+ // Skip items with empty routePath
91
+ if (!item.routePath || item.routePath.trim() === '') {
92
+ continue;
93
+ }
94
+
90
95
  // Get markdown content to count pages
91
96
  const module = modules[item.filePath];
92
97
  let content = '';
@@ -112,18 +117,25 @@ export function generateEntries(modules, routeBase, enableDirectoryIndex) {
112
117
  continue;
113
118
  }
114
119
 
115
- const segmentPathParts = item.routePath.split('/');
120
+ const segmentPathParts = item.routePath.split('/').filter(Boolean);
121
+
122
+ // Skip if routePath is empty (shouldn't happen, but be safe)
123
+ if (segmentPathParts.length === 0) {
124
+ continue;
125
+ }
116
126
 
117
127
  // Generate entry for each page
118
128
  for (let pageNum = 1; pageNum <= pages.length; pageNum++) {
129
+ const pathString = [...segmentPathParts, String(pageNum)].join('/');
119
130
  entries.push({
120
- path: [...segmentPathParts, String(pageNum)],
131
+ path: pathString,
121
132
  });
122
133
  }
123
134
 
124
135
  // Generate stub entry for segment root
136
+ const segmentPathString = segmentPathParts.join('/');
125
137
  entries.push({
126
- path: segmentPathParts,
138
+ path: segmentPathString,
127
139
  });
128
140
 
129
141
  // Generate directory index entries if enabled
@@ -135,18 +147,23 @@ export function generateEntries(modules, routeBase, enableDirectoryIndex) {
135
147
 
136
148
  // Check if we've already added this directory
137
149
  const exists = entries.some(
138
- (e) => e.path.length === dirPath.length && e.path.join('/') === dirPathStr
150
+ (e) => e.path === dirPathStr
139
151
  );
140
152
 
141
153
  if (!exists) {
142
154
  entries.push({
143
- path: dirPath,
155
+ path: dirPathStr,
144
156
  });
145
157
  }
146
158
  }
147
159
  }
148
160
  }
149
161
 
150
- return entries;
162
+ // Filter out any entries with empty or invalid paths
163
+ // SvelteKit requires catch-all routes to have at least one segment
164
+ return entries.filter((entry) => {
165
+ const path = entry.path;
166
+ return typeof path === 'string' && path.length > 0 && !path.startsWith('/') && !path.endsWith('/');
167
+ });
151
168
  }
152
169