@websline/cms-view-utils 1.2.8 → 1.3.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@websline/cms-view-utils",
3
- "version": "1.2.8",
3
+ "version": "1.3.0",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "src",
@@ -21,11 +21,11 @@
21
21
  "devDependencies": {
22
22
  "@eslint/compat": "^2.1.0",
23
23
  "@eslint/js": "^10.0.1",
24
- "eslint": "^10.4.1",
24
+ "eslint": "^10.5.0",
25
25
  "eslint-config-prettier": "^10.1.8",
26
26
  "eslint-plugin-svelte": "^3.19.0",
27
27
  "globals": "^17.6.0",
28
- "prettier": "^3.8.3",
28
+ "prettier": "^3.8.4",
29
29
  "prettier-plugin-svelte": "^3.5.2",
30
30
  "prettier-plugin-tailwindcss": "^0.8.0",
31
31
  "tsup": "^8.5.1"
@@ -0,0 +1,20 @@
1
+ import { buildCmsLlmsTxtUrl } from "./urlResolver.js";
2
+ import { buildCmsHeaders } from "./headers.js";
3
+ import { HttpError } from "../shared/errors.js";
4
+
5
+ const fetchLlmsTxt = async (request) => {
6
+ const cmsUrl = buildCmsLlmsTxtUrl();
7
+
8
+ const response = await fetch(cmsUrl, {
9
+ method: "GET",
10
+ headers: buildCmsHeaders(request),
11
+ });
12
+
13
+ if (!response.ok) {
14
+ throw new HttpError(response.status, "CMS Error");
15
+ }
16
+
17
+ return response.text();
18
+ };
19
+
20
+ export { fetchLlmsTxt };
@@ -18,4 +18,13 @@ const buildCmsSitemapUrl = () => {
18
18
  return `${CMS_BASE_URL}/api/public/sitemap`;
19
19
  };
20
20
 
21
- export { buildCmsPageUrl, buildCmsSiteConfigUrl, buildCmsSitemapUrl };
21
+ const buildCmsLlmsTxtUrl = () => {
22
+ return `${CMS_BASE_URL}/api/public/llms-txt`;
23
+ };
24
+
25
+ export {
26
+ buildCmsPageUrl,
27
+ buildCmsSiteConfigUrl,
28
+ buildCmsSitemapUrl,
29
+ buildCmsLlmsTxtUrl,
30
+ };
@@ -6,10 +6,16 @@
6
6
  decoding = "async",
7
7
  fetchpriority = "auto",
8
8
  image,
9
+ img = $bindable(),
9
10
  loading = "lazy",
11
+ pictureProps = {},
10
12
  sources = {},
13
+ ...rest
11
14
  } = $props();
12
15
 
16
+ const buildSrcset = (source) =>
17
+ source.url2x ? `${source.url} 1x, ${source.url2x} 2x` : source.url;
18
+
13
19
  const data = (() => {
14
20
  if (!image || !image.formats) {
15
21
  return {
@@ -58,7 +64,12 @@
58
64
  const last = resolved[resolved.length - 1];
59
65
 
60
66
  fallbackFormat = last.format;
61
- fallbackSrc = fallbackFormat.sources[0]?.url ?? "";
67
+
68
+ // Use the last source (original format, e.g. jpg/png) for the <img>
69
+ // fallback instead of sources[0] (avif), for maximum compatibility.
70
+ const fmtSources = fallbackFormat.sources;
71
+ fallbackSrc =
72
+ fmtSources[fmtSources.length - 1]?.url ?? fmtSources[0]?.url ?? "";
62
73
  }
63
74
 
64
75
  const alt = image.alt ?? image.title ?? "";
@@ -68,17 +79,19 @@
68
79
  </script>
69
80
 
70
81
  {#if data.resolved.length}
71
- <picture>
82
+ <picture {...pictureProps}>
72
83
  {#each data.resolved as r (r.format.identifier + "-" + r.min)}
73
84
  {#each r.format.sources as source (source.type + source.url)}
74
85
  <source
75
- srcset={source.url}
86
+ srcset={buildSrcset(source)}
76
87
  type={source.type}
77
88
  media={r.min > 0 ? `(min-width: ${r.min}px)` : undefined} />
78
89
  {/each}
79
90
  {/each}
80
91
 
81
92
  <img
93
+ bind:this={img}
94
+ {...rest}
82
95
  alt={data.alt}
83
96
  class={tw("h-full w-full object-cover", className)}
84
97
  {decoding}
@@ -0,0 +1,27 @@
1
+ import { fetchLlmsTxt } from "../cms/fetchLlmsTxt.js";
2
+ import { HttpError } from "../shared/errors.js";
3
+
4
+ const createLlmsTxtHandler =
5
+ () =>
6
+ async ({ request }) => {
7
+ try {
8
+ const body = await fetchLlmsTxt(request);
9
+
10
+ return new Response(body, {
11
+ status: 200,
12
+ headers: {
13
+ "Content-Type": "text/plain; charset=utf-8",
14
+ "Cache-Control": "no-store",
15
+ },
16
+ });
17
+ } catch (error) {
18
+ if (error instanceof HttpError) {
19
+ return new Response(`llms.txt error: ${error.message}`, {
20
+ status: error.status,
21
+ });
22
+ }
23
+ throw error;
24
+ }
25
+ };
26
+
27
+ export { createLlmsTxtHandler };
package/src/server.js CHANGED
@@ -6,4 +6,5 @@ export { withCmsFetch } from "./middleware/withCmsFetch.js";
6
6
  export { withParaglide } from "./middleware/withParaglide.js";
7
7
  export { createSitemapHandler } from "./handlers/sitemapHandler.js";
8
8
  export { createRobotsHandler } from "./handlers/robotsHandler.js";
9
+ export { createLlmsTxtHandler } from "./handlers/llmsTxtHandler.js";
9
10
  export { createCmsProxyHandler } from "./cms/proxyToCms.js";