@functionalcms/svelte-components 5.13.2 → 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
  };
@@ -1,9 +1,9 @@
1
1
  import { CommunicationService, DataService, TemplateService, WebsitesService, FilesService, UsersService, SetupService } from "@functionalcms/services";
2
2
  import type { Locals } from "./types.js";
3
- export declare const getDataService: (locals: Locals, endpoint: string) => DataService;
4
- export declare const getCommunicationService: (locals: Locals, endpoint: string) => CommunicationService;
5
- export declare const getWebsiteService: (locals: Locals, endpoint: string) => WebsitesService;
6
- export declare const getTemplateService: (locals: Locals, endpoint: string) => TemplateService;
7
- export declare const getFileService: (locals: Locals, endpoint: string) => FilesService;
3
+ export declare const getDataService: (locals: Locals) => DataService;
4
+ export declare const getCommunicationService: (locals: Locals) => CommunicationService;
5
+ export declare const getWebsiteService: (locals: Locals) => WebsitesService;
6
+ export declare const getTemplateService: (locals: Locals) => TemplateService;
7
+ export declare const getFileService: (locals: Locals) => FilesService;
8
8
  export declare const getUsersService: (locals: Locals) => UsersService;
9
- export declare const getSetupService: (locals: Locals, endpoint: string) => SetupService;
9
+ export declare const getSetupService: (locals: Locals) => SetupService;
@@ -1,29 +1,29 @@
1
1
  import { CommunicationService, DataService, TemplateService, WebsitesService, FilesService, UsersService, SetupService, } from "@functionalcms/services";
2
2
  import { ENDPOINT } from '$env/static/private';
3
3
  const getAccessToken = (locals) => locals.token;
4
- export const getDataService = (locals, endpoint) => {
4
+ export const getDataService = (locals) => {
5
5
  const accessToken = getAccessToken(locals);
6
- const service = new DataService(accessToken, endpoint);
6
+ const service = new DataService(accessToken, ENDPOINT);
7
7
  return service;
8
8
  };
9
- export const getCommunicationService = (locals, endpoint) => {
9
+ export const getCommunicationService = (locals) => {
10
10
  const accessToken = getAccessToken(locals);
11
- const service = new CommunicationService(accessToken, endpoint);
11
+ const service = new CommunicationService(accessToken, ENDPOINT);
12
12
  return service;
13
13
  };
14
- export const getWebsiteService = (locals, endpoint) => {
14
+ export const getWebsiteService = (locals) => {
15
15
  const accessToken = getAccessToken(locals);
16
- const service = new WebsitesService(accessToken, endpoint);
16
+ const service = new WebsitesService(accessToken, ENDPOINT);
17
17
  return service;
18
18
  };
19
- export const getTemplateService = (locals, endpoint) => {
19
+ export const getTemplateService = (locals) => {
20
20
  const accessToken = getAccessToken(locals);
21
- const service = new TemplateService(accessToken, endpoint);
21
+ const service = new TemplateService(accessToken, ENDPOINT);
22
22
  return service;
23
23
  };
24
- export const getFileService = (locals, endpoint) => {
24
+ export const getFileService = (locals) => {
25
25
  const accessToken = getAccessToken(locals);
26
- const service = new FilesService(accessToken, endpoint);
26
+ const service = new FilesService(accessToken, ENDPOINT);
27
27
  return service;
28
28
  };
29
29
  export const getUsersService = (locals) => {
@@ -31,8 +31,8 @@ export const getUsersService = (locals) => {
31
31
  const service = new UsersService(accessToken, ENDPOINT);
32
32
  return service;
33
33
  };
34
- export const getSetupService = (locals, endpoint) => {
34
+ export const getSetupService = (locals) => {
35
35
  const accessToken = getAccessToken(locals);
36
- const service = new SetupService(accessToken, endpoint);
36
+ const service = new SetupService(accessToken, ENDPOINT);
37
37
  return service;
38
38
  };
@@ -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.2",
3
+ "version": "5.14.0",
4
4
  "license": "MIT",
5
5
  "watch": {
6
6
  "build": {