storyloco 2.8.1 → 2.9.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": "storyloco",
3
- "version": "2.8.1",
3
+ "version": "2.9.0",
4
4
  "description": "A collection of slick Storyblok field plugins built with Svelte 5, TypeScript, and Tailwind CSS",
5
5
  "keywords": [
6
6
  "storyblok",
@@ -210,15 +210,18 @@ interface Link {
210
210
  linktype?: string;
211
211
  url?: string;
212
212
  cached_url?: string;
213
+ anchor?: string;
214
+ email?: string;
213
215
  story?: {
214
216
  url?: string;
215
217
  [key: string]: unknown;
216
218
  };
217
219
  }
218
220
  /**
219
- * Resolve a multilink to an href. Story links become root-relative, everything else passes
220
- * through. Prefers `story.url` over `cached_url`, which goes stale when a target moves —
221
- * so pair with `resolve_links: "url"`.
221
+ * Resolve a multilink to an href, or `undefined` when the field links nowhere (so an `<a>`
222
+ * renders without one). Story links become root-relative with their anchor (`#section`);
223
+ * email links become `mailto:`; URL and asset links pass through. Prefers `story.url` over
224
+ * `cached_url`, which goes stale when a target moves, so pair with `resolve_links: "url"`.
222
225
  */
223
226
  export declare function href(link?: Link): string | undefined;
224
227
  /**
@@ -157,16 +157,23 @@ export function is_component(story, component) {
157
157
  return story?.content.component === component;
158
158
  }
159
159
  /**
160
- * Resolve a multilink to an href. Story links become root-relative, everything else passes
161
- * through. Prefers `story.url` over `cached_url`, which goes stale when a target moves —
162
- * so pair with `resolve_links: "url"`.
160
+ * Resolve a multilink to an href, or `undefined` when the field links nowhere (so an `<a>`
161
+ * renders without one). Story links become root-relative with their anchor (`#section`);
162
+ * email links become `mailto:`; URL and asset links pass through. Prefers `story.url` over
163
+ * `cached_url`, which goes stale when a target moves, so pair with `resolve_links: "url"`.
163
164
  */
164
165
  export function href(link) {
165
166
  if (!link)
166
167
  return undefined;
167
- return link.linktype === "story"
168
- ? `/${link.story?.url || link.cached_url}`
169
- : link.url || link.cached_url;
168
+ if (link.linktype === "email") {
169
+ const email = link.email || link.url;
170
+ return email ? `mailto:${email.replace(/^mailto:/, "")}` : undefined;
171
+ }
172
+ if (link.linktype !== "story")
173
+ return link.url || link.cached_url || undefined;
174
+ const path = (link.story?.url || link.cached_url || "").replace(/^\/+/, "");
175
+ const anchor = link.anchor ? `#${link.anchor.replace(/^#/, "")}` : "";
176
+ return path ? `/${path}${anchor}` : anchor || undefined;
170
177
  }
171
178
  /**
172
179
  * Turn a Storyblok error into a SvelteKit one, for `.catch(handle_error)`.