@arraypress/seo 1.0.0 → 1.1.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 +15 -3
- package/src/index.d.ts +8 -0
- package/src/index.js +18 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arraypress/seo",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "HTML meta tag builder for SEO. Open Graph, Twitter Cards, canonical URLs, robots directives, hreflang, and site verification.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -11,11 +11,23 @@
|
|
|
11
11
|
"types": "./src/index.d.ts"
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
|
-
"files": [
|
|
14
|
+
"files": [
|
|
15
|
+
"src"
|
|
16
|
+
],
|
|
15
17
|
"scripts": {
|
|
16
18
|
"test": "node --test tests/seo.test.js"
|
|
17
19
|
},
|
|
18
|
-
"keywords": [
|
|
20
|
+
"keywords": [
|
|
21
|
+
"seo",
|
|
22
|
+
"meta",
|
|
23
|
+
"open-graph",
|
|
24
|
+
"twitter-card",
|
|
25
|
+
"canonical",
|
|
26
|
+
"robots",
|
|
27
|
+
"hreflang",
|
|
28
|
+
"json-ld",
|
|
29
|
+
"head"
|
|
30
|
+
],
|
|
19
31
|
"author": "David Sherlock",
|
|
20
32
|
"license": "MIT",
|
|
21
33
|
"repository": {
|
package/src/index.d.ts
CHANGED
|
@@ -9,6 +9,8 @@ export interface BuildHeadOptions {
|
|
|
9
9
|
twitterCard?: string;
|
|
10
10
|
twitterSite?: string;
|
|
11
11
|
twitterCreator?: string;
|
|
12
|
+
/** twitter:image:alt — only emitted when an `image` is set. */
|
|
13
|
+
twitterImageAlt?: string;
|
|
12
14
|
locale?: string;
|
|
13
15
|
articlePublished?: string;
|
|
14
16
|
articleModified?: string;
|
|
@@ -21,6 +23,12 @@ export interface BuildHeadOptions {
|
|
|
21
23
|
};
|
|
22
24
|
hreflang?: Array<{ lang: string; url: string }>;
|
|
23
25
|
jsonLd?: object | object[];
|
|
26
|
+
/** Extra `<meta>` tags — each object's keys become attributes
|
|
27
|
+
* (`true` → bare attribute, null/false/undefined → omitted). For
|
|
28
|
+
* anything the typed options don't cover (viewport, theme-color, …). */
|
|
29
|
+
meta?: Array<Record<string, string | number | boolean | undefined>>;
|
|
30
|
+
/** Extra `<link>` tags — same attribute rules as `meta`. */
|
|
31
|
+
link?: Array<Record<string, string | number | boolean | undefined>>;
|
|
24
32
|
}
|
|
25
33
|
|
|
26
34
|
/** Build a complete <head> HTML string from options. */
|
package/src/index.js
CHANGED
|
@@ -84,9 +84,10 @@ function esc(str) {
|
|
|
84
84
|
*/
|
|
85
85
|
export function buildHead(options = {}) {
|
|
86
86
|
const { title, description, image, url, type = 'website', robots, siteName,
|
|
87
|
-
twitterCard, twitterSite, twitterCreator,
|
|
87
|
+
twitterCard, twitterSite, twitterCreator, twitterImageAlt,
|
|
88
88
|
locale, articlePublished, articleModified, articleAuthor,
|
|
89
|
-
verification = {}, hreflang = [], jsonLd
|
|
89
|
+
verification = {}, hreflang = [], jsonLd,
|
|
90
|
+
meta = [], link = [] } = options;
|
|
90
91
|
|
|
91
92
|
const parts = [];
|
|
92
93
|
|
|
@@ -115,6 +116,7 @@ export function buildHead(options = {}) {
|
|
|
115
116
|
if (title) parts.push(`<meta name="twitter:title" content="${esc(title)}">`);
|
|
116
117
|
if (description) parts.push(`<meta name="twitter:description" content="${esc(description)}">`);
|
|
117
118
|
if (image) parts.push(`<meta name="twitter:image" content="${esc(image)}">`);
|
|
119
|
+
if (image && twitterImageAlt) parts.push(`<meta name="twitter:image:alt" content="${esc(twitterImageAlt)}">`);
|
|
118
120
|
if (twitterSite) parts.push(`<meta name="twitter:site" content="${esc(twitterSite)}">`);
|
|
119
121
|
if (twitterCreator) parts.push(`<meta name="twitter:creator" content="${esc(twitterCreator)}">`);
|
|
120
122
|
|
|
@@ -129,6 +131,20 @@ export function buildHead(options = {}) {
|
|
|
129
131
|
if (tag.lang && tag.url) parts.push(`<link rel="alternate" hreflang="${esc(tag.lang)}" href="${esc(tag.url)}">`);
|
|
130
132
|
}
|
|
131
133
|
|
|
134
|
+
// Extra pass-through <meta>/<link> tags — anything the typed options
|
|
135
|
+
// don't cover (viewport, theme-color, favicon, sitemap link, …). Each
|
|
136
|
+
// object's keys become attributes: `true` → bare attribute, and
|
|
137
|
+
// null/false/undefined → omitted.
|
|
138
|
+
const attrTag = (tag, attrs) => {
|
|
139
|
+
const a = Object.entries(attrs)
|
|
140
|
+
.filter(([, v]) => v != null && v !== false)
|
|
141
|
+
.map(([k, v]) => (v === true ? ` ${k}` : ` ${k}="${esc(String(v))}"`))
|
|
142
|
+
.join('');
|
|
143
|
+
return `<${tag}${a}>`;
|
|
144
|
+
};
|
|
145
|
+
for (const m of meta) parts.push(attrTag('meta', m));
|
|
146
|
+
for (const l of link) parts.push(attrTag('link', l));
|
|
147
|
+
|
|
132
148
|
// JSON-LD injection
|
|
133
149
|
const ldItems = Array.isArray(jsonLd) ? jsonLd : jsonLd ? [jsonLd] : [];
|
|
134
150
|
for (const ld of ldItems) {
|