@kawapress/plugin-last-updated 0.0.1 → 0.2.0
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 +3 -2
- package/README.zh-CN.md +3 -2
- package/package.json +3 -3
- package/src/components/LastUpdated.vue +4 -8
- package/src/index.ts +0 -1
- package/src/plugin.ts +3 -5
- package/src/types.ts +17 -9
package/README.md
CHANGED
|
@@ -126,7 +126,7 @@ KawaPress keeps extension boundaries explicit:
|
|
|
126
126
|
- a **Runtime Plugin** extends the real Vue App and Vue Router in both SSR and the browser;
|
|
127
127
|
- a **Preset** combines configuration and plugins into a ready-to-use experience such as nagi.
|
|
128
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/
|
|
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/plugins/plugin-system).
|
|
130
130
|
|
|
131
131
|
## Documentation
|
|
132
132
|
|
|
@@ -134,7 +134,8 @@ A logical plugin is installed once and can provide both generator and runtime be
|
|
|
134
134
|
- [What is KawaPress?](https://shenqingchuan.github.io/kawapress/en/guide/what-is-kawapress)
|
|
135
135
|
- [Markdown Extensions](https://shenqingchuan.github.io/kawapress/en/guide/markdown-extensions)
|
|
136
136
|
- [Internationalization](https://shenqingchuan.github.io/kawapress/en/guide/internationalization)
|
|
137
|
-
- [Plugin System](https://shenqingchuan.github.io/kawapress/en/
|
|
137
|
+
- [Plugin System](https://shenqingchuan.github.io/kawapress/en/plugins/plugin-system)
|
|
138
|
+
- [Official Plugins](https://shenqingchuan.github.io/kawapress/en/plugins/overview)
|
|
138
139
|
- [Theme Customization](https://shenqingchuan.github.io/kawapress/en/guide/theme-customization)
|
|
139
140
|
|
|
140
141
|
## Contributing
|
package/README.zh-CN.md
CHANGED
|
@@ -126,7 +126,7 @@ KawaPress 把扩展边界分得很清楚:
|
|
|
126
126
|
- **Runtime Plugin** 在 SSR 和浏览器中扩展真实的 Vue App 与 Vue Router;
|
|
127
127
|
- **Preset** 把配置和一组插件组合成可以直接使用的产品体验,例如 nagi。
|
|
128
128
|
|
|
129
|
-
一个逻辑插件只需要安装一次,同时可以提供生成侧和运行侧能力。更多内容请查看[插件体系](https://shenqingchuan.github.io/kawapress/
|
|
129
|
+
一个逻辑插件只需要安装一次,同时可以提供生成侧和运行侧能力。更多内容请查看[插件体系](https://shenqingchuan.github.io/kawapress/plugins/plugin-system)。
|
|
130
130
|
|
|
131
131
|
## 文档
|
|
132
132
|
|
|
@@ -134,7 +134,8 @@ KawaPress 把扩展边界分得很清楚:
|
|
|
134
134
|
- [KawaPress 是什么?](https://shenqingchuan.github.io/kawapress/guide/what-is-kawapress)
|
|
135
135
|
- [Markdown 语法扩展](https://shenqingchuan.github.io/kawapress/guide/markdown-extensions)
|
|
136
136
|
- [国际化](https://shenqingchuan.github.io/kawapress/guide/internationalization)
|
|
137
|
-
- [插件体系](https://shenqingchuan.github.io/kawapress/
|
|
137
|
+
- [插件体系](https://shenqingchuan.github.io/kawapress/plugins/plugin-system)
|
|
138
|
+
- [官方插件总览](https://shenqingchuan.github.io/kawapress/plugins/overview)
|
|
138
139
|
- [主题定制](https://shenqingchuan.github.io/kawapress/guide/theme-customization)
|
|
139
140
|
|
|
140
141
|
## 参与贡献
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kawapress/plugin-last-updated",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0
|
|
4
|
+
"version": "0.2.0",
|
|
5
5
|
"description": "Last updated time and edit link for every KawaPress page",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://shenqingchuan.github.io/kawapress/",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"registry": "https://registry.npmjs.org/"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
|
-
"kawapress": "0.0
|
|
40
|
+
"kawapress": "0.2.0"
|
|
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.0
|
|
50
|
+
"kawapress": "0.2.0"
|
|
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
|
|
package/src/index.ts
CHANGED
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
|
}
|