@kawapress/plugin-last-updated 0.1.0 → 0.2.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/README.md +32 -128
- package/README.zh-CN.md +33 -129
- package/package.json +6 -6
- package/src/components/LastUpdated.vue +11 -9
- package/src/index.ts +0 -1
- package/src/last-updated.css +29 -6
- package/src/plugin.ts +3 -5
- package/src/types.ts +17 -9
package/README.md
CHANGED
|
@@ -1,156 +1,60 @@
|
|
|
1
|
-
|
|
2
|
-
<picture>
|
|
3
|
-
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/ShenQingchuan/kawapress/main/docs/public/kawapress-logo-dark.png">
|
|
4
|
-
<img src="https://raw.githubusercontent.com/ShenQingchuan/kawapress/main/docs/public/kawapress-logo.png" alt="KawaPress" width="180">
|
|
5
|
-
</picture>
|
|
6
|
-
</p>
|
|
1
|
+
# @kawapress/plugin-last-updated
|
|
7
2
|
|
|
8
|
-
|
|
3
|
+
A last updated time and an edit link at the bottom of every KawaPress page.
|
|
9
4
|
|
|
10
|
-
|
|
11
|
-
<strong>A Vue-first static site generator for documentation and content-focused websites.</strong>
|
|
12
|
-
</p>
|
|
5
|
+
[](https://www.npmjs.com/package/@kawapress/plugin-last-updated) · [简体中文](https://github.com/kawapress/kawapress/blob/main/packages/plugin-last-updated/README.zh-CN.md)
|
|
13
6
|
|
|
14
|
-
|
|
15
|
-
Write in Markdown. Develop with real SSR. Extend everything through public APIs.
|
|
16
|
-
</p>
|
|
7
|
+
`@kawapress/plugin-last-updated` is part of [KawaPress](https://github.com/kawapress/kawapress), a Vue-first static site generator.
|
|
17
8
|
|
|
18
|
-
|
|
19
|
-
<a href="https://www.npmjs.com/package/kawapress"><img src="https://img.shields.io/npm/v/kawapress?label=npm&color=42b883" alt="npm version"></a>
|
|
20
|
-
<a href="https://github.com/ShenQingchuan/kawapress/actions/workflows/deploy-pages.yml"><img src="https://github.com/ShenQingchuan/kawapress/actions/workflows/deploy-pages.yml/badge.svg" alt="documentation build"></a>
|
|
21
|
-
<a href="https://github.com/ShenQingchuan/kawapress/blob/main/LICENSE"><img src="https://img.shields.io/github/license/ShenQingchuan/kawapress" alt="MIT license"></a>
|
|
22
|
-
<img src="https://img.shields.io/badge/Node.js-%E2%89%A522.12-339933?logo=nodedotjs&logoColor=white" alt="Node.js 22.12 or newer">
|
|
23
|
-
</p>
|
|
9
|
+
## Features
|
|
24
10
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
11
|
+
- The time comes from the last git commit of the Markdown file, so nobody keeps it up to date by hand.
|
|
12
|
+
- An "Edit this page" link built from a URL template.
|
|
13
|
+
- The server renders in UTC and the browser reformats the time in the visitor's zone.
|
|
14
|
+
- Pass any `Intl.DateTimeFormat` options to change the format.
|
|
15
|
+
- Turn off the date or the link for one page with `lastUpdated: false` or `editLink: false`.
|
|
30
16
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
## Why KawaPress?
|
|
34
|
-
|
|
35
|
-
KawaPress turns Markdown into pre-rendered Vue websites. It keeps the familiar simplicity of a documentation generator while giving themes and plugins the same public extension points used by the official experience.
|
|
36
|
-
|
|
37
|
-
- **Real SSR during development** — every initial request is server-rendered, so SSR-only problems appear before build or deployment.
|
|
38
|
-
- **A complete default experience** — the built-in nagi (凪) preset includes responsive documentation layouts, dark mode, local search, syntax highlighting, Twoslash, code groups, multilingual navigation, and more.
|
|
39
|
-
- **Vue from end to end** — Markdown becomes Vue components, Vue Router handles navigation, and regular Vue SFCs fit naturally into content.
|
|
40
|
-
- **AI-ready output** — nagi generates page-level Markdown, locale-aware `llms.txt` and `llms-full.txt`, plus built-in copy actions.
|
|
41
|
-
- **One extension model** — Generator Plugins, Runtime Plugins, and Presets cover build-time behavior, the Vue runtime, themes, and reusable product setups without private theme hooks.
|
|
42
|
-
|
|
43
|
-
KawaPress is an independent project. It is not a VitePress fork or a drop-in replacement, and it intentionally does not use VitePress configuration.
|
|
44
|
-
|
|
45
|
-
## Quick Start
|
|
46
|
-
|
|
47
|
-
You need [Node.js](https://nodejs.org/) 22.12 or newer.
|
|
48
|
-
|
|
49
|
-
Create a new site with the scaffolder:
|
|
17
|
+
## Install
|
|
50
18
|
|
|
51
19
|
```sh
|
|
52
|
-
npm
|
|
53
|
-
cd my-kawapress-site
|
|
54
|
-
npm run dev
|
|
20
|
+
npm install --save-dev @kawapress/plugin-last-updated
|
|
55
21
|
```
|
|
56
22
|
|
|
57
|
-
`pnpm
|
|
58
|
-
|
|
59
|
-
If you would rather see every file from the start, set the site up by hand:
|
|
60
|
-
|
|
61
|
-
```sh
|
|
62
|
-
mkdir my-kawapress-site
|
|
63
|
-
cd my-kawapress-site
|
|
64
|
-
pnpm init
|
|
65
|
-
pnpm add --save-dev kawapress
|
|
66
|
-
```
|
|
23
|
+
`pnpm add --save-dev @kawapress/plugin-last-updated` and `yarn add --dev @kawapress/plugin-last-updated` work too.
|
|
67
24
|
|
|
68
|
-
|
|
25
|
+
## Usage
|
|
69
26
|
|
|
70
27
|
```ts
|
|
28
|
+
import lastUpdatedPlugin from '@kawapress/plugin-last-updated'
|
|
71
29
|
import { nagi } from 'kawapress/nagi'
|
|
72
30
|
|
|
73
31
|
export default nagi({
|
|
74
|
-
|
|
32
|
+
plugins: [
|
|
33
|
+
lastUpdatedPlugin({
|
|
34
|
+
editLink: {
|
|
35
|
+
pattern: 'https://github.com/your-name/your-repo/edit/main/:path',
|
|
36
|
+
},
|
|
37
|
+
}),
|
|
38
|
+
],
|
|
75
39
|
})
|
|
76
40
|
```
|
|
77
41
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
```md
|
|
81
|
-
---
|
|
82
|
-
layout: home
|
|
83
|
-
title: My Docs
|
|
84
|
-
---
|
|
85
|
-
|
|
86
|
-
# My Docs
|
|
87
|
-
|
|
88
|
-
Welcome to my KawaPress site.
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
Start the development server:
|
|
92
|
-
|
|
93
|
-
```sh
|
|
94
|
-
pnpm exec kawapress dev
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
Build static files into `dist`:
|
|
98
|
-
|
|
99
|
-
```sh
|
|
100
|
-
pnpm exec kawapress build
|
|
101
|
-
```
|
|
42
|
+
In a shallow clone the plugin skips the date and prints a warning. In GitHub Actions, set `fetch-depth: 0` for `actions/checkout`.
|
|
102
43
|
|
|
103
|
-
|
|
44
|
+
## Options
|
|
104
45
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
## What You Get
|
|
108
|
-
|
|
109
|
-
| Area | Included capability |
|
|
46
|
+
| Option | Description |
|
|
110
47
|
| --- | --- |
|
|
111
|
-
|
|
|
112
|
-
|
|
|
113
|
-
|
|
|
114
|
-
|
|
|
115
|
-
|
|
|
116
|
-
| AI consumption | Page `.md`, `llms.txt`, `llms-full.txt`, copy actions |
|
|
117
|
-
| Styling | UnoCSS integration with sensible nagi defaults |
|
|
118
|
-
|
|
119
|
-
The `kawapress` package includes nagi and its official plugins. A basic site only needs this one package; advanced users can compose the individual `@kawapress/*` packages directly.
|
|
120
|
-
|
|
121
|
-
## Extension Model
|
|
122
|
-
|
|
123
|
-
KawaPress keeps extension boundaries explicit:
|
|
124
|
-
|
|
125
|
-
- a **Generator Plugin** extends configuration, Markdown, page data, Vite, and build artifacts;
|
|
126
|
-
- a **Runtime Plugin** extends the real Vue App and Vue Router in both SSR and the browser;
|
|
127
|
-
- a **Preset** combines configuration and plugins into a ready-to-use experience such as nagi.
|
|
128
|
-
|
|
129
|
-
A logical plugin is installed once and can provide both generator and runtime behavior. Learn more in the [Plugin System guide](https://shenqingchuan.github.io/kawapress/en/guide/plugin-system).
|
|
48
|
+
| `editLink.pattern` | The edit address. `:path` is replaced by the file path in the repository. |
|
|
49
|
+
| `editLink.text` | The link text. |
|
|
50
|
+
| `lastUpdated.formatOptions` | Options for `Intl.DateTimeFormat`. |
|
|
51
|
+
| `labels` | Override the texts for every language. |
|
|
52
|
+
| `localeLabels` | Override the texts for one language. |
|
|
130
53
|
|
|
131
54
|
## Documentation
|
|
132
55
|
|
|
133
|
-
- [
|
|
134
|
-
- [What is KawaPress?](https://shenqingchuan.github.io/kawapress/en/guide/what-is-kawapress)
|
|
135
|
-
- [Markdown Extensions](https://shenqingchuan.github.io/kawapress/en/guide/markdown-extensions)
|
|
136
|
-
- [Internationalization](https://shenqingchuan.github.io/kawapress/en/guide/internationalization)
|
|
137
|
-
- [Plugin System](https://shenqingchuan.github.io/kawapress/en/guide/plugin-system)
|
|
138
|
-
- [Theme Customization](https://shenqingchuan.github.io/kawapress/en/guide/theme-customization)
|
|
139
|
-
|
|
140
|
-
## Contributing
|
|
141
|
-
|
|
142
|
-
Issues and pull requests are welcome. For a large feature, please open an issue first so the direction can be agreed on before implementation.
|
|
143
|
-
|
|
144
|
-
```sh
|
|
145
|
-
pnpm install
|
|
146
|
-
pnpm lint
|
|
147
|
-
pnpm typecheck
|
|
148
|
-
pnpm test
|
|
149
|
-
pnpm build
|
|
150
|
-
```
|
|
151
|
-
|
|
152
|
-
KawaPress uses Node.js 22.12 or newer and pnpm 11.22.0 for repository development.
|
|
56
|
+
[Documentation](https://kawapress.dev/en/plugins/last-updated) · [Report a problem](https://github.com/kawapress/kawapress/issues)
|
|
153
57
|
|
|
154
58
|
## License
|
|
155
59
|
|
|
156
|
-
[MIT](https://github.com/
|
|
60
|
+
[MIT](https://github.com/kawapress/kawapress/blob/main/LICENSE) © KawaPress contributors
|
package/README.zh-CN.md
CHANGED
|
@@ -1,156 +1,60 @@
|
|
|
1
|
-
|
|
2
|
-
<picture>
|
|
3
|
-
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/ShenQingchuan/kawapress/main/docs/public/kawapress-logo-dark.png">
|
|
4
|
-
<img src="https://raw.githubusercontent.com/ShenQingchuan/kawapress/main/docs/public/kawapress-logo.png" alt="KawaPress" width="180">
|
|
5
|
-
</picture>
|
|
6
|
-
</p>
|
|
1
|
+
# @kawapress/plugin-last-updated
|
|
7
2
|
|
|
8
|
-
|
|
3
|
+
在每个 KawaPress 页面底部显示最后更新时间和编辑链接。
|
|
9
4
|
|
|
10
|
-
|
|
11
|
-
<strong>以 Vue 为核心,面向文档与内容型网站的静态站点生成器。</strong>
|
|
12
|
-
</p>
|
|
5
|
+
[](https://www.npmjs.com/package/@kawapress/plugin-last-updated) · [English](https://github.com/kawapress/kawapress/blob/main/packages/plugin-last-updated/README.md)
|
|
13
6
|
|
|
14
|
-
|
|
15
|
-
用 Markdown 安心写作,在真实 SSR 中开发,通过公开能力自由扩展。
|
|
16
|
-
</p>
|
|
7
|
+
`@kawapress/plugin-last-updated` 是 [KawaPress](https://github.com/kawapress/kawapress) 的一部分。KawaPress 是一个以 Vue 为核心的静态站点生成器。
|
|
17
8
|
|
|
18
|
-
|
|
19
|
-
<a href="https://www.npmjs.com/package/kawapress"><img src="https://img.shields.io/npm/v/kawapress?label=npm&color=42b883" alt="npm 版本"></a>
|
|
20
|
-
<a href="https://github.com/ShenQingchuan/kawapress/actions/workflows/deploy-pages.yml"><img src="https://github.com/ShenQingchuan/kawapress/actions/workflows/deploy-pages.yml/badge.svg" alt="文档构建状态"></a>
|
|
21
|
-
<a href="https://github.com/ShenQingchuan/kawapress/blob/main/LICENSE"><img src="https://img.shields.io/github/license/ShenQingchuan/kawapress" alt="MIT 许可"></a>
|
|
22
|
-
<img src="https://img.shields.io/badge/Node.js-%E2%89%A522.12-339933?logo=nodedotjs&logoColor=white" alt="Node.js 22.12 或更高版本">
|
|
23
|
-
</p>
|
|
9
|
+
## 特性
|
|
24
10
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
11
|
+
- 时间来自 Markdown 文件最后一次 git 提交,不用人手维护。
|
|
12
|
+
- "编辑此页"链接由一个地址模板生成。
|
|
13
|
+
- 服务端按 UTC 渲染,浏览器加载后按访客所在的时区重新格式化。
|
|
14
|
+
- 传入任何 `Intl.DateTimeFormat` 选项都能改格式。
|
|
15
|
+
- 单个页面用 `lastUpdated: false` 或 `editLink: false` 关掉日期或链接。
|
|
30
16
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
## 为什么选择 KawaPress?
|
|
34
|
-
|
|
35
|
-
KawaPress 会把 Markdown 编译成预渲染的 Vue 网站。它保留了文档生成器简单、轻快的写作方式,同时让官方主题和第三方扩展使用完全相同的公开能力。
|
|
36
|
-
|
|
37
|
-
- **开发时也执行真实 SSR**:每次首次请求都会在服务端渲染。只在 SSR 中出现的问题,不必等到构建或上线后才发现。
|
|
38
|
-
- **默认体验完整**:内置 nagi(凪)预设,包含响应式文档布局、深浅色模式、本地搜索、代码高亮、Twoslash、代码组和多语言导航等常用能力。
|
|
39
|
-
- **从头到尾使用 Vue**:Markdown 会变成 Vue 组件,页面跳转交给 Vue Router;需要交互时,也可以自然地使用普通 Vue SFC。
|
|
40
|
-
- **面向 AI 的文档产物**:nagi 默认生成每页 `.md`、各语言的 `llms.txt` 与 `llms-full.txt`,并提供复制正文和链接的操作。
|
|
41
|
-
- **统一的扩展模型**:Generator Plugin、Runtime Plugin 与 Preset 分别覆盖生成阶段、Vue 运行时和能力组合,不依赖主题私有入口。
|
|
42
|
-
|
|
43
|
-
KawaPress 是一个独立项目,不是 VitePress 的分支或配置兼容层,也不能直接使用 VitePress 配置。
|
|
44
|
-
|
|
45
|
-
## 快速开始
|
|
46
|
-
|
|
47
|
-
请先准备 [Node.js](https://nodejs.org/) 22.12 或更高版本。
|
|
48
|
-
|
|
49
|
-
用脚手架创建新站点:
|
|
17
|
+
## 安装
|
|
50
18
|
|
|
51
19
|
```sh
|
|
52
|
-
npm
|
|
53
|
-
cd my-kawapress-site
|
|
54
|
-
npm run dev
|
|
20
|
+
npm install --save-dev @kawapress/plugin-last-updated
|
|
55
21
|
```
|
|
56
22
|
|
|
57
|
-
`pnpm
|
|
58
|
-
|
|
59
|
-
如果你更想从零看清每个文件,可以手动创建:
|
|
60
|
-
|
|
61
|
-
```sh
|
|
62
|
-
mkdir my-kawapress-site
|
|
63
|
-
cd my-kawapress-site
|
|
64
|
-
pnpm init
|
|
65
|
-
pnpm add --save-dev kawapress
|
|
66
|
-
```
|
|
23
|
+
也可以用 `pnpm add --save-dev @kawapress/plugin-last-updated` 或 `yarn add --dev @kawapress/plugin-last-updated`。
|
|
67
24
|
|
|
68
|
-
|
|
25
|
+
## 使用
|
|
69
26
|
|
|
70
27
|
```ts
|
|
28
|
+
import lastUpdatedPlugin from '@kawapress/plugin-last-updated'
|
|
71
29
|
import { nagi } from 'kawapress/nagi'
|
|
72
30
|
|
|
73
31
|
export default nagi({
|
|
74
|
-
|
|
32
|
+
plugins: [
|
|
33
|
+
lastUpdatedPlugin({
|
|
34
|
+
editLink: {
|
|
35
|
+
pattern: 'https://github.com/your-name/your-repo/edit/main/:path',
|
|
36
|
+
},
|
|
37
|
+
}),
|
|
38
|
+
],
|
|
75
39
|
})
|
|
76
40
|
```
|
|
77
41
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
```md
|
|
81
|
-
---
|
|
82
|
-
layout: home
|
|
83
|
-
title: My Docs
|
|
84
|
-
---
|
|
85
|
-
|
|
86
|
-
# My Docs
|
|
87
|
-
|
|
88
|
-
欢迎来到我的 KawaPress 站点。
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
启动开发服务器:
|
|
92
|
-
|
|
93
|
-
```sh
|
|
94
|
-
pnpm exec kawapress dev
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
构建静态文件到 `dist`:
|
|
98
|
-
|
|
99
|
-
```sh
|
|
100
|
-
pnpm exec kawapress build
|
|
101
|
-
```
|
|
42
|
+
浅克隆的仓库里,插件会跳过日期并给出警告。在 GitHub Actions 里,请给 `actions/checkout` 设置 `fetch-depth: 0`。
|
|
102
43
|
|
|
103
|
-
|
|
44
|
+
## 配置项
|
|
104
45
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
## 默认包含什么?
|
|
108
|
-
|
|
109
|
-
| 范围 | 内置能力 |
|
|
46
|
+
| 选项 | 说明 |
|
|
110
47
|
| --- | --- |
|
|
111
|
-
|
|
|
112
|
-
|
|
|
113
|
-
|
|
|
114
|
-
|
|
|
115
|
-
|
|
|
116
|
-
| AI 读取 | 页面 `.md`、`llms.txt`、`llms-full.txt`、页面复制操作 |
|
|
117
|
-
| 样式 | UnoCSS 集成与 nagi 默认配置 |
|
|
118
|
-
|
|
119
|
-
`kawapress` 已经包含 nagi 和它使用的官方插件。普通文档站只需要安装这一个包;需要自行组合能力时,也可以直接使用独立的 `@kawapress/*` 包。
|
|
120
|
-
|
|
121
|
-
## 扩展模型
|
|
122
|
-
|
|
123
|
-
KawaPress 把扩展边界分得很清楚:
|
|
124
|
-
|
|
125
|
-
- **Generator Plugin** 负责配置、Markdown、页面数据、Vite 与构建产物;
|
|
126
|
-
- **Runtime Plugin** 在 SSR 和浏览器中扩展真实的 Vue App 与 Vue Router;
|
|
127
|
-
- **Preset** 把配置和一组插件组合成可以直接使用的产品体验,例如 nagi。
|
|
128
|
-
|
|
129
|
-
一个逻辑插件只需要安装一次,同时可以提供生成侧和运行侧能力。更多内容请查看[插件体系](https://shenqingchuan.github.io/kawapress/guide/plugin-system)。
|
|
48
|
+
| `editLink.pattern` | 编辑地址。`:path` 会被替换成文件在仓库里的路径。 |
|
|
49
|
+
| `editLink.text` | 链接文字。 |
|
|
50
|
+
| `lastUpdated.formatOptions` | `Intl.DateTimeFormat` 的选项。 |
|
|
51
|
+
| `labels` | 改写所有语言的文字。 |
|
|
52
|
+
| `localeLabels` | 改写某一种语言的文字。 |
|
|
130
53
|
|
|
131
54
|
## 文档
|
|
132
55
|
|
|
133
|
-
- [
|
|
134
|
-
- [KawaPress 是什么?](https://shenqingchuan.github.io/kawapress/guide/what-is-kawapress)
|
|
135
|
-
- [Markdown 语法扩展](https://shenqingchuan.github.io/kawapress/guide/markdown-extensions)
|
|
136
|
-
- [国际化](https://shenqingchuan.github.io/kawapress/guide/internationalization)
|
|
137
|
-
- [插件体系](https://shenqingchuan.github.io/kawapress/guide/plugin-system)
|
|
138
|
-
- [主题定制](https://shenqingchuan.github.io/kawapress/guide/theme-customization)
|
|
139
|
-
|
|
140
|
-
## 参与贡献
|
|
141
|
-
|
|
142
|
-
欢迎提交 Issue 和 Pull Request。如果准备增加较大的功能,请先创建 Issue,把目标和方案聊清楚后再开始实现。
|
|
143
|
-
|
|
144
|
-
```sh
|
|
145
|
-
pnpm install
|
|
146
|
-
pnpm lint
|
|
147
|
-
pnpm typecheck
|
|
148
|
-
pnpm test
|
|
149
|
-
pnpm build
|
|
150
|
-
```
|
|
151
|
-
|
|
152
|
-
KawaPress 仓库使用 Node.js 22.12 或更高版本,以及 pnpm 11.22.0 进行开发。
|
|
56
|
+
[文档](https://kawapress.dev/plugins/last-updated) · [反馈问题](https://github.com/kawapress/kawapress/issues)
|
|
153
57
|
|
|
154
|
-
##
|
|
58
|
+
## 许可证
|
|
155
59
|
|
|
156
|
-
[MIT](https://github.com/
|
|
60
|
+
[MIT](https://github.com/kawapress/kawapress/blob/main/LICENSE) © KawaPress contributors
|
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kawapress/plugin-last-updated",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.1
|
|
4
|
+
"version": "0.2.1",
|
|
5
5
|
"description": "Last updated time and edit link for every KawaPress page",
|
|
6
6
|
"license": "MIT",
|
|
7
|
-
"homepage": "https://
|
|
7
|
+
"homepage": "https://kawapress.dev/",
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
10
|
-
"url": "git+https://github.com/
|
|
10
|
+
"url": "git+https://github.com/kawapress/kawapress.git",
|
|
11
11
|
"directory": "packages/plugin-last-updated"
|
|
12
12
|
},
|
|
13
13
|
"bugs": {
|
|
14
|
-
"url": "https://github.com/
|
|
14
|
+
"url": "https://github.com/kawapress/kawapress/issues"
|
|
15
15
|
},
|
|
16
16
|
"exports": {
|
|
17
17
|
".": {
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"registry": "https://registry.npmjs.org/"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
|
-
"kawapress": "0.1
|
|
40
|
+
"kawapress": "^0.2.1"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"consola": "^3.4.2"
|
|
@@ -47,6 +47,6 @@
|
|
|
47
47
|
"typescript": "^6.0.3",
|
|
48
48
|
"vite": "^8.2.2",
|
|
49
49
|
"vue": "^3.5.41",
|
|
50
|
-
"kawapress": "0.1
|
|
50
|
+
"kawapress": "0.2.1"
|
|
51
51
|
}
|
|
52
52
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import type { LastUpdatedPageData } from '../types'
|
|
3
2
|
import { usePageData, useSite } from 'kawapress/client'
|
|
4
3
|
import { computed, onMounted, shallowRef } from 'vue'
|
|
5
4
|
import { formatLastUpdatedDate } from '../format'
|
|
@@ -23,23 +22,20 @@ const texts = computed(() => resolveLastUpdatedTexts({
|
|
|
23
22
|
localeLabels: runtimeOptions.localeLabels,
|
|
24
23
|
}))
|
|
25
24
|
|
|
26
|
-
const frontmatter = computed<Record<string, unknown>>(
|
|
27
|
-
() => page.value?.frontmatter ?? {},
|
|
28
|
-
)
|
|
29
25
|
const lastUpdated = computed(() => {
|
|
30
|
-
const value =
|
|
26
|
+
const value = page.value?.lastUpdated
|
|
31
27
|
return typeof value === 'number' && Number.isFinite(value) ? value : undefined
|
|
32
28
|
})
|
|
33
29
|
const editLink = computed(() => {
|
|
34
|
-
const value =
|
|
30
|
+
const value = page.value?.editLink
|
|
35
31
|
return typeof value === 'string' && value.length > 0 ? value : undefined
|
|
36
32
|
})
|
|
37
33
|
|
|
38
34
|
const showDate = computed(() => (
|
|
39
|
-
lastUpdated.value !== undefined &&
|
|
35
|
+
lastUpdated.value !== undefined && page.value?.frontmatter.lastUpdated !== false
|
|
40
36
|
))
|
|
41
37
|
const showEditLink = computed(() => (
|
|
42
|
-
editLink.value !== undefined &&
|
|
38
|
+
editLink.value !== undefined && page.value?.frontmatter.editLink !== false
|
|
43
39
|
))
|
|
44
40
|
const visible = computed(() => showDate.value || showEditLink.value)
|
|
45
41
|
|
|
@@ -72,7 +68,13 @@ const formatted = computed(() => formatLastUpdatedDate(
|
|
|
72
68
|
:href="editLink"
|
|
73
69
|
rel="noopener noreferrer"
|
|
74
70
|
target="_blank"
|
|
75
|
-
>
|
|
71
|
+
>
|
|
72
|
+
<svg class="kawa-last-updated__icon" viewBox="0 0 24 24" aria-hidden="true">
|
|
73
|
+
<path d="M12 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7" />
|
|
74
|
+
<path d="M18.4 2.6a2.1 2.1 0 0 1 3 3L12 15l-4 1 1-4z" />
|
|
75
|
+
</svg>
|
|
76
|
+
<span>{{ texts.editLink }}</span>
|
|
77
|
+
</a>
|
|
76
78
|
<span v-if="showDate" class="kawa-last-updated__text">
|
|
77
79
|
<span class="kawa-last-updated__label">{{ texts.lastUpdated }}</span>
|
|
78
80
|
<time class="kawa-last-updated__time" :datetime="iso">{{ formatted }}</time>
|
package/src/index.ts
CHANGED
package/src/last-updated.css
CHANGED
|
@@ -1,20 +1,26 @@
|
|
|
1
1
|
@layer kawa.plugin {
|
|
2
|
+
/* Edit link on the left, last updated time on the right. */
|
|
2
3
|
.kawa-last-updated {
|
|
3
4
|
display: flex;
|
|
4
5
|
flex-wrap: wrap;
|
|
5
|
-
gap: 0.
|
|
6
|
-
align-items:
|
|
6
|
+
gap: 0.5rem 1.25rem;
|
|
7
|
+
align-items: center;
|
|
8
|
+
justify-content: space-between;
|
|
7
9
|
margin: 0;
|
|
8
|
-
color: var(--kawa-c-text-3);
|
|
9
10
|
font-family: var(--kawa-font-sans);
|
|
10
|
-
font-size: 0.
|
|
11
|
-
|
|
11
|
+
font-size: 0.875rem;
|
|
12
|
+
font-weight: 500;
|
|
13
|
+
line-height: 1.5rem;
|
|
12
14
|
}
|
|
13
15
|
|
|
14
16
|
.kawa-last-updated__edit {
|
|
15
|
-
|
|
17
|
+
display: inline-flex;
|
|
18
|
+
gap: 0.5rem;
|
|
19
|
+
align-items: center;
|
|
20
|
+
color: var(--kawa-c-brand);
|
|
16
21
|
text-decoration: none;
|
|
17
22
|
border-radius: calc(var(--kawa-radius) / 2);
|
|
23
|
+
transition: color 180ms cubic-bezier(0.22, 1, 0.36, 1);
|
|
18
24
|
}
|
|
19
25
|
|
|
20
26
|
.kawa-last-updated__edit:hover {
|
|
@@ -27,6 +33,23 @@
|
|
|
27
33
|
outline-offset: 2px;
|
|
28
34
|
}
|
|
29
35
|
|
|
36
|
+
.kawa-last-updated__icon {
|
|
37
|
+
flex: none;
|
|
38
|
+
width: 1em;
|
|
39
|
+
height: 1em;
|
|
40
|
+
fill: none;
|
|
41
|
+
stroke: currentcolor;
|
|
42
|
+
stroke-linecap: round;
|
|
43
|
+
stroke-linejoin: round;
|
|
44
|
+
stroke-width: 2;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/* With no edit link the time still sits on the right. */
|
|
48
|
+
.kawa-last-updated__text {
|
|
49
|
+
margin-left: auto;
|
|
50
|
+
color: var(--kawa-c-text-2);
|
|
51
|
+
}
|
|
52
|
+
|
|
30
53
|
.kawa-last-updated__time {
|
|
31
54
|
font-variant-numeric: tabular-nums;
|
|
32
55
|
}
|
package/src/plugin.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { KawaPressPlugin } from 'kawapress'
|
|
2
|
-
import type {
|
|
2
|
+
import type { LastUpdatedPluginOptions } from './types'
|
|
3
3
|
import { resolve } from 'node:path'
|
|
4
4
|
import process from 'node:process'
|
|
5
5
|
import { consola } from 'consola'
|
|
@@ -50,12 +50,10 @@ export function lastUpdatedPlugin(
|
|
|
50
50
|
|
|
51
51
|
api.pageData(async (pageData, { file }) => {
|
|
52
52
|
const sourceFile = resolve(file)
|
|
53
|
-
const page = pageData as LastUpdatedPageData
|
|
54
|
-
|
|
55
53
|
const dates = await loadTimestamps()
|
|
56
54
|
const lastUpdated = dates.get(sourceFile)
|
|
57
55
|
if (lastUpdated !== undefined) {
|
|
58
|
-
|
|
56
|
+
pageData.lastUpdated = lastUpdated
|
|
59
57
|
}
|
|
60
58
|
|
|
61
59
|
if (!editLinkPattern) {
|
|
@@ -71,7 +69,7 @@ export function lastUpdatedPlugin(
|
|
|
71
69
|
}
|
|
72
70
|
const repositoryPath = toRepositoryPath(sourceFile, topLevel)
|
|
73
71
|
if (repositoryPath) {
|
|
74
|
-
|
|
72
|
+
pageData.editLink = createEditLink(editLinkPattern, repositoryPath)
|
|
75
73
|
}
|
|
76
74
|
})
|
|
77
75
|
},
|
package/src/types.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import type { PageData } from 'kawapress'
|
|
2
|
-
|
|
3
1
|
/** User-visible strings of the last updated footer. */
|
|
4
2
|
export interface LastUpdatedLabels {
|
|
5
3
|
/** Text before the date, for example `Last updated`. */
|
|
@@ -40,12 +38,22 @@ export interface LastUpdatedRuntimeOptions {
|
|
|
40
38
|
}
|
|
41
39
|
|
|
42
40
|
/**
|
|
43
|
-
*
|
|
44
|
-
*
|
|
41
|
+
* Fields this plugin adds to the page data and to the frontmatter. Every
|
|
42
|
+
* reader sees them as soon as the plugin is imported, so a custom component can
|
|
43
|
+
* read `usePageData().value?.lastUpdated` without a cast.
|
|
45
44
|
*/
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
45
|
+
declare module 'kawapress' {
|
|
46
|
+
interface PageData {
|
|
47
|
+
/** Last commit time of the Markdown source file, in milliseconds since the epoch. */
|
|
48
|
+
lastUpdated?: number
|
|
49
|
+
/** Absolute URL of the page source on the repository host. */
|
|
50
|
+
editLink?: string
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
interface PageFrontmatter {
|
|
54
|
+
/** `false` hides the last updated time of this page. */
|
|
55
|
+
lastUpdated?: boolean | string
|
|
56
|
+
/** `false` hides the edit link of this page. */
|
|
57
|
+
editLink?: boolean
|
|
58
|
+
}
|
|
51
59
|
}
|