@functionalcms/svelte-components 5.13.3 → 5.14.0

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.
@@ -1,2 +1,2 @@
1
1
  import type { Handle } from "@sveltejs/kit";
2
- export declare const hookSequence: (secret: string, paraglideMiddleware: any, getTextDirection: any, customHooks: Handle[]) => Handle;
2
+ export declare const hookSequence: (secret: string, paraglideMiddleware: any, getTextDirection: any, settings: any, customHooks: Handle[]) => Handle;
@@ -4,7 +4,7 @@ import { paraglideHandler } from "./handlers/paraglideHandler";
4
4
  import authorizationHandle from "./auth/authorizationHandle";
5
5
  import { userHandler } from "./handlers/userHandler";
6
6
  import { accessTokenHandler } from "./handlers/accessTokenHandler";
7
- import handleHealthCheck from "./handlers/handleHealthCheck";
8
- export const hookSequence = (secret, paraglideMiddleware, getTextDirection, customHooks) => {
9
- return sequence(userHandler(secret), accessTokenHandler(secret), paraglideHandler(paraglideMiddleware, getTextDirection), authorizationHandle(), ...customHooks, errorHandler);
7
+ import { sitemapHandle } from "./handlers/sitemapHandler";
8
+ export const hookSequence = (secret, paraglideMiddleware, getTextDirection, settings, customHooks) => {
9
+ return sequence(userHandler(secret), accessTokenHandler(secret), paraglideHandler(paraglideMiddleware, getTextDirection), authorizationHandle(), sitemapHandle(settings), ...customHooks, errorHandler);
10
10
  };
@@ -0,0 +1,4 @@
1
+ export declare const sitemapHandle: (settings: any) => ({ event, resolve }: {
2
+ event: any;
3
+ resolve: any;
4
+ }) => Promise<any>;
@@ -0,0 +1,46 @@
1
+ async function getAllRoutes() {
2
+ const staticPages = Object.keys(import.meta.glob('/src/routes/**/+page.svelte')).map(path => path
3
+ .replace('/src/routes', '')
4
+ .replace('/+page.svelte', ''));
5
+ const posts = import.meta.glob('/src/posts/**/*.md');
6
+ const dynamicPosts = Object
7
+ .keys(posts)
8
+ .map(p => `/blog${p}`)
9
+ .map(path => path.replace('/src/posts', ''));
10
+ return [...staticPages, ...dynamicPosts];
11
+ }
12
+ function createSitemap(settings, pages) {
13
+ const urls = pages
14
+ .map(p => ({
15
+ loc: `${settings.siteUrl}${p}`,
16
+ lastmod: new Date().toISOString(),
17
+ changefreq: 'daily',
18
+ priority: 0.8
19
+ }));
20
+ return `<?xml version="1.0" encoding="UTF-8"?>
21
+ <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
22
+ ${urls
23
+ .map((u) => `<url>
24
+ <loc>${u.loc}</loc>
25
+ ${u.changefreq ? `<changefreq>${u.changefreq}</changefreq>` : ''}
26
+ ${u.priority ? `<priority>${u.priority}</priority>` : ''}
27
+ ${u.lastmod ? `<lastmod>${u.lastmod}</lastmod>` : ''}
28
+ </url>`)
29
+ .join('\n')}
30
+ </urlset>`;
31
+ }
32
+ export const sitemapHandle = (settings) => {
33
+ return async ({ event, resolve }) => {
34
+ if (event.url.pathname === '/sitemap.xml') {
35
+ const pages = await getAllRoutes(); // your dynamic data source
36
+ const xml = createSitemap(settings, pages);
37
+ return new Response(xml, {
38
+ headers: {
39
+ 'Content-Type': 'application/xml'
40
+ }
41
+ });
42
+ }
43
+ // Default behaviour for all other routes
44
+ return resolve(event);
45
+ };
46
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@functionalcms/svelte-components",
3
- "version": "5.13.3",
3
+ "version": "5.14.0",
4
4
  "license": "MIT",
5
5
  "watch": {
6
6
  "build": {