@riebeckite/plugin-discord-embed 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 +201 -0
- package/README.md +82 -0
- package/README_ja.md +74 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +124 -0
- package/dist/src/head.d.ts +10 -0
- package/dist/src/options.d.ts +8 -0
- package/dist/src/types.d.ts +34 -0
- package/package.json +51 -0
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,82 @@
|
|
|
1
|
+
# @riebeckite/plugin-discord-embed
|
|
2
|
+
|
|
3
|
+
Completes each page's `<head>` for Discord link previews.
|
|
4
|
+
|
|
5
|
+
Discord's `Discordbot` reads the shared page's `<head>` metadata to build its
|
|
6
|
+
preview card. The `seo` plugin already emits the shared `og:*` and `twitter:*`
|
|
7
|
+
tags, so this plugin adds only the Discord-specific pieces that are missing:
|
|
8
|
+
|
|
9
|
+
- `<meta name="theme-color">`, which Discord uses for the embed's left border
|
|
10
|
+
color;
|
|
11
|
+
- `og:image:alt` (and optionally `og:image:width` / `og:image:height`).
|
|
12
|
+
|
|
13
|
+
[日本語](./README_ja.md)
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { defineConfig } from "@riebeckite/core";
|
|
19
|
+
import { discordEmbed } from "@riebeckite/plugin-discord-embed";
|
|
20
|
+
|
|
21
|
+
export default defineConfig({
|
|
22
|
+
// ...
|
|
23
|
+
plugins: [discordEmbed()],
|
|
24
|
+
});
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Options
|
|
28
|
+
|
|
29
|
+
| Option | Type | Default | Description |
|
|
30
|
+
| ------ | ---- | ------- | ----------- |
|
|
31
|
+
| `themeColor` | `string` | `"#5865F2"` | Embed accent color. Discord blurple |
|
|
32
|
+
| `imageAlt` | `boolean` | `true` | Emit `og:image:alt` when the entry has an image |
|
|
33
|
+
| `imageDimensions` | `boolean` | `true` | Emit `og:image:width` / `og:image:height` when the entry's image dimensions are known |
|
|
34
|
+
|
|
35
|
+
`themeColor` accepts `#rgb`, `#rgba`, `#rrggbb`, or `#rrggbbaa`.
|
|
36
|
+
|
|
37
|
+
## Frontmatter
|
|
38
|
+
|
|
39
|
+
| Field | Use |
|
|
40
|
+
| ----- | --- |
|
|
41
|
+
| `theme_color` / `themeColor` / `discord_color` | Override the embed color for one entry |
|
|
42
|
+
| `ogImage` / `image` | Mark that the entry has an image, enabling the image tags |
|
|
43
|
+
| `ogImageWidth` / `imageWidth` | Image width |
|
|
44
|
+
| `ogImageHeight` / `imageHeight` | Image height |
|
|
45
|
+
|
|
46
|
+
The color resolves from the frontmatter override first, then the `themeColor`
|
|
47
|
+
option. An invalid frontmatter color records a
|
|
48
|
+
`discord-embed-invalid-color` diagnostic (warning) and falls back to the option
|
|
49
|
+
default.
|
|
50
|
+
|
|
51
|
+
## Emitted tags
|
|
52
|
+
|
|
53
|
+
The `onManifestCreated` hook assigns `entry.headTags` for every entry:
|
|
54
|
+
|
|
55
|
+
```html
|
|
56
|
+
<meta name="theme-color" content="#1ABC9C" />
|
|
57
|
+
<meta property="og:image:alt" content="Article title" />
|
|
58
|
+
<meta property="og:image:width" content="1200" />
|
|
59
|
+
<meta property="og:image:height" content="630" />
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## The site shell renders `headTags`
|
|
63
|
+
|
|
64
|
+
This plugin does not own the `<head>`. It provides
|
|
65
|
+
`ContentManifestEntry.headTags`; whether to render them is the site's decision.
|
|
66
|
+
A site route sets `c.set("headTags", entry.headTags ?? [])`, and
|
|
67
|
+
`app/routes/_renderer.tsx` maps them to `<meta>` / `<link>` / `<script>`.
|
|
68
|
+
See [HonoX Integration](../../../docs/en/honox-integration.md), section
|
|
69
|
+
"Site application contract", for details.
|
|
70
|
+
|
|
71
|
+
## Exports
|
|
72
|
+
|
|
73
|
+
- `discordEmbed(options?)` / `discordEmbedPlugin(options?)` — plugin factory
|
|
74
|
+
- `buildDiscordHeadTags(entry, options, diagnostics)` — build one entry's head
|
|
75
|
+
tags
|
|
76
|
+
- `resolveDiscordEmbedOptions(options?)` — resolve defaults
|
|
77
|
+
- Types: `DiscordEmbedOptions`, `ResolvedDiscordEmbedOptions`
|
|
78
|
+
|
|
79
|
+
## See also
|
|
80
|
+
|
|
81
|
+
- [HonoX Integration](../../../docs/en/honox-integration.md)
|
|
82
|
+
- [Plugin system](../../../docs/en/plugin-system.md)
|
package/README_ja.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# @riebeckite/plugin-discord-embed
|
|
2
|
+
|
|
3
|
+
Discord のリンクプレビュー向けに、各ページの `<head>` を補完するプラグインです。
|
|
4
|
+
|
|
5
|
+
Discord の `Discordbot` は共有されたページの `<head>` メタデータを読んでプレビューカードを組み立てます。
|
|
6
|
+
`seo` プラグインが共通の `og:*` と `twitter:*` を出力するのに対し、このプラグインは Discord 固有の不足分だけを追加します。
|
|
7
|
+
|
|
8
|
+
- 埋め込みの左側ボーダー色に使われる `<meta name="theme-color">`
|
|
9
|
+
- `og:image:alt`(任意で `og:image:width` / `og:image:height`)
|
|
10
|
+
|
|
11
|
+
[English](./README.md)
|
|
12
|
+
|
|
13
|
+
## 設定する
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { defineConfig } from "@riebeckite/core";
|
|
17
|
+
import { discordEmbed } from "@riebeckite/plugin-discord-embed";
|
|
18
|
+
|
|
19
|
+
export default defineConfig({
|
|
20
|
+
// ...
|
|
21
|
+
plugins: [discordEmbed()],
|
|
22
|
+
});
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## オプション
|
|
26
|
+
|
|
27
|
+
| オプション | 型 | 既定値 | 説明 |
|
|
28
|
+
| --- | --- | --- | --- |
|
|
29
|
+
| `themeColor` | `string` | `"#5865F2"` | 埋め込みのアクセントカラー。Discord の blurple |
|
|
30
|
+
| `imageAlt` | `boolean` | `true` | 画像がある記事に `og:image:alt` を出力する |
|
|
31
|
+
| `imageDimensions` | `boolean` | `true` | 画像サイズが分かる記事に `og:image:width` / `og:image:height` を出力する |
|
|
32
|
+
|
|
33
|
+
`themeColor` は `#rgb`、`#rgba`、`#rrggbb`、`#rrggbbaa` のいずれかを受け付けます。
|
|
34
|
+
|
|
35
|
+
## Frontmatter
|
|
36
|
+
|
|
37
|
+
| フィールド | 用途 |
|
|
38
|
+
| --- | --- |
|
|
39
|
+
| `theme_color` / `themeColor` / `discord_color` | この記事だけ埋め込みカラーを上書きする |
|
|
40
|
+
| `ogImage` / `image` | 画像の有無を判定し、`og:image:alt` などを付ける |
|
|
41
|
+
| `ogImageWidth` / `imageWidth` | 画像の幅 |
|
|
42
|
+
| `ogImageHeight` / `imageHeight` | 画像の高さ |
|
|
43
|
+
|
|
44
|
+
色の解決順は、frontmatter の上書き、なければ `themeColor` オプションです。
|
|
45
|
+
frontmatter の色が無効な場合は診断 `discord-embed-invalid-color`(warning)を記録し、オプションの既定値へフォールバックします。
|
|
46
|
+
|
|
47
|
+
## 出力するタグ
|
|
48
|
+
|
|
49
|
+
`onManifestCreated` フックで、すべてのエントリーに `entry.headTags` を設定します。
|
|
50
|
+
|
|
51
|
+
```html
|
|
52
|
+
<meta name="theme-color" content="#1ABC9C" />
|
|
53
|
+
<meta property="og:image:alt" content="記事タイトル" />
|
|
54
|
+
<meta property="og:image:width" content="1200" />
|
|
55
|
+
<meta property="og:image:height" content="630" />
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Site shell が headTags を描画する
|
|
59
|
+
|
|
60
|
+
このプラグインは `<head>` を所有しません。プラグインが提供するのは `ContentManifestEntry.headTags` であり、描画するかどうかは Site が決めます。
|
|
61
|
+
Site の route が `c.set("headTags", entry.headTags ?? [])` を設定し、`app/routes/_renderer.tsx` がそれを `<meta>` / `<link>` / `<script>` に変換します。
|
|
62
|
+
詳しくは [HonoX Integration](../../../docs/ja/honox-integration.md) の "Site Application の拡張 contract" を参照してください。
|
|
63
|
+
|
|
64
|
+
## 主なエクスポート
|
|
65
|
+
|
|
66
|
+
- `discordEmbed(options?)` / `discordEmbedPlugin(options?)`: プラグインを作成する
|
|
67
|
+
- `buildDiscordHeadTags(entry, options, diagnostics)`: エントリーの head タグを組み立てる
|
|
68
|
+
- `resolveDiscordEmbedOptions(options?)`: 既定値を解決する
|
|
69
|
+
- 型: `DiscordEmbedOptions`、`ResolvedDiscordEmbedOptions`
|
|
70
|
+
|
|
71
|
+
## 関連資料
|
|
72
|
+
|
|
73
|
+
- [HonoX Integration](../../../docs/ja/honox-integration.md)
|
|
74
|
+
- [プラグインシステム](../../../docs/ja/plugin-system.md)
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { DiscordEmbedOptions } from "./src/types.js";
|
|
2
|
+
export type { DiscordEmbedOptions, ResolvedDiscordEmbedOptions, } from "./src/types.js";
|
|
3
|
+
export { buildDiscordHeadTags } from "./src/head.js";
|
|
4
|
+
export { DEFAULT_THEME_COLOR, resolveDiscordEmbedOptions, } from "./src/options.js";
|
|
5
|
+
/**
|
|
6
|
+
* Completes a page's `<head>` for Discord link previews.
|
|
7
|
+
*
|
|
8
|
+
* `Discordbot` reads the shared page's head metadata, so this plugin provides
|
|
9
|
+
* the missing Discord-specific tags on each manifest entry: the embed accent
|
|
10
|
+
* color (`theme-color`) and the OpenGraph image metadata. It does not own the
|
|
11
|
+
* site shell; the Site renders `entry.headTags` (see the HonoX integration
|
|
12
|
+
* docs).
|
|
13
|
+
*/
|
|
14
|
+
export declare function discordEmbed(options?: DiscordEmbedOptions): import("@riebeckite/core").RiebeckitePlugin<DiscordEmbedOptions>;
|
|
15
|
+
export declare const discordEmbedPlugin: typeof discordEmbed;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
// index.ts
|
|
2
|
+
import { definePlugin } from "@riebeckite/core";
|
|
3
|
+
|
|
4
|
+
// src/options.ts
|
|
5
|
+
var DEFAULT_THEME_COLOR = "#5865F2";
|
|
6
|
+
var HEX_COLOR_PATTERN = /^#(?:[0-9a-fA-F]{3,4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/;
|
|
7
|
+
function resolveDiscordEmbedOptions(options = {}) {
|
|
8
|
+
return {
|
|
9
|
+
themeColor: options.themeColor ?? DEFAULT_THEME_COLOR,
|
|
10
|
+
imageAlt: options.imageAlt ?? true,
|
|
11
|
+
imageDimensions: options.imageDimensions ?? true
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
function validateDiscordEmbedOptions(options) {
|
|
15
|
+
if (!options) return [];
|
|
16
|
+
const issues = [];
|
|
17
|
+
if (options.themeColor !== void 0 && (typeof options.themeColor !== "string" || !HEX_COLOR_PATTERN.test(options.themeColor))) {
|
|
18
|
+
issues.push({
|
|
19
|
+
path: "themeColor",
|
|
20
|
+
message: 'Expected a hex color such as "#5865F2".'
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
for (const key of ["imageAlt", "imageDimensions"]) {
|
|
24
|
+
if (options[key] !== void 0 && typeof options[key] !== "boolean") {
|
|
25
|
+
issues.push({ path: key, message: "Expected a boolean." });
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return issues;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// src/head.ts
|
|
32
|
+
var COLOR_FIELDS = ["theme_color", "themeColor", "discord_color"];
|
|
33
|
+
var IMAGE_FIELDS = ["ogImage", "image"];
|
|
34
|
+
var WIDTH_FIELDS = ["ogImageWidth", "imageWidth"];
|
|
35
|
+
var HEIGHT_FIELDS = ["ogImageHeight", "imageHeight"];
|
|
36
|
+
function buildDiscordHeadTags(entry, options, diagnostics) {
|
|
37
|
+
const tags = [];
|
|
38
|
+
const color = resolveColor(entry, options, diagnostics);
|
|
39
|
+
tags.push({ tag: "meta", attrs: { name: "theme-color", content: color } });
|
|
40
|
+
const image = readFirstString(entry, IMAGE_FIELDS);
|
|
41
|
+
if (image !== null) {
|
|
42
|
+
if (options.imageAlt) {
|
|
43
|
+
const alt = entry.title.trim() || entry.slug;
|
|
44
|
+
tags.push({
|
|
45
|
+
tag: "meta",
|
|
46
|
+
attrs: { property: "og:image:alt", content: alt }
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
if (options.imageDimensions) {
|
|
50
|
+
const width = readFirstNumber(entry, WIDTH_FIELDS);
|
|
51
|
+
const height = readFirstNumber(entry, HEIGHT_FIELDS);
|
|
52
|
+
if (width !== null) {
|
|
53
|
+
tags.push({
|
|
54
|
+
tag: "meta",
|
|
55
|
+
attrs: { property: "og:image:width", content: String(width) }
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
if (height !== null) {
|
|
59
|
+
tags.push({
|
|
60
|
+
tag: "meta",
|
|
61
|
+
attrs: { property: "og:image:height", content: String(height) }
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return tags;
|
|
67
|
+
}
|
|
68
|
+
function resolveColor(entry, options, diagnostics) {
|
|
69
|
+
const requested = readFirstString(entry, COLOR_FIELDS);
|
|
70
|
+
if (requested === null) return options.themeColor;
|
|
71
|
+
if (HEX_COLOR_PATTERN.test(requested)) return requested;
|
|
72
|
+
diagnostics.push({
|
|
73
|
+
code: "discord-embed-invalid-color",
|
|
74
|
+
severity: "warning",
|
|
75
|
+
pluginName: "discord-embed",
|
|
76
|
+
slug: entry.slug,
|
|
77
|
+
message: `Invalid Discord embed color "${requested}" was ignored.`,
|
|
78
|
+
suggestion: `Use a hex color such as "#5865F2". Fell back to "${options.themeColor}".`
|
|
79
|
+
});
|
|
80
|
+
return options.themeColor;
|
|
81
|
+
}
|
|
82
|
+
function readFirstString(entry, fields) {
|
|
83
|
+
for (const field of fields) {
|
|
84
|
+
const value = entry.frontmatter[field];
|
|
85
|
+
if (typeof value === "string" && value.trim().length > 0) {
|
|
86
|
+
return value.trim();
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
function readFirstNumber(entry, fields) {
|
|
92
|
+
for (const field of fields) {
|
|
93
|
+
const value = entry.frontmatter[field];
|
|
94
|
+
if (typeof value === "number" && Number.isFinite(value)) return value;
|
|
95
|
+
if (typeof value === "string" && value.trim().length > 0) {
|
|
96
|
+
const parsed = Number(value.trim());
|
|
97
|
+
if (Number.isFinite(parsed)) return parsed;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// index.ts
|
|
104
|
+
function discordEmbed(options = {}) {
|
|
105
|
+
const resolved = resolveDiscordEmbedOptions(options);
|
|
106
|
+
return definePlugin({
|
|
107
|
+
name: "discord-embed",
|
|
108
|
+
options,
|
|
109
|
+
validateOptions: validateDiscordEmbedOptions,
|
|
110
|
+
onManifestCreated: ({ manifest, diagnostics }) => {
|
|
111
|
+
for (const entry of manifest.entries) {
|
|
112
|
+
entry.headTags = buildDiscordHeadTags(entry, resolved, diagnostics);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
var discordEmbedPlugin = discordEmbed;
|
|
118
|
+
export {
|
|
119
|
+
DEFAULT_THEME_COLOR,
|
|
120
|
+
buildDiscordHeadTags,
|
|
121
|
+
discordEmbed,
|
|
122
|
+
discordEmbedPlugin,
|
|
123
|
+
resolveDiscordEmbedOptions
|
|
124
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ContentManifestEntry, Diagnostic, PluginHeadTag } from "@riebeckite/core";
|
|
2
|
+
import type { ResolvedDiscordEmbedOptions } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Builds the Discord-specific head tags for one entry.
|
|
5
|
+
*
|
|
6
|
+
* The color is always emitted. The OpenGraph image tags are only emitted when
|
|
7
|
+
* the entry actually has an image, so the metadata stays consistent with the
|
|
8
|
+
* `og:image` the `seo` plugin emits.
|
|
9
|
+
*/
|
|
10
|
+
export declare function buildDiscordHeadTags(entry: ContentManifestEntry, options: ResolvedDiscordEmbedOptions, diagnostics: Diagnostic[]): PluginHeadTag[];
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ConfigValidationIssue } from "@riebeckite/core";
|
|
2
|
+
import type { DiscordEmbedOptions, ResolvedDiscordEmbedOptions } from "./types.js";
|
|
3
|
+
/** Discord blurple, the accent color of the official embed card. */
|
|
4
|
+
export declare const DEFAULT_THEME_COLOR = "#5865F2";
|
|
5
|
+
/** Accepts `#rgb`, `#rgba`, `#rrggbb`, and `#rrggbbaa`. */
|
|
6
|
+
export declare const HEX_COLOR_PATTERN: RegExp;
|
|
7
|
+
export declare function resolveDiscordEmbedOptions(options?: DiscordEmbedOptions): ResolvedDiscordEmbedOptions;
|
|
8
|
+
export declare function validateDiscordEmbedOptions(options: DiscordEmbedOptions | undefined): readonly ConfigValidationIssue[];
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Discord-specific link preview options.
|
|
3
|
+
*
|
|
4
|
+
* The `seo` plugin already emits the shared OpenGraph and Twitter metadata.
|
|
5
|
+
* This plugin adds only the pieces Discord reads on top of that: the embed
|
|
6
|
+
* accent color and the OpenGraph image metadata.
|
|
7
|
+
*/
|
|
8
|
+
export type DiscordEmbedOptions = {
|
|
9
|
+
/**
|
|
10
|
+
* Embed accent color, emitted as `<meta name="theme-color">`. Discord uses
|
|
11
|
+
* it for the left border of the preview card.
|
|
12
|
+
*
|
|
13
|
+
* @default "#5865F2"
|
|
14
|
+
*/
|
|
15
|
+
themeColor?: string;
|
|
16
|
+
/**
|
|
17
|
+
* Emit `og:image:alt` with the entry title when the entry has an image.
|
|
18
|
+
*
|
|
19
|
+
* @default true
|
|
20
|
+
*/
|
|
21
|
+
imageAlt?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Emit `og:image:width` and `og:image:height` from frontmatter when the
|
|
24
|
+
* entry has an image and the dimensions are known.
|
|
25
|
+
*
|
|
26
|
+
* @default true
|
|
27
|
+
*/
|
|
28
|
+
imageDimensions?: boolean;
|
|
29
|
+
};
|
|
30
|
+
export type ResolvedDiscordEmbedOptions = {
|
|
31
|
+
themeColor: string;
|
|
32
|
+
imageAlt: boolean;
|
|
33
|
+
imageDimensions: boolean;
|
|
34
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@riebeckite/plugin-discord-embed",
|
|
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/discord-embed"
|
|
32
|
+
},
|
|
33
|
+
"homepage": "https://github.com/Rerurate514/riebeckite#readme",
|
|
34
|
+
"bugs": {
|
|
35
|
+
"url": "https://github.com/Rerurate514/riebeckite/issues"
|
|
36
|
+
},
|
|
37
|
+
"description": "Discord link preview metadata for Riebeckite pages.",
|
|
38
|
+
"keywords": [
|
|
39
|
+
"riebeckite",
|
|
40
|
+
"plugin",
|
|
41
|
+
"discord",
|
|
42
|
+
"embeds"
|
|
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
|
+
}
|