@turnipxenon/pineapple 4.2.3 → 4.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.
@@ -1,6 +1,8 @@
1
1
  <!--
2
- OverridableMeta is convenient Svelte component allowing each page to override the head meta values
2
+ @component OverridableMeta is convenient Svelte component allowing each page to override the head meta values
3
3
  based on their +page.ts.
4
+ @deprecated Pass in meta: PinyaHead in page.server.ts instead
5
+ ref: https://github.com/sveltejs/kit/issues/1540#issuecomment-2029016082
4
6
 
5
7
  For example:
6
8
  <code>
@@ -17,6 +19,7 @@ export const load = async (): Promise<OverridableMetaProps> => {
17
19
  -->
18
20
 
19
21
  <script lang="ts">
22
+ import { page } from "$app/state";
20
23
  import { pinyaHead } from "../../ui/templates/runes.svelte";
21
24
 
22
25
  interface Props {
@@ -32,7 +35,7 @@ export const load = async (): Promise<OverridableMetaProps> => {
32
35
  title = undefined,
33
36
  ogTitle = undefined,
34
37
  ogDescription = undefined,
35
- ogImage = undefined
38
+ ogImage = []
36
39
  }: Props = $props();
37
40
 
38
41
  if (rootUrl) {
@@ -48,6 +51,12 @@ export const load = async (): Promise<OverridableMetaProps> => {
48
51
  pinyaHead.ogDescription = ogDescription;
49
52
  }
50
53
  if (ogImage) {
51
- pinyaHead.ogImage = ogImage;
54
+ pinyaHead.ogImage = ogImage.map(img => {
55
+ if (img.startsWith('/')) {
56
+ return `${pinyaHead.rootUrl}${img}`
57
+ }
58
+
59
+ return img;
60
+ });
52
61
  }
53
62
  </script>
@@ -5,6 +5,25 @@ interface Props {
5
5
  ogDescription?: string;
6
6
  ogImage?: string[];
7
7
  }
8
+ /**
9
+ * OverridableMeta is convenient Svelte component allowing each page to override the head meta values
10
+ * based on their +page.ts.
11
+ * @deprecated Pass in meta: PinyaHead in page.server.ts instead
12
+ * ref: https://github.com/sveltejs/kit/issues/1540#issuecomment-2029016082
13
+ *
14
+ * For example:
15
+ * <code>
16
+ * // +page.ts
17
+ *
18
+ * import type { OverridableMetaProps } from "../..";
19
+ *
20
+ * export const load = async (): Promise<OverridableMetaProps> => {
21
+ * return {
22
+ * title: "CustomTitle",
23
+ * };
24
+ * };
25
+ * </code>
26
+ */
8
27
  declare const OverridableMeta: import("svelte").Component<Props, {}, "">;
9
28
  type OverridableMeta = ReturnType<typeof OverridableMeta>;
10
29
  export default OverridableMeta;
@@ -1,10 +1,8 @@
1
1
  <script lang="ts">
2
- import { OverridableMeta } from "../../overrideable_meta/index";
3
2
  import type { PageMeta } from "../../../ui/modules/NavigationMenu/PageMeta";
4
- import { getCmsBaseUrl } from "../../../util/env-getter";
3
+ import BlogTemplate from "../../../ui/templates/blog_template/BlogTemplate.svelte";
5
4
  import ParsnipBlockChildren from "../ParsnipBlockChildren.svelte";
6
5
  import type { ParsnipEntry } from "../ParsnipEntry";
7
- import BlogTemplate from "../../../ui/templates/blog_template/BlogTemplate.svelte";
8
6
 
9
7
  const { parsnipEntry }: { parsnipEntry: ParsnipEntry } = $props();
10
8
 
@@ -18,15 +16,6 @@
18
16
  });
19
17
  </script>
20
18
 
21
- <OverridableMeta
22
- title={parsnipEntry.basename}
23
- ogTitle={parsnipEntry.basename}
24
- ogDescription={parsnipEntry.tagline}
25
- ogImage={parsnipEntry.preview
26
- ? [`${getCmsBaseUrl()}/${parsnipEntry.preview}`]
27
- : []}
28
- />
29
-
30
19
  <BlogTemplate pageMeta={pageMeta}>
31
20
  <ParsnipBlockChildren blockChildren={parsnipEntry.ast.ast.children} />
32
21
  </BlogTemplate>
@@ -1,8 +1,10 @@
1
1
  import type { ParsnipEntry } from "../ParsnipEntry";
2
+ import type { PinyaHead } from "../../../ui/templates/runes.svelte";
2
3
  export declare const slugPageServerLoad: ({ params }: {
3
4
  params: {
4
5
  slug: string;
5
6
  };
6
7
  }) => Promise<{
7
8
  parsnipEntry: ParsnipEntry;
9
+ meta: PinyaHead;
8
10
  }>;
@@ -18,7 +18,15 @@ export const slugPageServerLoad = async ({ params }) => {
18
18
  if (!entryResponse.ok) {
19
19
  error(400, "Not found");
20
20
  }
21
+ const parsnipEntry = await entryResponse.json();
22
+ const meta = {
23
+ title: parsnipEntry.basename,
24
+ ogTitle: parsnipEntry.basename,
25
+ ogDescription: parsnipEntry.tagline,
26
+ ogImage: parsnipEntry.preview ? [`${baseUrl}/${parsnipEntry.preview}`] : undefined
27
+ };
21
28
  return {
22
- parsnipEntry: await entryResponse.json()
29
+ parsnipEntry,
30
+ meta
23
31
  };
24
32
  };
@@ -1,35 +1,36 @@
1
1
  <script lang="ts">
2
- import { pinyaHead } from "./runes.svelte";
3
- import { ModeWatcher } from "mode-watcher";
4
- import { Modals } from "svelte-modals";
5
2
  import { page } from "$app/state";
6
3
  import { locales, localizeHref } from "../../paraglide/runtime";
7
4
  import "../../styles/global.css";
8
-
9
- import "../../styles/app.css";
5
+ import WebThumbnailImage from "../../assets/placeholder/placeholder_circle.png";
6
+ import type { PinyaHead } from "./runes.svelte";
10
7
  import { ToastProvider } from "@skeletonlabs/skeleton-svelte";
8
+ import { ModeWatcher } from "mode-watcher";
9
+ import "../../styles/app.css";
10
+ import { Modals } from "svelte-modals";
11
11
 
12
12
  let { children } = $props();
13
13
 
14
- const ogUrl = $derived(`${pinyaHead.rootUrl}${page.url.pathname}`);
15
- </script>
14
+ // https://github.com/sveltejs/kit/issues/1540#issuecomment-2029016082
15
+ const meta: PinyaHead = ({
16
+ rootUrl: "http://localhost:5173",
17
+ title: "Welcome to my portfolio",
18
+ ogTitle: "Turnip time!",
19
+ ogDescription: "Welcome to Turnip's test portfolio",
20
+ ogImage: [WebThumbnailImage],
21
+ ...(page.data?.meta ?? []) // override
22
+ });
16
23
 
17
- <svelte:head>
18
- <meta charset="utf-8" />
19
- <title>{pinyaHead.title}</title>
20
- <meta property="og:url" content={ogUrl} />
21
- <meta property="og:site_name" content={pinyaHead.ogTitle} />
22
- <meta property="og:title" content={pinyaHead.ogTitle} />
23
- <meta property="twitter:title" content={pinyaHead.ogTitle} />
24
- <meta property="description" content={pinyaHead.ogDescription} />
25
- <meta property="og:description" content={pinyaHead.ogDescription} />
26
- <meta property="twitter:description" content={pinyaHead.ogDescription} />
27
- <meta property="twitter:card" content="summary">
28
- {#each pinyaHead.ogImage ?? [] as imgUrl, idx (`${idx}_${imgUrl}`)}
29
- <meta property="og:image" content={imgUrl} />
30
- <meta property="twitter:image" content={imgUrl} />
31
- {/each}
32
- </svelte:head>
24
+ const ogUrl = $derived(`${meta?.rootUrl}${page.url.pathname}`);
25
+
26
+ const imageList = $derived.by(() => meta?.ogImage?.map(img => {
27
+ if (img.startsWith("/")) {
28
+ return `${meta?.rootUrl}${img}`;
29
+ }
30
+
31
+ return img;
32
+ }) ?? []);
33
+ </script>
33
34
 
34
35
  <Modals>
35
36
  <!-- shown when any modal is opened -->
@@ -54,6 +55,23 @@
54
55
  {/each}
55
56
  </div>
56
57
 
58
+ <svelte:head>
59
+ <meta charset="utf-8" />
60
+ <title>{meta?.title ?? page.url.hostname}</title>
61
+ <meta property="og:url" content={ogUrl} />
62
+ <meta property="og:site_name" content={meta?.ogTitle ?? 'Home'} />
63
+ <meta property="og:title" content={meta?.ogTitle ?? 'Home'} />
64
+ <meta property="twitter:title" content={meta?.ogTitle ?? 'Home'} />
65
+ <meta property="description" content={meta?.ogDescription ?? ''} />
66
+ <meta property="og:description" content={meta?.ogDescription ?? ''} />
67
+ <meta property="twitter:description" content={meta?.ogDescription ?? ''} />
68
+ <meta property="twitter:card" content="summary">
69
+ {#each imageList as imgUrl, idx (`${idx}_${imgUrl}`)}
70
+ <meta property="og:image" content={imgUrl} />
71
+ <meta property="twitter:image" content={imgUrl} />
72
+ {/each}
73
+ </svelte:head>
74
+
57
75
  <style>
58
76
  .backdrop {
59
77
  position: fixed;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@turnipxenon/pineapple",
3
3
  "description": "personal package for base styling for other personal projects",
4
- "version": "4.2.3",
4
+ "version": "4.3.0",
5
5
  "scripts": {
6
6
  "dev": "vite dev",
7
7
  "build": "vite build && yarn package",