feat: add last contributor to each document#980
Conversation
|
Deploy preview for docusaurus-preview ready! Built with commit 821331e |
endiliey
left a comment
There was a problem hiding this comment.
The PR preview for v2 is available on
https://deploy-preview-980--munseo-preview.netlify.com/
To be honest I don't agree with this feature on v2 as this would best be left as a plugin and not every user would want it. I personally don't want to see bloated contributor A xxxx% on the docs
|
@endiliey - does the Netlify preview actually show the contributor list? I don't see it. This was a v1 feature request that would have been toggled by a siteConfig option. Can we just add this as a |
|
I do agree if it's on v1. But I think for v2 our paradigm is that we don't want a lot of siteConfig and try to keep things as simple as possible especially on UI related things like this. In addition, I think it's not a good idea to add the field into the docs metadata itself. In the UI itself, we are exposed |
|
@JoelMarcey @endiliey I finished doing My proposed solution would be:
But, we still need to think of edge case like how if the readme inside versioned_docs get changed, how shall we combine the result from /docs and /versioned_docs? |
|
That is correct. Do note we have version fallback on v1 & that make things even more complicated.
Maybe I should say its the same for v1. But ofc it could be a good addition to have. WDYT @JoelMarcey @yangshun |
|
I think this feature was always intended for v1. I have to scope change thoughts two this, if we believe contributors are becoming too difficult or cumbersome:
|
|
Now that the last updated time is merged, I will start working back on this. Do we want the |
- Rename css class to be more general
bf676bf to
b8487a7
Compare
- s/getGitlastupdated/getGitLastUpdatedTime - refactor part in getGitLastUpdated[Time|By] that overlaps - remove getAuthorInformation
b8487a7 to
4bb321f
Compare
JoelMarcey
left a comment
There was a problem hiding this comment.
I ❤️ the way this looks on the preview.
Is there anyway to have a link to the commit represented by the last update time and last committer?
yangshun
left a comment
There was a problem hiding this comment.
Code looks good, just have some suggestions regarding formatting!
v1/lib/core/DocsLayout.js
Outdated
| <div className="docLastUpdateTimestamp"> | ||
| {(updateTime || updateAuthor) && ( | ||
| <div className="docLastUpdate"> | ||
| {updateTime && ( |
There was a problem hiding this comment.
Let's use a combined format:
- Only
enableUpdateTime: "Last updated on 2018-10-15 01:23" - Only
enableUpdateBy: "Last updated by @fiennyangeln" - Both
enableUpdateTimeandenableUpdateBy: "Last updated on 2018-10-15 01:23 by @fiennyangeln"
WDYT?
There was a problem hiding this comment.
It's nice 😍 ! I will implement this.
yangshun
left a comment
There was a problem hiding this comment.
Gave a more thorough review. Please let me know if you have questions!
v1/lib/core/utils.js
Outdated
|
|
||
| // Wrap in try/catch in case the shell commands fail (e.g. project doesn't use Git, etc). | ||
| try { | ||
| const format = GIT_LAST_UPDATED_TYPE.TIME === type ? '%ct' : 'author=%an'; |
There was a problem hiding this comment.
Do we need the author here?
Let's do away with this format variable. Instead, we could do
git log --follow --summary --format="%ct, %an" <file>
which would generate something like:
1539553317, Yangshun Tay
1539457591, Yangshun Tay
1539185600, Yangshun Tay
1538339532, Fienny Angelina
1537426859, Marvin Heilemann
1537330146, Yangshun Tay
1537203487, Yangshun Tay
copy package.json => v1/package.json (81%)
1537169695, Yangshun Tay
1537157761, Yangshun Tay
1537157671, Endilie Y
1537157183, endiliey
and then parse each line for the timestamp and author using a regex that extracts the timestamp and the author. Exampe regex here - https://regex101.com/r/O0HQrc/1
This method will just return both the relevant timestamp and author as an object { timestamp: 12345, author: 'Fienny' }, and it's up to the callsite to use whichever field they need.
There was a problem hiding this comment.
I initially put the author to differentiate author vs commit summary since both are just plain string 😁 Wdyt about making it stronger like ^(\d{10}), (.+)$ ? It can last until 2038 based on Google
v1/lib/core/utils.js
Outdated
|
|
||
| const records = getGitLastUpdated(filepath, GIT_LAST_UPDATED_TYPE.TIME); | ||
|
|
||
| const timeSpan = records.find((item, index, arr) => { |
There was a problem hiding this comment.
This finding logic can be shifted into the getGitLastUpdated method.
And getGitLastUpdatedTime will in the end just become:
function getGitLastUpdatedTime(filepath) {
const commit = getGitLastUpdated(filepath);
if (!commit) {
return null;
}
const date = new Date(parseInt(commit.timestamp, 10) * 1000);
return date.toLocaleString();
}
It's possible but not sure how much value it provides. Going directly to the list of commits for the file would be more valuable. We could do this in a follow up PR though. |
I think we can debate which is more valuable, but I am ok with going to a list of commits (in fact, I may have suggested even that option before). I am quite certain though, having a link to somewhere makes more sense than having no link at all. I would totally expect as a user to have a link to some commit or a list of commits for the file or something. |
-Refactor the utils, combine lastupdatedtime and lastupdatedby -Replace the test
f9d02dc to
dc6f24f
Compare
For more clarity and to make relationship more clear
…n/Docusaurus into fiennyangeln-add-contributor-list
docs/api-site-config.md
Outdated
| #### `fonts` [object] | ||
| Font-family CSS configuration for the site. If a font family is specified in `siteConfig.js` as `$myFont`, then adding a `myFont` key to an array in `fonts` will allow you to configure the font. Items appearing earlier in the array will take priority of later elements, so ordering of the fonts matter. | ||
|
|
||
| #### `enableUpdateBy` [boolean] |
There was a problem hiding this comment.
This is a wrong place to put this. Now it's in between the fonts config.
docs/api-site-config.md
Outdated
| Font-family CSS configuration for the site. If a font family is specified in `siteConfig.js` as `$myFont`, then adding a `myFont` key to an array in `fonts` will allow you to configure the font. Items appearing earlier in the array will take priority of later elements, so ordering of the fonts matter. | ||
|
|
||
| #### `enableUpdateBy` [boolean] | ||
| An option to enable the docs showing last update time. Set to `true` to show a line at the bottom right corner of each doc page as `Last updated by <Author Name>`. |
There was a problem hiding this comment.
Copy paste error... Should be about last author not last update time.
yangshun
left a comment
There was a problem hiding this comment.
There are some small nits which I have made on your behalf. Additionally, I changed the updated time format to show just the date as the timing is not that crucial. Thanks for making this happen!


Motivation
Create Contributor List for each documents (#858)
Have you read the Contributing Guidelines on pull requests?
Yes
Test Plan
Run yarn build on the website -- it will update the author list in the metadata
Related PRs
None