astro-openmoji 0.1.0 → 0.1.2
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 +24 -48
- package/dist/index.js +1 -1
- package/dist/rehype.js +1 -1
- package/dist/{transform-CnWUZewM.js → transform-CcxaX6qn.js} +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
# astro-openmoji
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/astro-openmoji)
|
|
4
|
+
[](https://github.com/xjn2005/astro-openmoji/actions/workflows/publish.yml)
|
|
5
|
+
|
|
3
6
|
在 Astro 构建 Markdown 时,把源码中的原生 Unicode Emoji 转换为本地 [OpenMoji](https://openmoji.org/) SVG。
|
|
4
7
|
|
|
5
8
|
- Markdown 源文件保持不变
|
|
@@ -39,13 +42,13 @@ export default defineConfig({
|
|
|
39
42
|
```html
|
|
40
43
|
<p>
|
|
41
44
|
今天学 CMake 学得有些
|
|
42
|
-
<img class="openmoji" src="/openmoji/1F635-200D-1F4AB.svg" alt="😵💫" style="width:
|
|
45
|
+
<img class="openmoji" src="/openmoji/1F635-200D-1F4AB.svg" alt="😵💫" style="width:var(--openmoji-size,1.25em);height:var(--openmoji-size,1.25em);vertical-align:var(--openmoji-vertical-align,-0.22em);display:inline-block">
|
|
43
46
|
,但总算跑通了
|
|
44
|
-
<img class="openmoji" src="/openmoji/1F680.svg" alt="🚀" style="width:
|
|
47
|
+
<img class="openmoji" src="/openmoji/1F680.svg" alt="🚀" style="width:var(--openmoji-size,1.25em);height:var(--openmoji-size,1.25em);vertical-align:var(--openmoji-vertical-align,-0.22em);display:inline-block">
|
|
45
48
|
</p>
|
|
46
49
|
```
|
|
47
50
|
|
|
48
|
-
`alt` 始终保留原 Emoji
|
|
51
|
+
`alt` 始终保留原 Emoji。内联样式默认以 `1.25em` 渲染图片并对齐文字基线;尺寸仍跟随当前字体缩放,不会引入客户端 JavaScript。
|
|
49
52
|
|
|
50
53
|
## 配置项
|
|
51
54
|
|
|
@@ -63,6 +66,24 @@ openmoji({
|
|
|
63
66
|
| `assetDir` | `string` | `"openmoji"` | 输出目录和公共 URL 路径,可使用 `emoji/assets` 这样的相对路径 |
|
|
64
67
|
| `className` | `string` | `"openmoji"` | 生成的 `<img>` 使用的单个 CSS 类名 |
|
|
65
68
|
|
|
69
|
+
### 尺寸与对齐
|
|
70
|
+
|
|
71
|
+
OpenMoji 图形在 SVG 画布内通常带有留白,因此插件默认使用 `1.25em`,让可见图形更接近原生 Emoji 的视觉高度。可以通过 CSS 自定义属性调整生成图片,不需要使用 `!important`:
|
|
72
|
+
|
|
73
|
+
```css
|
|
74
|
+
.openmoji {
|
|
75
|
+
--openmoji-size: 1.1em;
|
|
76
|
+
--openmoji-vertical-align: -0.15em;
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
| CSS 自定义属性 | 默认值 | 说明 |
|
|
81
|
+
| --- | --- | --- |
|
|
82
|
+
| `--openmoji-size` | `1.25em` | 同时控制生成图片的宽度和高度 |
|
|
83
|
+
| `--openmoji-vertical-align` | `-0.22em` | 控制图片相对文字基线的垂直位置 |
|
|
84
|
+
|
|
85
|
+
如果需要恢复旧版外观,可设置 `--openmoji-size: 1em` 和 `--openmoji-vertical-align: -0.125em`。使用自定义 `className` 时,将这些变量设置在对应类名上即可。
|
|
86
|
+
|
|
66
87
|
Astro 的 `base` 会自动加入图片 URL。例如 `base: "/blog"` 时,图片地址为 `/blog/openmoji/1F680.svg`,资源仍输出到 `dist/openmoji/`。
|
|
67
88
|
|
|
68
89
|
## 转换范围
|
|
@@ -108,51 +129,6 @@ npm pack --dry-run
|
|
|
108
129
|
|
|
109
130
|
测试包含独立 Rehype 转换、真实 `astro build` fixture、`base: "/blog"`、最小资源输出,以及真实 `astro dev` SVG 请求。
|
|
110
131
|
|
|
111
|
-
## 通过 GitHub Actions 发布到 npm
|
|
112
|
-
|
|
113
|
-
仓库包含两个发布工作流:
|
|
114
|
-
|
|
115
|
-
- `Bootstrap publish to npm`:仅用于第一次创建 npm 包,需要一个临时 `NPM_TOKEN`。
|
|
116
|
-
- `Publish to npm`:之后在 GitHub Release 发布时运行,使用 npm Trusted Publishing(OIDC),不保存 npm Token。
|
|
117
|
-
|
|
118
|
-
### 第一次发布
|
|
119
|
-
|
|
120
|
-
1. 确保 GitHub 仓库 `xjn2005/astro-openmoji` 是公开仓库,并将当前项目推送到 `main`。
|
|
121
|
-
2. 在 npm 创建一个短有效期、具备公开包发布权限的 Granular Access Token。若 npm 账户启用了发布 2FA,请按 npm 页面提示允许该自动化 Token 绕过发布 2FA。
|
|
122
|
-
3. 打开 GitHub 仓库的 **Settings → Secrets and variables → Actions**,新增 Repository secret:`NPM_TOKEN`。
|
|
123
|
-
4. 打开 **Actions → Bootstrap publish to npm → Run workflow**。它会依次执行安装、测试、构建、打包预检,并发布 `0.1.0`;不要重复运行同一版本。
|
|
124
|
-
5. 在 npm 确认 `astro-openmoji` 已创建且包含 provenance 信息。
|
|
125
|
-
|
|
126
|
-
首次工作流使用 `--provenance`,因此 GitHub 仓库必须公开。Token 不要写入文件、提交记录或工作流源码。
|
|
127
|
-
|
|
128
|
-
### 切换到 Trusted Publishing
|
|
129
|
-
|
|
130
|
-
首次发布成功后,在 npm 的 `astro-openmoji` 包设置中添加 GitHub Actions Trusted Publisher,填写:
|
|
131
|
-
|
|
132
|
-
| 字段 | 值 |
|
|
133
|
-
| --- | --- |
|
|
134
|
-
| Organization or user | `xjn2005` |
|
|
135
|
-
| Repository | `astro-openmoji` |
|
|
136
|
-
| Workflow filename | `publish.yml` |
|
|
137
|
-
| Environment | 留空 |
|
|
138
|
-
|
|
139
|
-
保存后:
|
|
140
|
-
|
|
141
|
-
1. 删除 GitHub Repository secret `NPM_TOKEN`。
|
|
142
|
-
2. 禁用或删除 `.github/workflows/bootstrap-publish.yml`,避免误触首次发布流程。
|
|
143
|
-
3. 在 Trusted Publisher 创建后的两天内完成一次正式 OIDC 发布验证;验证成功后,可在 npm 包设置中进一步禁止 Token 发布并要求 2FA。
|
|
144
|
-
|
|
145
|
-
长期工作流只授予 `contents: read` 和 `id-token: write`,不会读取 npm Token。Trusted Publishing 会自动生成 npm provenance。
|
|
146
|
-
|
|
147
|
-
### 发布后续版本
|
|
148
|
-
|
|
149
|
-
1. 更新 `package.json` 和 `package-lock.json` 中的版本,例如运行 `npm version patch --no-git-tag-version`。
|
|
150
|
-
2. 运行 `npm test`、`npm run build` 和 `npm pack --dry-run`,然后提交并推送版本改动。
|
|
151
|
-
3. 为该提交创建匹配的标签,例如版本为 `0.1.1` 时使用 `v0.1.1`。
|
|
152
|
-
4. 在 GitHub 创建并发布使用该标签的 Release。
|
|
153
|
-
|
|
154
|
-
`Publish to npm` 会检出 Release 标签,并在发布前验证标签严格等于 `v${package.json.version}`。两者不一致时工作流会失败,不会发布。
|
|
155
|
-
|
|
156
132
|
## 许可证与署名
|
|
157
133
|
|
|
158
134
|
`astro-openmoji` 插件代码使用 [MIT License](./LICENSE)。OpenMoji 图形资产由 OpenMoji 项目提供,使用 [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/);详情见 [ATTRIBUTION.md](./ATTRIBUTION.md)。
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as openmojiAssetRoot, n as normalizeBase, r as resolveOptions, t as transformOpenmojiTree } from "./transform-
|
|
1
|
+
import { i as openmojiAssetRoot, n as normalizeBase, r as resolveOptions, t as transformOpenmojiTree } from "./transform-CcxaX6qn.js";
|
|
2
2
|
import { copyFile, mkdir, readFile } from "node:fs/promises";
|
|
3
3
|
import { isUnifiedProcessor, unified } from "@astrojs/markdown-remark";
|
|
4
4
|
// src/index.ts
|
package/dist/rehype.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as openmojiAssetRoot, n as normalizeBase, r as resolveOptions, t as transformOpenmojiTree } from "./transform-
|
|
1
|
+
import { i as openmojiAssetRoot, n as normalizeBase, r as resolveOptions, t as transformOpenmojiTree } from "./transform-CcxaX6qn.js";
|
|
2
2
|
// src/rehype.ts
|
|
3
3
|
const rehypeOpenmoji = (options = {}) => {
|
|
4
4
|
const resolved = resolveOptions(options);
|
|
@@ -47,7 +47,7 @@ function assetUrl(base, assetDir, filename) {
|
|
|
47
47
|
}
|
|
48
48
|
// src/transform.ts
|
|
49
49
|
const skippedElements = /* @__PURE__ */ new Set(["code", "pre"]);
|
|
50
|
-
const imageStyle = "width:
|
|
50
|
+
const imageStyle = "width:var(--openmoji-size,1.25em);height:var(--openmoji-size,1.25em);vertical-align:var(--openmoji-vertical-align,-0.22em);display:inline-block";
|
|
51
51
|
function transformOpenmojiTree(tree, options) {
|
|
52
52
|
transformChildren(tree, options);
|
|
53
53
|
}
|