@riebeckite/plugin-seo 0.0.5 → 0.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/README.md +1 -1
- package/dist/index.js +38 -21
- package/package.json +8 -3
package/README.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -82,29 +82,32 @@ function escapeXml(value) {
|
|
|
82
82
|
|
|
83
83
|
// src/feeds.ts
|
|
84
84
|
function renderRssFeed(config, entries) {
|
|
85
|
+
const feed = getResolvedFeedMetadata(config);
|
|
85
86
|
const items = entries.map((entry) => {
|
|
86
87
|
const url = buildPostUrl(config, entry.permalink);
|
|
87
88
|
const pubDate = getEntryPublishedTime(entry);
|
|
88
89
|
return `<item><title>${escapeXml(entry.title)}</title><link>${escapeXml(url)}</link><guid>${escapeXml(url)}</guid><description>${escapeXml(getDescription(entry))}</description>${pubDate ? `<pubDate>${new Date(pubDate).toUTCString()}</pubDate>` : ""}</item>`;
|
|
89
90
|
});
|
|
90
|
-
return `<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"><channel><title>${escapeXml(
|
|
91
|
+
return `<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"><channel><title>${escapeXml(feed.title)}</title><link>${escapeXml(buildAbsoluteUrl(config, "/"))}</link><description>${escapeXml(feed.description)}</description><language>${escapeXml(feed.language)}</language>${items.join("")}</channel></rss>`;
|
|
91
92
|
}
|
|
92
93
|
function renderAtomFeed(config, entries) {
|
|
94
|
+
const feed = getResolvedFeedMetadata(config);
|
|
93
95
|
const updated = entries.map(getEntryUpdatedTime).find(Boolean) ?? (/* @__PURE__ */ new Date(0)).toISOString();
|
|
94
96
|
const items = entries.map((entry) => {
|
|
95
97
|
const url = buildPostUrl(config, entry.permalink);
|
|
96
98
|
return `<entry><title>${escapeXml(entry.title)}</title><link href="${escapeXml(url)}"/><id>${escapeXml(url)}</id><updated>${escapeXml(getEntryUpdatedTime(entry) ?? updated)}</updated><summary>${escapeXml(getDescription(entry))}</summary></entry>`;
|
|
97
99
|
});
|
|
98
|
-
return `<?xml version="1.0" encoding="UTF-8"?><feed xmlns="http://www.w3.org/2005/Atom"><title>${escapeXml(
|
|
100
|
+
return `<?xml version="1.0" encoding="UTF-8"?><feed xmlns="http://www.w3.org/2005/Atom"><title>${escapeXml(feed.title)}</title><link href="${escapeXml(buildAbsoluteUrl(config, "/"))}"/><link rel="self" href="${escapeXml(buildAbsoluteUrl(config, "/atom.xml"))}"/><id>${escapeXml(buildAbsoluteUrl(config, "/"))}</id><updated>${escapeXml(updated)}</updated>${items.join("")}</feed>`;
|
|
99
101
|
}
|
|
100
102
|
function renderJsonFeed(config, entries) {
|
|
103
|
+
const feed = getResolvedFeedMetadata(config);
|
|
101
104
|
return JSON.stringify({
|
|
102
105
|
version: "https://jsonfeed.org/version/1.1",
|
|
103
|
-
title:
|
|
106
|
+
title: feed.title,
|
|
104
107
|
home_page_url: buildAbsoluteUrl(config, "/"),
|
|
105
108
|
feed_url: buildAbsoluteUrl(config, "/feed.json"),
|
|
106
|
-
description:
|
|
107
|
-
language:
|
|
109
|
+
description: feed.description,
|
|
110
|
+
language: feed.language,
|
|
108
111
|
items: entries.map((entry) => {
|
|
109
112
|
const url = buildPostUrl(config, entry.permalink);
|
|
110
113
|
return removeUndefined({
|
|
@@ -120,6 +123,13 @@ function renderJsonFeed(config, entries) {
|
|
|
120
123
|
})
|
|
121
124
|
});
|
|
122
125
|
}
|
|
126
|
+
function getResolvedFeedMetadata(config) {
|
|
127
|
+
return {
|
|
128
|
+
title: config.site.feed.title ?? config.site.title,
|
|
129
|
+
description: config.site.feed.description ?? config.site.description,
|
|
130
|
+
language: config.site.feed.language ?? getHtmlLanguage(config)
|
|
131
|
+
};
|
|
132
|
+
}
|
|
123
133
|
|
|
124
134
|
// src/metadata.ts
|
|
125
135
|
import { calculateReadingTime } from "@riebeckite/core";
|
|
@@ -266,22 +276,27 @@ function renderRobots(config) {
|
|
|
266
276
|
|
|
267
277
|
// src/endpoints.ts
|
|
268
278
|
function createSeoEndpoints(options) {
|
|
269
|
-
|
|
270
|
-
|
|
279
|
+
const endpoints = [];
|
|
280
|
+
if (options.sitemap === true) {
|
|
281
|
+
endpoints.push({
|
|
271
282
|
path: "/sitemap.xml",
|
|
272
283
|
handler: ({ config, manifest }) => ({
|
|
273
284
|
headers: { "content-type": "application/xml; charset=utf-8" },
|
|
274
285
|
body: renderSitemap(config, manifest.entries)
|
|
275
286
|
})
|
|
276
|
-
}
|
|
277
|
-
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
if (options.robots === true) {
|
|
290
|
+
endpoints.push({
|
|
278
291
|
path: "/robots.txt",
|
|
279
292
|
handler: ({ config }) => ({
|
|
280
293
|
headers: { "content-type": "text/plain; charset=utf-8" },
|
|
281
294
|
body: renderRobots(config)
|
|
282
295
|
})
|
|
283
|
-
}
|
|
284
|
-
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
if (options.feed?.rss === true) {
|
|
299
|
+
endpoints.push({
|
|
285
300
|
path: "/feed.xml",
|
|
286
301
|
handler: ({ config, manifest }) => ({
|
|
287
302
|
headers: { "content-type": "application/rss+xml; charset=utf-8" },
|
|
@@ -290,8 +305,10 @@ function createSeoEndpoints(options) {
|
|
|
290
305
|
filterFeedEntries(config, manifest.entries)
|
|
291
306
|
)
|
|
292
307
|
})
|
|
293
|
-
}
|
|
294
|
-
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
if (options.feed?.atom === true) {
|
|
311
|
+
endpoints.push({
|
|
295
312
|
path: "/atom.xml",
|
|
296
313
|
handler: ({ config, manifest }) => ({
|
|
297
314
|
headers: { "content-type": "application/atom+xml; charset=utf-8" },
|
|
@@ -300,19 +317,19 @@ function createSeoEndpoints(options) {
|
|
|
300
317
|
filterFeedEntries(config, manifest.entries)
|
|
301
318
|
)
|
|
302
319
|
})
|
|
303
|
-
}
|
|
304
|
-
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
if (options.feed?.json === true) {
|
|
323
|
+
endpoints.push({
|
|
305
324
|
path: "/feed.json",
|
|
306
325
|
handler: ({ config, manifest }) => ({
|
|
307
326
|
json: JSON.parse(
|
|
308
|
-
renderJsonFeed(
|
|
309
|
-
config,
|
|
310
|
-
filterFeedEntries(config, manifest.entries)
|
|
311
|
-
)
|
|
327
|
+
renderJsonFeed(config, filterFeedEntries(config, manifest.entries))
|
|
312
328
|
)
|
|
313
329
|
})
|
|
314
|
-
}
|
|
315
|
-
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
return endpoints;
|
|
316
333
|
}
|
|
317
334
|
|
|
318
335
|
// src/plugin.ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@riebeckite/plugin-seo",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -14,7 +14,11 @@
|
|
|
14
14
|
}
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@riebeckite/core": "0.0.
|
|
17
|
+
"@riebeckite/core": "0.0.6"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"tsx": "^4.22.4",
|
|
21
|
+
"@riebeckite/test": "0.0.6"
|
|
18
22
|
},
|
|
19
23
|
"publishConfig": {
|
|
20
24
|
"access": "public"
|
|
@@ -46,6 +50,7 @@
|
|
|
46
50
|
},
|
|
47
51
|
"sideEffects": false,
|
|
48
52
|
"scripts": {
|
|
49
|
-
"build": "node ../../../scripts/build_package.mjs"
|
|
53
|
+
"build": "node ../../../scripts/build_package.mjs",
|
|
54
|
+
"test": "node --import tsx --test \"test/*.test.ts\""
|
|
50
55
|
}
|
|
51
56
|
}
|