@nekm/svelte-core 1.8.0 → 1.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/dist/seo.svelte CHANGED
@@ -1,5 +1,11 @@
1
1
  <script lang="ts">
2
- import {type QueryParams, queryParamsCreate, strTrimEnd, strTrimStart} from "@nekm/core";
2
+ import { page } from "$app/state";
3
+ import {
4
+ type QueryParams,
5
+ queryParamsCreate,
6
+ strTrimStart,
7
+ urlSetOrigin,
8
+ } from "@nekm/core";
3
9
 
4
10
  export interface SeoCanonical {
5
11
  readonly path?: string;
@@ -13,46 +19,48 @@
13
19
  readonly mimeContentType: string;
14
20
  }
15
21
 
22
+ export interface SeoTwitter {
23
+ readonly creator?: string;
24
+ readonly site?: string;
25
+ }
26
+
16
27
  export interface SeoProps {
17
28
  readonly siteTitle: string;
18
29
  readonly pageTitle: string;
19
30
  readonly description: string;
20
- readonly origin: string;
31
+ readonly origin?: string;
21
32
  readonly icon: SeoIcon;
22
33
  readonly canonical?: SeoCanonical;
23
34
  readonly next?: SeoCanonical;
35
+ readonly twitter?: SeoTwitter;
24
36
  }
25
37
 
26
- const { siteTitle, description, pageTitle, icon, canonical, next, origin }: SeoProps = $props();
38
+ const {
39
+ siteTitle,
40
+ pageTitle,
41
+ description,
42
+ icon,
43
+ canonical,
44
+ next,
45
+ origin: propsOrigin,
46
+ twitter,
47
+ }: SeoProps = $props();
27
48
 
28
- function createCanonical(canonical?: SeoCanonical, includeBaseUrl = false): string | undefined {
29
- let url;
49
+ function createCanonical(canonical: SeoCanonical): string | undefined {
50
+ if (!canonical.path) return origin;
30
51
 
31
- if (canonical || includeBaseUrl) {
32
- url = origin;
33
- }
52
+ const path = strTrimStart(canonical.path, "/");
53
+ const canonicalWithPath = `${origin}/${path}`;
34
54
 
35
- if (canonical?.path) {
36
- url += `/${canonical.path}`;
37
- }
55
+ if (!canonical.queryParams) return canonicalWithPath;
38
56
 
39
- if (canonical?.queryParams) {
40
- const queryParamsStr = queryParamsCreate(canonical.queryParams)
41
- url += `?${queryParamsStr}`;
42
- }
43
-
44
- return url;
57
+ return `${canonicalWithPath}?${queryParamsCreate(canonical.queryParams)}`;
45
58
  }
46
59
 
47
- // Starts with http or https. I.e, is an absolute URL.
48
- const iconHref = $derived.by(() => {
49
- return !icon.href.match(/^https?:\/\//ig)
50
- ? `${strTrimEnd(origin, "/")}/${strTrimStart(icon.href, "/")}`
51
- : icon.href;
52
- });
53
-
54
- const canonicalUrl = $derived(createCanonical(canonical, true));
55
- const nextUrl = $derived(createCanonical(next));
60
+ const origin = $derived(propsOrigin ?? page.url.origin);
61
+ const iconHref = $derived(urlSetOrigin(origin, icon.href));
62
+ const canonicalUrl = $derived(!canonical ? origin : createCanonical(canonical));
63
+ const nextUrl = $derived(!next ? undefined : createCanonical(next));
56
64
  </script>
57
65
 
58
66
  <svelte:head>
@@ -76,9 +84,16 @@
76
84
  <meta property="og:url" content={canonicalUrl} />
77
85
  <meta property="og:type" content="website" />
78
86
 
79
- <meta name="twitter:card" content="summary_large_image">
87
+ <meta name="twitter:card" content="summary_large_image" />
80
88
  <meta name="twitter:title" content={pageTitle} />
81
89
  <meta name="twitter:description" content={description} />
82
90
  <meta name="twitter:image" content={iconHref} />
83
- <meta name="twitter:creator" content="@iamBraska" />
91
+
92
+ {#if twitter?.creator}
93
+ <meta name="twitter:creator" content="@{twitter.creator}" />
94
+ {/if}
95
+
96
+ {#if twitter?.site}
97
+ <meta name="twitter:site" content="@{twitter.site}" />
98
+ {/if}
84
99
  </svelte:head>
@@ -9,14 +9,19 @@ export interface SeoIcon {
9
9
  readonly width: number;
10
10
  readonly mimeContentType: string;
11
11
  }
12
+ export interface SeoTwitter {
13
+ readonly creator?: string;
14
+ readonly site?: string;
15
+ }
12
16
  export interface SeoProps {
13
17
  readonly siteTitle: string;
14
18
  readonly pageTitle: string;
15
19
  readonly description: string;
16
- readonly origin: string;
20
+ readonly origin?: string;
17
21
  readonly icon: SeoIcon;
18
22
  readonly canonical?: SeoCanonical;
19
23
  readonly next?: SeoCanonical;
24
+ readonly twitter?: SeoTwitter;
20
25
  }
21
26
  declare const Seo: import("svelte").Component<SeoProps, {}, "">;
22
27
  type Seo = ReturnType<typeof Seo>;
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@nekm/svelte-core",
3
3
  "description": "Code I find myself re-writing over-and-over, Svelte edition.",
4
4
  "license": "MIT",
5
- "version": "1.8.0",
5
+ "version": "1.9.0",
6
6
  "scripts": {
7
7
  "dev": "vite dev",
8
8
  "build": "vite build && npm run prepack",
@@ -34,16 +34,16 @@
34
34
  }
35
35
  },
36
36
  "devDependencies": {
37
- "@sveltejs/adapter-auto": "^7.0.0",
37
+ "@sveltejs/adapter-auto": "^7.0.1",
38
38
  "@sveltejs/package": "^2.5.7",
39
- "@sveltejs/vite-plugin-svelte": "^6.2.1",
40
- "@types/node": "^25.0.10",
41
- "mongodb": "^7.1.0",
42
- "publint": "^0.3.15",
43
- "svelte-check": "^4.3.4",
39
+ "@sveltejs/vite-plugin-svelte": "^6",
40
+ "@types/node": "^25.5.0",
41
+ "mongodb": "^7.1.1",
42
+ "publint": "^0.3.18",
43
+ "svelte-check": "^4.4.5",
44
44
  "svelte-kit-sessions": "^0.4.0",
45
- "typescript": "^5.9.3",
46
- "vite": "^7.2.7",
45
+ "typescript": "^5",
46
+ "vite": "^7",
47
47
  "vite-plugin-devtools-json": "^1.0.0"
48
48
  },
49
49
  "keywords": [