Skip to content

Commit 880cb2f

Browse files
shigmaulivz
authored andcommitted
rfc: plugin-git-log (#1406)
1 parent 01ef457 commit 880cb2f

File tree

1 file changed

+126
-0
lines changed

1 file changed

+126
-0
lines changed

rfcs/002.plugin-git-log.md

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
- Start Date: 2019-03-06
2+
- RFC PR: (leave this empty)
3+
- VuePress Issue: (leave this empty)
4+
5+
# Summary
6+
7+
A new official plugin `@vuepress/plugin-git-log` featured with more computed properties to be mixed in.
8+
9+
# Basic example
10+
11+
1. Apply the plugin `@vuepress/git-log`.
12+
2. It will provide a computed property `$git`, with following attributes:
13+
- **$git.updated:** the last updating time for this page
14+
- **$git.created:** the first creating time for this page
15+
- **$git.author:** the author for this page
16+
- **$git.contributors:** contributors for this page
17+
- **$git.commits:** detailed informations of commits to this page
18+
19+
# Motivation
20+
21+
Although last-updated works well, git-log provides more information. Such plugin will provide remarkable convenience to users, because it automatically generates some necessary meta information.
22+
23+
# Detailed design
24+
25+
## Computed Properties
26+
27+
We will get all computed properties through a command line like this:
28+
29+
```bash
30+
git log --format="%h %at %ct %an"
31+
```
32+
33+
Passing the result to client, we will get a `$git.commits` like this:
34+
35+
```json
36+
[{
37+
"hash": "aabbccd",
38+
"authorTime": 11111111,
39+
"commitTime": 22222222,
40+
"author": "fooooooo"
41+
}, {
42+
"hash": "ffeeddc",
43+
"authorTime": 33333333,
44+
"commitTime": 44444444,
45+
"author": "baaaaaar"
46+
}]
47+
```
48+
49+
And other computed properties can be derived from this.
50+
51+
## Options
52+
53+
### formatTime
54+
55+
A function to format unix time. It may have two arguments: `time` and `lang`. The default value will be:
56+
57+
```js
58+
function formatTime (timestamp, lang) {
59+
return new Date(timestamp).toLocaleString(lang)
60+
}
61+
```
62+
63+
### additionalProps
64+
65+
Aside from some properties listed above, we can add some custom properties throuth this option:
66+
67+
```js
68+
module.exports = {
69+
plugins: [
70+
['@vuepress/git-log', {
71+
additionalProps: {
72+
subject: '%s',
73+
authorEmail: '%ae',
74+
}
75+
}]
76+
]
77+
}
78+
```
79+
80+
### additionalArgs
81+
82+
A string or an array of strings to include all the additional args. The default value will be `'--no-merge'`.
83+
84+
### onlyFirstAndLastCommit
85+
86+
If set to `true`, this plugin will only look for the first and last commit, which may save lots of time. The default value is `false`.
87+
88+
However, setting this option to also means you will have no access to **\$git.contributors** and **$git.commits**.
89+
90+
# Drawbacks
91+
92+
- It will replace existing plugin `@vuepress/plugin-last-updated`, which may lead to a breaking change (also see [adoption-strategy](#adoption-strategy)).
93+
- It will cost more time to get all the detailed informations on a large git project than in the past with default options (because `onlyFirstAndLastCommit` is `false`).
94+
95+
# Alternatives
96+
97+
Publish multiple packages like `@vuepress/plugin-last-updated`. But in that case, we may need lots of command lines, which may seriously affect performance.
98+
99+
# Adoption strategy
100+
101+
We will deprecate `@vuepress/plugin-last-updated` after several months. Before then, we will automatically import `@vuepress/plugin-git-log` in `@vuepress/plugin-last-updated` and support both functionality.
102+
103+
```js
104+
// server
105+
module.exports = {
106+
plugins: ['@vuepress/last-updated']
107+
// show deprecation warnging
108+
}
109+
```
110+
```js
111+
// client
112+
export default {
113+
created () {
114+
console.log(this.$lastUpdated) // show deprecation warnging
115+
console.log(this.$git.updated)
116+
}
117+
}
118+
```
119+
120+
# How we teach this
121+
122+
Through official plugin documentation (i.e. `/plugin/official/plugin-git-log.html`).
123+
124+
# Unresolved questions
125+
126+
N/A

0 commit comments

Comments
 (0)