Skip to content

Commit d45d733

Browse files
committed
fix: sitemap
1 parent a82292f commit d45d733

File tree

4 files changed

+59
-47
lines changed

4 files changed

+59
-47
lines changed

src/routes/api/posts/+server.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// src/routes/api/posts/+server.ts
22
import { json } from "@sveltejs/kit";
3-
import { fetchMarkdownPosts, fetchBuilders, fetchBlocksMarkdownPosts, fetchDashboardMarkdownPosts } from "../../utils";
3+
import { fetchMarkdownPosts, fetchBuilders, fetchBlocksMarkdownPosts, fetchDashboardPosts } from "../../utils";
44

55
export const GET = async () => {
6-
const [posts, blocks, builders, dashboard] = await Promise.all([fetchMarkdownPosts(), fetchBlocksMarkdownPosts(), fetchBuilders(), fetchDashboardMarkdownPosts()]);
6+
const [posts, blocks, builders, dashboard] = await Promise.all([fetchMarkdownPosts(), fetchBlocksMarkdownPosts(), fetchBuilders(), fetchDashboardPosts()]);
77

88
return json({
99
posts,

src/routes/sitemap.xml/+server.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export const GET: RequestHandler = async () => {
77
let docsSlugs;
88
try {
99
docsSlugs = await docs.getDocsSlugs();
10-
console.log('Generated docs slugs:', docsSlugs );
10+
// console.log('Generated docs slugs:', docsSlugs );
1111
} catch (err) {
1212
console.error('Could not load docs data for sitemap:', err);
1313
throw error(500, 'Could not load data for param values.');
@@ -20,9 +20,9 @@ export const GET: RequestHandler = async () => {
2020
'^/docs-examples.*',
2121
'^/docs/examples.*',
2222
'^/fonts.*',
23-
'^/admin-dashboard.*',
2423
'^/testdir.*',
2524
'^/layouts/component.*',
25+
'^/admin-dashboard/.*/\\[.*\\].*', // Exclude any dynamic routes in admin-dashboard
2626
],
2727
paramValues: {
2828
'/docs/pages/[slug]': docsSlugs['pages'] || [],
@@ -31,18 +31,13 @@ export const GET: RequestHandler = async () => {
3131
'/docs/typography/[slug]': docsSlugs['typography'] || [],
3232
'/docs/utilities/[slug]': docsSlugs['utilities'] || [],
3333
'/docs/extend/[slug]': docsSlugs['extend'] || [],
34-
// '/docs/examples/[slug]': docsSlugs['examples'] || [],
3534
'/docs/plugins/[slug]': docsSlugs['plugins'] || [],
3635
'/icons/[slug]': docsSlugs['icons'] || [],
3736
'/illustrations/[slug]': docsSlugs['illustrations'] || [],
38-
3937
'/blocks/application/[slug]': docsSlugs['blocks-application'] || [],
4038
'/blocks/marketing/[slug]': docsSlugs['blocks-marketing'] || [],
4139
'/blocks/publisher/[slug]': docsSlugs['blocks-publisher'] || [],
42-
// '/builder': docsSlugs['builders'] || [],
43-
// paramValues can be a 1D array of strings
44-
// '/docs/': fetchMarkdownPosts(), // e.g. ['hello-world', 'another-post']
45-
// '/blog/tag/[tag]': blogTags, // e.g. ['red', 'green', 'blue']
4640
},
41+
additionalPaths: docsSlugs['dashboard']?.map(route => `/${route}`) || [],
4742
});
4843
};

src/routes/sitemap.xml/docs.ts

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
// /src/routes/sitemap.xml/docs.ts
2-
import { fetchMarkdownPosts, fetchBuilders, fetchBlocksMarkdownPosts, fetchDashboardMarkdownPosts } from "../utils";
3-
4-
// console.log('fetchBlocksMarkdownPosts', fetchBlocksMarkdownPosts());
2+
import { fetchMarkdownPosts, fetchBuilders, fetchBlocksMarkdownPosts, fetchDashboardPosts } from "../utils";
53

64
export async function getDocsSlugs() {
75
// Fetch your markdown posts
86
const posts = await fetchMarkdownPosts();
97
const builders = await fetchBuilders();
108
const blocks = await fetchBlocksMarkdownPosts();
11-
const dashboard = await fetchDashboardMarkdownPosts();
9+
const dashboard = await fetchDashboardPosts();
1210

13-
// console.log('builders', builders);
14-
// console.log('blocks', blocks);
1511
console.log('dashboard', dashboard);
1612

1713
const slugsByCategory: Record<string, string[]> = {};
@@ -44,17 +40,13 @@ export async function getDocsSlugs() {
4440
}
4541

4642
if (Array.isArray(dashboard)) {
47-
slugsByCategory['dashboard'] = dashboard.map(item => item.path);
43+
slugsByCategory['dashboard'] = dashboard.map(item => {
44+
// item.path is the string path from the improved fetchDashboardPosts
45+
const path = typeof item === 'string' ? item : item.path;
46+
// Ensure path starts with admin-dashboard
47+
return path.startsWith('admin-dashboard') ? path : `admin-dashboard/${path}`;
48+
});
4849
}
4950

5051
return slugsByCategory;
5152
}
52-
53-
54-
// Individual category functions (if you prefer separate calls)
55-
export async function getDocsPagesSlugs() {
56-
const posts = await fetchMarkdownPosts();
57-
return posts.pages?.map(item =>
58-
item.path.startsWith('/') ? item.path.slice(1) : item.path
59-
) || [];
60-
}

src/routes/utils/index.ts

Lines changed: 46 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -149,25 +149,50 @@ export const fetchBlocksMarkdownPosts = async () => {
149149
return Object.fromEntries(entries);
150150
};
151151

152-
export const fetchDashboardMarkdownPosts = async () => {
153-
const globs = {
154-
dashboard: import.meta.glob("/src/routes/admin-dashboard/**/+page.svelte")
155-
};
156-
157-
const allPaths = Object.keys(globs.dashboard)
158-
.map((path) => ({
159-
path: extractRouteName(path)
160-
}))
161-
.filter((item, index, self) => self.findIndex((i) => i.path === item.path) === index);
162-
163-
return allPaths;
164-
165-
// const entries = await Promise.all(
166-
// Object.entries(globs).map(async ([key, files]) => {
167-
// const resolved = await resolveMarkdownFiles(files);
168-
// return [key, resolved] as const;
169-
// })
170-
// );
171-
172-
// return Object.fromEntries(entries);
152+
export const fetchDashboardPosts = async () => {
153+
// Get all +page.svelte files
154+
const pageGlobs = import.meta.glob("/src/routes/admin-dashboard/**/+page.svelte");
155+
156+
// Get authentication .svelte files (these are not +page.svelte)
157+
const authGlobs = import.meta.glob("/src/routes/admin-dashboard/authentication/*.svelte");
158+
159+
// Extract routes from +page.svelte files
160+
const pageRoutes = Object.keys(pageGlobs)
161+
.map((path) => {
162+
let route = path
163+
.replace('/src/routes/admin-dashboard', '')
164+
.replace('/+page.svelte', '')
165+
.replace(/\/\([^)]+\)/g, '') // Remove route groups
166+
.replace(/^\//, '')
167+
.replace(/\/$/, '');
168+
169+
if (route === '') {
170+
route = 'admin-dashboard';
171+
} else {
172+
route = `admin-dashboard/${route}`;
173+
}
174+
return route;
175+
})
176+
.filter((route) => !route.includes('[') && !route.includes(']')); // Filter out dynamic routes
177+
178+
// Extract routes from authentication .svelte files
179+
const authRoutes = Object.keys(authGlobs)
180+
.map((path) => {
181+
const filename = path.split('/').pop()?.replace('.svelte', '') || '';
182+
return `admin-dashboard/authentication/${filename}`;
183+
});
184+
185+
// Add specific error routes that we know exist
186+
const errorRoutes = [
187+
'admin-dashboard/errors/400',
188+
'admin-dashboard/errors/404',
189+
'admin-dashboard/errors/500'
190+
];
191+
192+
// Combine all routes and remove duplicates
193+
const allRoutes = [...pageRoutes, ...authRoutes, ...errorRoutes]
194+
.filter((route, index, self) => self.indexOf(route) === index)
195+
.sort();
196+
197+
return allRoutes;
173198
};

0 commit comments

Comments
 (0)