@websline/cms-view-utils 1.0.5 → 1.0.6
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 +3 -3
- package/src/components/SiteHead.astro +112 -0
- package/src/index.js +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@websline/cms-view-utils",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"src",
|
|
@@ -19,14 +19,14 @@
|
|
|
19
19
|
"jsonwebtoken": "^9.0.3"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
|
-
"@eslint/compat": "^2.0
|
|
22
|
+
"@eslint/compat": "^2.1.0",
|
|
23
23
|
"@eslint/js": "^10.0.1",
|
|
24
24
|
"eslint": "^10.3.0",
|
|
25
25
|
"eslint-config-prettier": "^10.1.8",
|
|
26
26
|
"eslint-plugin-svelte": "^3.17.1",
|
|
27
27
|
"globals": "^17.6.0",
|
|
28
28
|
"prettier": "^3.8.3",
|
|
29
|
-
"prettier-plugin-svelte": "^3.5.
|
|
29
|
+
"prettier-plugin-svelte": "^3.5.2",
|
|
30
30
|
"prettier-plugin-tailwindcss": "^0.8.0",
|
|
31
31
|
"tsup": "^8.5.1"
|
|
32
32
|
},
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* SEO Meta Tags component
|
|
4
|
+
*
|
|
5
|
+
* Reads meta data from Astro.locals.seo and renders the corresponding
|
|
6
|
+
* HTML tags in the <head>.
|
|
7
|
+
*
|
|
8
|
+
* Overrides via props:
|
|
9
|
+
* - title: replaces the title completely
|
|
10
|
+
* - titleTransform: function that transforms the title (e.g. append suffix)
|
|
11
|
+
* - description: replaces the description completely
|
|
12
|
+
* - canonical: replaces the canonical URL completely
|
|
13
|
+
* - image: replaces the image completely (null = explicitly no image)
|
|
14
|
+
* - noIndex: overrides noIndex
|
|
15
|
+
* - noFollow: overrides noFollow
|
|
16
|
+
*
|
|
17
|
+
* Title logic (in this order):
|
|
18
|
+
* 1. If title prop is set → use it
|
|
19
|
+
* 2. Otherwise: use seo.title from Astro.locals
|
|
20
|
+
* 3. If titleTransform is set → apply it to the result
|
|
21
|
+
*
|
|
22
|
+
* Examples:
|
|
23
|
+
* <SeoTags /> → seo.title
|
|
24
|
+
* <SeoTags title="Custom Title" /> → "Custom Title"
|
|
25
|
+
* <SeoTags titleTransform={(t) => `${t} | My Hotel`} /> → "{seo.title} | My Hotel"
|
|
26
|
+
* <SeoTags title="Custom" titleTransform={(t) => `${t} | My Hotel`} />
|
|
27
|
+
* → "Custom | My Hotel"
|
|
28
|
+
*
|
|
29
|
+
* Important: In preview mode, robots is always forced to noindex, nofollow
|
|
30
|
+
* regardless of the page's robots settings. This prevents unpublished drafts
|
|
31
|
+
* from being indexed by search engines.
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
const isPreview = Astro.locals._preview ?? false;
|
|
35
|
+
|
|
36
|
+
const {
|
|
37
|
+
title: titleOverride,
|
|
38
|
+
titleTransform,
|
|
39
|
+
type: typeOverride,
|
|
40
|
+
description: descriptionOverride,
|
|
41
|
+
canonical: canonicalOverride,
|
|
42
|
+
image: imageOverride,
|
|
43
|
+
noIndex: noIndexOverride,
|
|
44
|
+
noFollow: noFollowOverride,
|
|
45
|
+
} = Astro.props;
|
|
46
|
+
|
|
47
|
+
const {
|
|
48
|
+
meta: {
|
|
49
|
+
canonical: seoCanonical,
|
|
50
|
+
description: seoDescription,
|
|
51
|
+
image: seoImage,
|
|
52
|
+
noIndex: seoNoIndex,
|
|
53
|
+
noFollow: seoNoFollow,
|
|
54
|
+
title: seoTitle,
|
|
55
|
+
} = {},
|
|
56
|
+
} = Astro.locals.seo || {};
|
|
57
|
+
|
|
58
|
+
// Title: override takes precedence over SEO value, then optionally apply transform
|
|
59
|
+
const baseTitle = titleOverride ?? seoTitle;
|
|
60
|
+
const finalTitle =
|
|
61
|
+
titleTransform && baseTitle ? titleTransform(baseTitle) : baseTitle;
|
|
62
|
+
|
|
63
|
+
// Other fields: override takes precedence over SEO value
|
|
64
|
+
const finalDescription = descriptionOverride ?? seoDescription;
|
|
65
|
+
const finalCanonical = canonicalOverride ?? seoCanonical;
|
|
66
|
+
|
|
67
|
+
// For image, use explicit undefined check so null can mean "explicitly no image"
|
|
68
|
+
const finalImage = imageOverride !== undefined ? imageOverride : seoImage;
|
|
69
|
+
|
|
70
|
+
// In preview mode, force noindex/nofollow regardless of page settings
|
|
71
|
+
// to prevent unpublished drafts from being indexed
|
|
72
|
+
const finalNoIndex = isPreview ? true : (noIndexOverride ?? seoNoIndex ?? false);
|
|
73
|
+
const finalNoFollow = isPreview ? true : (noFollowOverride ?? seoNoFollow ?? false);
|
|
74
|
+
|
|
75
|
+
// Build robots string only if at least one directive is active
|
|
76
|
+
const robotsDirectives = [];
|
|
77
|
+
if (finalNoIndex) robotsDirectives.push("noindex");
|
|
78
|
+
if (finalNoFollow) robotsDirectives.push("nofollow");
|
|
79
|
+
const robotsContent =
|
|
80
|
+
robotsDirectives.length > 0 ? robotsDirectives.join(", ") : null;
|
|
81
|
+
|
|
82
|
+
const finalType = typeOverride ?? "website";
|
|
83
|
+
|
|
84
|
+
// OG fallbacks (same as meta by default, can be extended via overrides later)
|
|
85
|
+
const ogTitle = finalTitle;
|
|
86
|
+
const ogDescription = finalDescription;
|
|
87
|
+
---
|
|
88
|
+
|
|
89
|
+
{finalTitle && <title>{finalTitle}</title>}
|
|
90
|
+
{finalDescription && <meta name="description" content={finalDescription} />}
|
|
91
|
+
{finalCanonical && <link rel="canonical" href={finalCanonical} />}
|
|
92
|
+
{robotsContent && <meta name="robots" content={robotsContent} />}
|
|
93
|
+
|
|
94
|
+
{/* Open Graph */}
|
|
95
|
+
{ogTitle && <meta property="og:title" content={ogTitle} />}
|
|
96
|
+
{ogDescription && <meta property="og:description" content={ogDescription} />}
|
|
97
|
+
<meta property="og:type" content={finalType} />
|
|
98
|
+
|
|
99
|
+
{
|
|
100
|
+
finalImage && (
|
|
101
|
+
<>
|
|
102
|
+
<meta property="og:image" content={finalImage.url} />
|
|
103
|
+
<meta property="og:image:width" content={String(finalImage.width)} />
|
|
104
|
+
<meta property="og:image:height" content={String(finalImage.height)} />
|
|
105
|
+
<meta property="og:image:type" content={finalImage.type} />
|
|
106
|
+
{finalImage.alt && <meta property="og:image:alt" content={finalImage.alt} />}
|
|
107
|
+
</>
|
|
108
|
+
)
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
{/* Twitter / X – only the card tag is needed, the rest falls back to OG */}
|
|
112
|
+
<meta name="twitter:card" content="summary_large_image" />
|
package/src/index.js
CHANGED
|
@@ -5,3 +5,4 @@ export { default as BlockWrapper } from "./components/BlockWrapper.svelte";
|
|
|
5
5
|
export { default as EditableBlock } from "./components/EditableBlock.svelte";
|
|
6
6
|
export { default as PageContent } from "./components/PageContent.svelte";
|
|
7
7
|
export { default as Picture } from "./components/Picture.svelte";
|
|
8
|
+
export { default as SiteHead } from "./components/SiteHead.astro";
|