@riebeckite/plugin-seo 0.0.1

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/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright Rerurate_514
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,110 @@
1
+ # @riebeckite/plugin-seo
2
+
3
+ SEO metadata, sitemap, robots.txt, and feed generation for Riebeckite.
4
+
5
+ [日本語](./README_ja.md)
6
+
7
+ ## Overview
8
+
9
+ `seo()` provides a `PluginSeoExtension` consumed by the Riebeckite app. It
10
+ builds per-page SEO metadata and renders `/sitemap.xml`, `/robots.txt`, and
11
+ RSS / Atom / JSON feeds.
12
+
13
+ ## Usage
14
+
15
+ ```ts
16
+ import { defineConfig } from "@riebeckite/core";
17
+ import { seo } from "@riebeckite/plugin-seo";
18
+
19
+ export default defineConfig({
20
+ // ...
21
+ plugins: [
22
+ seo({
23
+ siteName: "Riebeckite Blog",
24
+ defaultImage: "/ogp.png",
25
+ feed: { rss: true, atom: true, json: true },
26
+ sitemap: true,
27
+ robots: true,
28
+ }),
29
+ ],
30
+ });
31
+ ```
32
+
33
+ ## Options
34
+
35
+ | Option | Type | Description |
36
+ | ------ | ---- | ----------- |
37
+ | `siteName` | `string` | Site name used in page titles. Defaults to `site.title`. |
38
+ | `defaultImage` | `string` | Default OG image. Falls back to `site.defaultOgImage`. |
39
+ | `feed` | `{ rss?: boolean; atom?: boolean; json?: boolean }` | Feed output settings. |
40
+ | `sitemap` | `boolean` | Sitemap output settings. |
41
+ | `robots` | `boolean` | robots.txt output settings. |
42
+
43
+ ## Generated metadata
44
+
45
+ ### Articles (`buildArticleSeo`)
46
+
47
+ - `title`: `"{title} | {siteName}"`
48
+ - `description`: `frontmatter.description`, otherwise the first 160 characters
49
+ of the post text
50
+ - `canonicalUrl`: `frontmatter.canonical`, otherwise the entry's resolved canonical permalink
51
+ - `imageUrl`: `frontmatter.ogImage` / `frontmatter.image`, otherwise
52
+ `defaultImage` / `site.defaultOgImage`
53
+ - `noindex`: `frontmatter.noindex === true`
54
+ - `publishedTime`: `published` / `date` / `created`
55
+ - `modifiedTime`: `updated`, falling back to the publish time
56
+ - `tags`, `readingTimeMinutes`
57
+ - JSON-LD: `BlogPosting` and `BreadcrumbList`
58
+
59
+ ### Websites (`buildWebsiteSeo`)
60
+
61
+ Title, description, canonical URL, default image, and JSON-LD `WebSite` +
62
+ `BreadcrumbList` for index, tag, and other non-article pages.
63
+
64
+ ## Feeds, sitemap, and robots
65
+
66
+ | Function | Output |
67
+ | -------- | ------ |
68
+ | `renderSitemap` | `/sitemap.xml` — home page plus published, non-`noindex` entries |
69
+ | `renderRobots` | `/robots.txt` — allow all plus sitemap link |
70
+ | `renderRssFeed` | RSS 2.0 built from `config.site.feed` |
71
+ | `renderAtomFeed` | Atom feed |
72
+ | `renderJsonFeed` | JSON Feed 1.1 with `content_html` |
73
+
74
+ Feed and sitemap entries are filtered with `isPublished`, exclude
75
+ `noindex: true`, and are sorted by the most recent update first. Their URLs use
76
+ each entry's resolved canonical `permalink` (`ContentManifestEntry.permalink`);
77
+ they are never rebuilt from slugs.
78
+
79
+ ## Reading time
80
+
81
+ `calculateReadingTime` counts CJK characters (500/min) and Latin words
82
+ (220/min), rounding up to at least 1 minute.
83
+
84
+ ## Frontmatter fields
85
+
86
+ | Field | Use |
87
+ | ----- | --- |
88
+ | `title` | Article title (falls back to the last slug segment) |
89
+ | `description` | Meta description |
90
+ | `canonical` | Canonical URL |
91
+ | `image` / `ogImage` | OG image |
92
+ | `published` / `date` / `created` | Publish time |
93
+ | `updated` | Modified time |
94
+ | `tags` | Keywords / feed tags |
95
+ | `noindex` | `noindex` meta, feed and sitemap exclusion |
96
+
97
+ ## Exports
98
+
99
+ - `seo(options?)` — plugin factory
100
+ - Types: `SeoPluginOptions`, `FeedOptions`, `SeoMetadata`, `WebsiteSeoInput`,
101
+ `RenderableFeedEntry`
102
+ - Helpers: `buildArticleSeo`, `buildWebsiteSeo`, `buildAbsoluteUrl`,
103
+ `buildPostUrl`, `getDescription`, `filterFeedEntries`,
104
+ `getEntryPublishedTime`, `getEntryUpdatedTime`, `getHtmlLanguage`,
105
+ `calculateReadingTime`, `renderSitemap`, `renderRobots`, `renderRssFeed`,
106
+ `renderAtomFeed`, `renderJsonFeed`
107
+
108
+ ## See also
109
+
110
+ - [Plugin guide](../../docs/plugins_en.md)
package/README_ja.md ADDED
@@ -0,0 +1,68 @@
1
+ # @riebeckite/plugin-seo
2
+
3
+ 記事のメタデータ、サイトマップ、robots.txt、RSS・Atom・JSON Feed をまとめて生成するプラグインです。アプリケーションはプラグインが提供する SEO 拡張を受け取り、各ページの出力に利用します。
4
+
5
+ [English](./README.md)
6
+
7
+ ## 設定する
8
+
9
+ ```ts
10
+ import { defineConfig } from "@riebeckite/core";
11
+ import { seo } from "@riebeckite/plugin-seo";
12
+
13
+ export default defineConfig({
14
+ // ...
15
+ plugins: [
16
+ seo({
17
+ siteName: "Riebeckite Blog",
18
+ defaultImage: "/ogp.png",
19
+ feed: { rss: true, atom: true, json: true },
20
+ sitemap: true,
21
+ robots: true,
22
+ }),
23
+ ],
24
+ });
25
+ ```
26
+
27
+ | 項目 | 説明 |
28
+ | --- | --- |
29
+ | `siteName` | ページタイトルに使うサイト名。省略時は `site.title` |
30
+ | `defaultImage` | 既定の OGP 画像。省略時は `site.defaultOgImage` |
31
+ | `feed` | RSS、Atom、JSON Feed の出力を個別に有効化する |
32
+ | `sitemap` | サイトマップを出力する |
33
+ | `robots` | robots.txt を出力する |
34
+
35
+ ## 記事の frontmatter が出力を決める
36
+
37
+ `buildArticleSeo()` は記事タイトル、説明、canonical URL、OGP 画像、公開・更新日時、タグ、読了時間を組み立て、`BlogPosting` と `BreadcrumbList` の JSON-LD を作ります。値は次の順で補完されます。
38
+
39
+ | フィールド | 用途 |
40
+ | --- | --- |
41
+ | `title` | 記事タイトル。なければ slug の末尾 |
42
+ | `description` | meta description。なければ本文の先頭 160 文字 |
43
+ | `canonical` | 正規 URL。なければ解決済みの canonical permalink |
44
+ | `image` / `ogImage` | OGP 画像。なければ設定上の既定画像 |
45
+ | `published` / `date` / `created` | 公開日時 |
46
+ | `updated` | 更新日時。なければ公開日時 |
47
+ | `tags` | キーワードとフィードのタグ |
48
+ | `noindex` | 検索エンジン向けの noindex と、サイトマップ・フィードからの除外 |
49
+
50
+ 記事以外には `buildWebsiteSeo()` を使えます。トップやタグ一覧向けに `WebSite` と `BreadcrumbList` の構造化データを作ります。
51
+
52
+ ## 公開物に含まれる記事
53
+
54
+ サイトマップとフィードは、公開済みで `noindex: true` ではないエントリーだけを対象にし、更新日時の新しい順に並べます。URL には各エントリーの解決済み canonical `permalink`(`ContentManifestEntry.permalink`)を使い、slug から再構築しません。出力関数は `renderSitemap`、`renderRobots`、`renderRssFeed`、`renderAtomFeed`、`renderJsonFeed` です。
55
+
56
+ 読了時間は CJK 文字を毎分 500 文字、ラテン文字の単語を毎分 220 語として数え、最低 1 分に切り上げます。
57
+
58
+ ## 主なエクスポート
59
+
60
+ - `seo(options?)`: プラグインを作成する
61
+ - `buildArticleSeo`、`buildWebsiteSeo`: ページの SEO 情報を構築する
62
+ - `renderSitemap`、`renderRobots`、`renderRssFeed`、`renderAtomFeed`、`renderJsonFeed`: 公開用ファイルを描画する
63
+ - `calculateReadingTime`: 読了時間を計算する
64
+ - 型: `SeoPluginOptions`、`FeedOptions`、`SeoMetadata`、`WebsiteSeoInput`、`RenderableFeedEntry`
65
+
66
+ ## 関連資料
67
+
68
+ - [プラグインシステム](../../../docs/ja/plugin-system.md)
@@ -0,0 +1,8 @@
1
+ export type { SeoMetadata, WebsiteSeoInput } from "@riebeckite/core";
2
+ export { filterFeedEntries, getDescription, getEntryPublishedTime, getEntryUpdatedTime, getHtmlLanguage, } from "./src/content.js";
3
+ export { renderAtomFeed, renderJsonFeed, renderRssFeed } from "./src/feeds.js";
4
+ export { buildArticleSeo, buildWebsiteSeo } from "./src/metadata.js";
5
+ export { seo } from "./src/plugin.js";
6
+ export { renderRobots, renderSitemap } from "./src/site-files.js";
7
+ export type { FeedOptions, RenderableFeedEntry, SeoPluginOptions, } from "./src/types.js";
8
+ export { buildAbsoluteUrl, buildPostUrl } from "./src/url.js";
package/dist/index.js ADDED
@@ -0,0 +1,357 @@
1
+ // src/content.ts
2
+ import { isPublished, stripHtml } from "@riebeckite/core";
3
+ function getDescription(post) {
4
+ const frontmatterDescription = post.frontmatter.description;
5
+ if (typeof frontmatterDescription === "string" && frontmatterDescription.trim()) {
6
+ return frontmatterDescription.trim();
7
+ }
8
+ return stripHtml(post.html).replace(/\s+/g, " ").trim().slice(0, 160);
9
+ }
10
+ function filterFeedEntries(config, entries) {
11
+ return entries.filter((entry) => isPublished(config, entry.frontmatter)).filter((entry) => entry.frontmatter.noindex !== true).sort((a, b) => getSortableTime(b) - getSortableTime(a));
12
+ }
13
+ function getEntryPublishedTime(entry) {
14
+ return getIsoDate(
15
+ entry.frontmatter.published ?? entry.frontmatter.date ?? entry.frontmatter.created
16
+ ) ?? null;
17
+ }
18
+ function getEntryUpdatedTime(entry) {
19
+ return getIsoDate(entry.frontmatter.updated) ?? getEntryPublishedTime(entry);
20
+ }
21
+ function getHtmlLanguage(config) {
22
+ return config.site.locale.replace("_", "-");
23
+ }
24
+ function normalizeTags(tags) {
25
+ if (!Array.isArray(tags)) return [];
26
+ return tags.filter(
27
+ (tag) => typeof tag === "string" && tag.trim().length > 0
28
+ );
29
+ }
30
+ function getIsoDate(value) {
31
+ if (value instanceof Date && !Number.isNaN(value.getTime())) {
32
+ return value.toISOString();
33
+ }
34
+ if (typeof value !== "string" || !value.trim()) return void 0;
35
+ const date = new Date(value);
36
+ return Number.isNaN(date.getTime()) ? void 0 : date.toISOString();
37
+ }
38
+ function getSortableTime(entry) {
39
+ const value = entry.frontmatter.updated ?? entry.frontmatter.published ?? entry.frontmatter.date ?? entry.frontmatter.created;
40
+ if (value instanceof Date) return value.getTime();
41
+ if (typeof value !== "string") return 0;
42
+ const time = new Date(value).getTime();
43
+ return Number.isNaN(time) ? 0 : time;
44
+ }
45
+
46
+ // src/url.ts
47
+ function buildAbsoluteUrl(config, pathOrUrl) {
48
+ if (!pathOrUrl) return config.site.baseUrl;
49
+ if (/^https?:\/\//.test(pathOrUrl)) return pathOrUrl;
50
+ return new URL(
51
+ pathOrUrl,
52
+ config.site.baseUrl || "https://example.com"
53
+ ).toString();
54
+ }
55
+ function buildPostUrl(config, permalink) {
56
+ return buildAbsoluteUrl(config, permalink);
57
+ }
58
+
59
+ // src/schema.ts
60
+ function buildBreadcrumbSchema(config, items) {
61
+ return {
62
+ "@context": "https://schema.org",
63
+ "@type": "BreadcrumbList",
64
+ itemListElement: items.map((item, index) => ({
65
+ "@type": "ListItem",
66
+ position: index + 1,
67
+ name: item.name,
68
+ item: item.url || buildAbsoluteUrl(config, "/")
69
+ }))
70
+ };
71
+ }
72
+ function removeUndefined(value) {
73
+ return Object.fromEntries(
74
+ Object.entries(value).filter(([, entryValue]) => entryValue !== void 0)
75
+ );
76
+ }
77
+
78
+ // src/xml.ts
79
+ function escapeXml(value) {
80
+ return value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
81
+ }
82
+
83
+ // src/feeds.ts
84
+ function renderRssFeed(config, entries) {
85
+ const items = entries.map((entry) => {
86
+ const url = buildPostUrl(config, entry.permalink);
87
+ const pubDate = getEntryPublishedTime(entry);
88
+ 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
+ return `<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"><channel><title>${escapeXml(config.site.feed.title)}</title><link>${escapeXml(buildAbsoluteUrl(config, "/"))}</link><description>${escapeXml(config.site.feed.description)}</description><language>${escapeXml(config.site.feed.language)}</language>${items.join("")}</channel></rss>`;
91
+ }
92
+ function renderAtomFeed(config, entries) {
93
+ const updated = entries.map(getEntryUpdatedTime).find(Boolean) ?? (/* @__PURE__ */ new Date(0)).toISOString();
94
+ const items = entries.map((entry) => {
95
+ const url = buildPostUrl(config, entry.permalink);
96
+ 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
+ });
98
+ return `<?xml version="1.0" encoding="UTF-8"?><feed xmlns="http://www.w3.org/2005/Atom"><title>${escapeXml(config.site.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
+ }
100
+ function renderJsonFeed(config, entries) {
101
+ return JSON.stringify({
102
+ version: "https://jsonfeed.org/version/1.1",
103
+ title: config.site.feed.title,
104
+ home_page_url: buildAbsoluteUrl(config, "/"),
105
+ feed_url: buildAbsoluteUrl(config, "/feed.json"),
106
+ description: config.site.feed.description,
107
+ language: getHtmlLanguage(config),
108
+ items: entries.map((entry) => {
109
+ const url = buildPostUrl(config, entry.permalink);
110
+ return removeUndefined({
111
+ id: url,
112
+ url,
113
+ title: entry.title,
114
+ content_html: entry.html,
115
+ summary: getDescription(entry),
116
+ date_published: getEntryPublishedTime(entry) ?? void 0,
117
+ date_modified: getEntryUpdatedTime(entry) ?? void 0,
118
+ tags: normalizeTags(entry.frontmatter.tags)
119
+ });
120
+ })
121
+ });
122
+ }
123
+
124
+ // src/metadata.ts
125
+ import { calculateReadingTime } from "@riebeckite/core";
126
+ function buildArticleSeo(config, options, permalink, post) {
127
+ const siteName = getSiteName(config, options);
128
+ const title = getArticleTitle(config, permalink, post.frontmatter.title);
129
+ const canonicalUrl = buildCanonicalUrl(
130
+ config,
131
+ post.frontmatter.canonical,
132
+ permalink
133
+ );
134
+ const description = getDescription(post) || config.site.description;
135
+ const imageUrl = buildImageUrl(
136
+ config,
137
+ options,
138
+ post.frontmatter.ogImage ?? post.frontmatter.image
139
+ );
140
+ const publishedTime = getIsoDate2(
141
+ post.frontmatter.published ?? post.frontmatter.date ?? post.frontmatter.created
142
+ );
143
+ const modifiedTime = getIsoDate2(post.frontmatter.updated) ?? publishedTime;
144
+ const tags = normalizeTags(post.frontmatter.tags);
145
+ const readingTimeMinutes = calculateReadingTime(post.html);
146
+ const breadcrumb = buildBreadcrumbSchema(config, [
147
+ { name: siteName, url: buildAbsoluteUrl(config, "/") },
148
+ { name: title, url: canonicalUrl }
149
+ ]);
150
+ return {
151
+ title: buildPageTitle(siteName, title),
152
+ description,
153
+ canonicalUrl,
154
+ imageUrl,
155
+ type: "article",
156
+ noindex: post.frontmatter.noindex === true,
157
+ publishedTime,
158
+ modifiedTime,
159
+ tags,
160
+ readingTimeMinutes,
161
+ jsonLd: [
162
+ removeUndefined({
163
+ "@context": "https://schema.org",
164
+ "@type": "BlogPosting",
165
+ headline: title,
166
+ description,
167
+ url: canonicalUrl,
168
+ image: imageUrl ? [imageUrl] : void 0,
169
+ datePublished: publishedTime,
170
+ dateModified: modifiedTime,
171
+ author: config.site.author ? { "@type": "Person", name: config.site.author } : void 0,
172
+ publisher: { "@type": "Organization", name: siteName },
173
+ keywords: tags.length > 0 ? tags.join(", ") : void 0,
174
+ timeRequired: readingTimeMinutes ? `PT${readingTimeMinutes}M` : void 0,
175
+ inLanguage: getHtmlLanguage(config)
176
+ }),
177
+ breadcrumb
178
+ ]
179
+ };
180
+ }
181
+ function buildWebsiteSeo(config, options, input) {
182
+ const siteName = getSiteName(config, options);
183
+ const canonicalUrl = buildAbsoluteUrl(config, input.path);
184
+ const description = input.description || config.site.description;
185
+ const imageUrl = buildImageUrl(config, options);
186
+ const title = input.kind === "tag" ? input.title : buildPageTitle(siteName, input.title);
187
+ return {
188
+ title,
189
+ description,
190
+ canonicalUrl,
191
+ imageUrl,
192
+ type: "website",
193
+ noindex: false,
194
+ tags: [],
195
+ jsonLd: [
196
+ removeUndefined({
197
+ "@context": "https://schema.org",
198
+ "@type": "WebSite",
199
+ name: siteName,
200
+ description,
201
+ url: canonicalUrl,
202
+ inLanguage: getHtmlLanguage(config)
203
+ }),
204
+ buildBreadcrumbSchema(config, [
205
+ { name: siteName, url: buildAbsoluteUrl(config, "/") }
206
+ ])
207
+ ]
208
+ };
209
+ }
210
+ function buildCanonicalUrl(config, canonical, permalink) {
211
+ if (typeof canonical === "string" && canonical.trim()) {
212
+ return buildAbsoluteUrl(config, canonical.trim());
213
+ }
214
+ return buildPostUrl(config, permalink);
215
+ }
216
+ function buildImageUrl(config, options, value) {
217
+ const image = value || options.defaultImage || config.site.defaultOgImage;
218
+ return image ? buildAbsoluteUrl(config, image) : "";
219
+ }
220
+ function getSiteName(config, options) {
221
+ return options.siteName || config.site.title;
222
+ }
223
+ function getArticleTitle(config, slug, value) {
224
+ if (typeof value === "string" && value.trim()) return value.trim();
225
+ const lastSegment = slug.split("/").filter(Boolean).at(-1);
226
+ return lastSegment || config.site.title;
227
+ }
228
+ function buildPageTitle(siteName, title) {
229
+ if (!title || title === siteName) return siteName;
230
+ return `${title} | ${siteName}`;
231
+ }
232
+ function getIsoDate2(value) {
233
+ if (value instanceof Date && !Number.isNaN(value.getTime())) {
234
+ return value.toISOString();
235
+ }
236
+ if (typeof value !== "string" || !value.trim()) return void 0;
237
+ const date = new Date(value);
238
+ return Number.isNaN(date.getTime()) ? void 0 : date.toISOString();
239
+ }
240
+
241
+ // src/plugin.ts
242
+ import { definePlugin } from "@riebeckite/core";
243
+
244
+ // src/site-files.ts
245
+ function renderSitemap(config, entries) {
246
+ const urls = [
247
+ { loc: buildAbsoluteUrl(config, "/"), lastmod: void 0 },
248
+ ...filterFeedEntries(config, entries).filter((entry) => entry.permalink !== "/").map((entry) => ({
249
+ loc: buildPostUrl(config, entry.permalink),
250
+ lastmod: getEntryUpdatedTime(entry)
251
+ }))
252
+ ];
253
+ const body = urls.map(
254
+ (url) => `<url><loc>${escapeXml(url.loc)}</loc>${url.lastmod ? `<lastmod>${escapeXml(url.lastmod)}</lastmod>` : ""}</url>`
255
+ ).join("");
256
+ return `<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">${body}</urlset>`;
257
+ }
258
+ function renderRobots(config) {
259
+ return [
260
+ "User-agent: *",
261
+ "Allow: /",
262
+ `Sitemap: ${buildAbsoluteUrl(config, "/sitemap.xml")}`,
263
+ ""
264
+ ].join("\n");
265
+ }
266
+
267
+ // src/endpoints.ts
268
+ function createSeoEndpoints(options) {
269
+ return [
270
+ options.sitemap === true ? {
271
+ path: "/sitemap.xml",
272
+ handler: ({ config, manifest }) => ({
273
+ headers: { "content-type": "application/xml; charset=utf-8" },
274
+ body: renderSitemap(config, manifest.entries)
275
+ })
276
+ } : null,
277
+ options.robots === true ? {
278
+ path: "/robots.txt",
279
+ handler: ({ config }) => ({
280
+ headers: { "content-type": "text/plain; charset=utf-8" },
281
+ body: renderRobots(config)
282
+ })
283
+ } : null,
284
+ options.feed?.rss === true ? {
285
+ path: "/feed.xml",
286
+ handler: ({ config, manifest }) => ({
287
+ headers: { "content-type": "application/rss+xml; charset=utf-8" },
288
+ body: renderRssFeed(
289
+ config,
290
+ filterFeedEntries(config, manifest.entries)
291
+ )
292
+ })
293
+ } : null,
294
+ options.feed?.atom === true ? {
295
+ path: "/atom.xml",
296
+ handler: ({ config, manifest }) => ({
297
+ headers: { "content-type": "application/atom+xml; charset=utf-8" },
298
+ body: renderAtomFeed(
299
+ config,
300
+ filterFeedEntries(config, manifest.entries)
301
+ )
302
+ })
303
+ } : null,
304
+ options.feed?.json === true ? {
305
+ path: "/feed.json",
306
+ handler: ({ config, manifest }) => ({
307
+ json: JSON.parse(
308
+ renderJsonFeed(
309
+ config,
310
+ filterFeedEntries(config, manifest.entries)
311
+ )
312
+ )
313
+ })
314
+ } : null
315
+ ].filter((endpoint) => endpoint !== null);
316
+ }
317
+
318
+ // src/plugin.ts
319
+ function seo(options = {}) {
320
+ return definePlugin({
321
+ name: "seo",
322
+ options,
323
+ seo: {
324
+ buildArticleSeo: (config, permalink, post) => buildArticleSeo(config, options, permalink, post),
325
+ buildWebsiteSeo: (config, input) => buildWebsiteSeo(config, options, input),
326
+ buildAbsoluteUrl,
327
+ buildPostUrl,
328
+ getDescription,
329
+ getEntryPublishedTime,
330
+ getEntryUpdatedTime,
331
+ getHtmlLanguage,
332
+ renderSitemap,
333
+ renderRobots,
334
+ renderRssFeed,
335
+ renderAtomFeed,
336
+ renderJsonFeed
337
+ },
338
+ endpoints: createSeoEndpoints(options)
339
+ });
340
+ }
341
+ export {
342
+ buildAbsoluteUrl,
343
+ buildArticleSeo,
344
+ buildPostUrl,
345
+ buildWebsiteSeo,
346
+ filterFeedEntries,
347
+ getDescription,
348
+ getEntryPublishedTime,
349
+ getEntryUpdatedTime,
350
+ getHtmlLanguage,
351
+ renderAtomFeed,
352
+ renderJsonFeed,
353
+ renderRobots,
354
+ renderRssFeed,
355
+ renderSitemap,
356
+ seo
357
+ };
@@ -0,0 +1,7 @@
1
+ import type { ContentManifestEntry, PostContent, ResolvedRiebeckiteConfig } from "@riebeckite/core";
2
+ export declare function getDescription(post: Pick<PostContent, "frontmatter" | "html">): string;
3
+ export declare function filterFeedEntries(config: ResolvedRiebeckiteConfig, entries: ContentManifestEntry[]): ContentManifestEntry[];
4
+ export declare function getEntryPublishedTime(entry: ContentManifestEntry): string | null;
5
+ export declare function getEntryUpdatedTime(entry: ContentManifestEntry): string | null;
6
+ export declare function getHtmlLanguage(config: ResolvedRiebeckiteConfig): string;
7
+ export declare function normalizeTags(tags: unknown): string[];
@@ -0,0 +1,3 @@
1
+ import type { PluginEndpoint } from "@riebeckite/core";
2
+ import type { SeoPluginOptions } from "./types.js";
3
+ export declare function createSeoEndpoints(options: SeoPluginOptions): PluginEndpoint[];
@@ -0,0 +1,5 @@
1
+ import type { ResolvedRiebeckiteConfig } from "@riebeckite/core";
2
+ import type { RenderableFeedEntry } from "./types.js";
3
+ export declare function renderRssFeed(config: ResolvedRiebeckiteConfig, entries: RenderableFeedEntry[]): string;
4
+ export declare function renderAtomFeed(config: ResolvedRiebeckiteConfig, entries: RenderableFeedEntry[]): string;
5
+ export declare function renderJsonFeed(config: ResolvedRiebeckiteConfig, entries: RenderableFeedEntry[]): string;
@@ -0,0 +1,4 @@
1
+ import type { PostContent, ResolvedRiebeckiteConfig, SeoMetadata, WebsiteSeoInput } from "@riebeckite/core";
2
+ import type { SeoPluginOptions } from "./types.js";
3
+ export declare function buildArticleSeo(config: ResolvedRiebeckiteConfig, options: SeoPluginOptions, permalink: string, post: PostContent): SeoMetadata;
4
+ export declare function buildWebsiteSeo(config: ResolvedRiebeckiteConfig, options: SeoPluginOptions, input: WebsiteSeoInput): SeoMetadata;
@@ -0,0 +1,2 @@
1
+ import type { SeoPluginOptions } from "./types.js";
2
+ export declare function seo(options?: SeoPluginOptions): import("@riebeckite/core").RiebeckitePlugin<SeoPluginOptions>;
@@ -0,0 +1,6 @@
1
+ import type { ResolvedRiebeckiteConfig } from "@riebeckite/core";
2
+ export declare function buildBreadcrumbSchema(config: ResolvedRiebeckiteConfig, items: {
3
+ name: string;
4
+ url: string;
5
+ }[]): Record<string, unknown>;
6
+ export declare function removeUndefined<T extends Record<string, unknown>>(value: T): T;
@@ -0,0 +1,3 @@
1
+ import type { ContentManifestEntry, ResolvedRiebeckiteConfig } from "@riebeckite/core";
2
+ export declare function renderSitemap(config: ResolvedRiebeckiteConfig, entries: ContentManifestEntry[]): string;
3
+ export declare function renderRobots(config: ResolvedRiebeckiteConfig): string;
@@ -0,0 +1,16 @@
1
+ import type { ContentManifestEntry } from "@riebeckite/core";
2
+ export type FeedOptions = {
3
+ rss?: boolean;
4
+ atom?: boolean;
5
+ json?: boolean;
6
+ };
7
+ export type SeoPluginOptions = {
8
+ siteName?: string;
9
+ defaultImage?: string;
10
+ feed?: FeedOptions;
11
+ sitemap?: boolean;
12
+ robots?: boolean;
13
+ };
14
+ export type RenderableFeedEntry = ContentManifestEntry & {
15
+ html?: string;
16
+ };
@@ -0,0 +1,3 @@
1
+ import type { ResolvedRiebeckiteConfig } from "@riebeckite/core";
2
+ export declare function buildAbsoluteUrl(config: ResolvedRiebeckiteConfig, pathOrUrl: string): string;
3
+ export declare function buildPostUrl(config: ResolvedRiebeckiteConfig, permalink: string): string;
@@ -0,0 +1 @@
1
+ export declare function escapeXml(value: string): string;
package/package.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "@riebeckite/plugin-seo",
3
+ "version": "0.0.1",
4
+ "license": "Apache-2.0",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js",
12
+ "source": "./index.ts",
13
+ "default": "./dist/index.js"
14
+ }
15
+ },
16
+ "dependencies": {
17
+ "@riebeckite/core": "0.0.1"
18
+ },
19
+ "publishConfig": {
20
+ "access": "public"
21
+ },
22
+ "files": [
23
+ "LICENSE",
24
+ "README.md",
25
+ "README_ja.md",
26
+ "dist"
27
+ ],
28
+ "repository": {
29
+ "type": "git",
30
+ "url": "https://github.com/Rerurate514/riebeckite.git",
31
+ "directory": "packages/plugins/seo"
32
+ },
33
+ "homepage": "https://github.com/Rerurate514/riebeckite#readme",
34
+ "bugs": {
35
+ "url": "https://github.com/Rerurate514/riebeckite/issues"
36
+ },
37
+ "description": "SEO metadata, sitemaps, feeds, and robots.txt for Riebeckite.",
38
+ "keywords": [
39
+ "riebeckite",
40
+ "plugin",
41
+ "seo",
42
+ "sitemap"
43
+ ],
44
+ "engines": {
45
+ "node": "^20.19.0 || >=22.12.0"
46
+ },
47
+ "sideEffects": false,
48
+ "scripts": {
49
+ "build": "node ../../../scripts/build_package.mjs"
50
+ }
51
+ }