Skip to content

Commit 8cf9afe

Browse files
fiennyangelnyangshun
authored andcommitted
feat: add last contributor to each document (#980)
* add contributor list to each document * handle case where there is no github repo * Move to v1 * Revert "handle case where there is no github repo" This reverts commit a76a887. * Revert "add contributor list to each document" This reverts commit c0cc79f. * Add last updated by field * -Include enableUpdateBy in the config - Rename css class to be more general * Fix lint * Refactor : - s/getGitlastupdated/getGitLastUpdatedTime - refactor part in getGitLastUpdated[Time|By] that overlaps - remove getAuthorInformation * -Modify the display logic -Refactor the utils, combine lastupdatedtime and lastupdatedby -Replace the test * Modify docs based on the display change * Update docs for url and baseurl For more clarity and to make relationship more clear * Update support for Web App Manifest (#1046) * misc: update nits * misc: update nits
1 parent 4a7e1ea commit 8cf9afe

7 files changed

Lines changed: 158 additions & 62 deletions

File tree

docs/api-site-config.md

Lines changed: 72 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,31 @@ The `siteConfig` object contains the bulk of the configuration settings for your
1818
### Mandatory Fields
1919

2020
#### `baseUrl` [string]
21+
2122
baseUrl for your site. This can also be considered the path after the host. For example, `/metro/` is the baseUrl of https://facebook.github.io/metro/. For urls that have no path, the baseUrl should be set to `/`. This field is related to the [`url` field](#url-string).
2223

2324
#### `colors` [object]
25+
2426
Color configurations for the site.
2527

26-
* `primaryColor` is the color used the header navigation bar and sidebars.
27-
* `secondaryColor` is the color seen in the second row of the header navigation bar when the site window is narrow (including on mobile).
28-
* Custom color configurations can also be added. For example, if user styles are added with colors specified as `$myColor`, then adding a `myColor` field to `colors` will allow you to easily configure this color.
28+
- `primaryColor` is the color used the header navigation bar and sidebars.
29+
- `secondaryColor` is the color seen in the second row of the header navigation bar when the site window is narrow (including on mobile).
30+
- Custom color configurations can also be added. For example, if user styles are added with colors specified as `$myColor`, then adding a `myColor` field to `colors` will allow you to easily configure this color.
2931

3032
#### `copyright` [string]
33+
3134
The copyright string at footer of site and within feed
3235

3336
#### `favicon` [string]
37+
3438
URL for site favicon.
3539

3640
#### `headerIcon` [string]
41+
3742
URL for icon used in header navigation bar.
3843

3944
#### `headerLinks` [array]
45+
4046
Links that will be used in the header navigation bar. The `label` field of each object will be the link text and will also be translated for each language.
4147

4248
Example Usage:
@@ -59,45 +65,57 @@ headerLinks: [
5965
```
6066

6167
#### `noIndex` [boolean]
68+
6269
Boolean. If true, Docusaurus will politely ask crawlers and search engines to avoid indexing your site. This is done with a header tag and so only applies to docs and pages. Will not attempt to hide static resources. This is a best effort request. Malicious crawlers can and will still index your site.
6370

6471
#### `organizationName` [string]
72+
6573
GitHub username of the organization or user hosting this project. This is used by the publishing script to determine where your GitHub pages website will be hosted.
6674

6775
#### `projectName` [string]
76+
6877
Project name. This must match your GitHub repository project name (case-sensitive).
6978

7079
#### `tagline` [string]
80+
7181
Tagline for your website.
7282

7383
#### `title` [string]
84+
7485
Title for your website.
7586

7687
#### `url` [string]
88+
7789
URL for your website. This can also be considered the top-level hostname. For example, `https://facebook.github.io` is the url of https://facebook.github.io/metro/, and `https://docusaurus.io` is the url for https://docusaurus.io. This field is related to the [`baseUrl` field](#baseurl-string).
7890

7991
### Optional Fields
8092

8193
#### `algolia` [object]
94+
8295
Information for Algolia search integration. If this field is excluded, the search bar will not appear in the header. You must specify two values for this field, and one (`appId`) is optional.
8396

84-
* `apiKey` - the Algolia provided API key for your search.
85-
* `indexName` - the Algolia provided index name for your search (usually this is the project name)
86-
* `appId` - Algolia provides a default scraper for your docs. If you provide your own, you will probably get this id from them.
97+
- `apiKey` - the Algolia provided API key for your search.
98+
- `indexName` - the Algolia provided index name for your search (usually this is the project name)
99+
- `appId` - Algolia provides a default scraper for your docs. If you provide your own, you will probably get this id from them.
87100

88101
#### `blogSidebarCount` [number]
102+
89103
Control the number of blog posts that show up in the sidebar. See the [adding a blog docs](guides-blog.md#changing-how-many-blog-posts-show-on-sidebar) for more information.
90104

91105
#### `blogSidebarTitle` [string]
106+
92107
Control the title of the blog sidebar. See the [adding a blog docs](guides-blog.md#changing-the-sidebar-title) for more information.
93108

94109
#### `cleanUrl` [string]
110+
95111
If `true`, allow URLs with no `html` extension. For example, a request to URL https://docusaurus.io/docs/installation will returns the same result as https://docusaurus.io/docs/installation.html.
96112

97113
#### `cname` [string]
114+
98115
The CNAME for your website. It will go into a `CNAME` file when your site is built.
99116

100117
#### `customDocsPath` [string]
118+
101119
By default, Docusaurus expects your documentation to be in a directory called `docs`. This directory is at the same level as the `website` directory (i.e., not inside the `website` directory). You can specify a custom path to your documentation with this field.
102120

103121
```js
@@ -109,30 +127,43 @@ customDocsPath: 'website-docs';
109127
```
110128

111129
#### `defaultVersionShown` [string]
130+
112131
The default version for the site to be shown. If this is not set, the latest version will be shown.
113132

114133
#### `disableHeaderTitle` [boolean]
134+
115135
An option to disable showing the title in the header next to the header icon. Exclude this field to keep the header as normal, otherwise set to `true`.
116136

117137
#### `disableTitleTagline` [boolean]
138+
118139
An option to disable showing the tagline in the title of main pages. Exclude this field to keep page titles as `Title • Tagline`. Set to `true` to make page titles just `Title`.
119140

120141
#### `editUrl` [string]
142+
121143
URL for editing docs, usage example: `editUrl + 'en/doc1.md'`. If this field is omitted, there will be no "Edit this Doc" button for each document.
122144

123-
#### `enableUpdateTime` [string]
124-
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: dd/mm/yyyy hh:MM:ss Z`.
145+
#### `enableUpdateBy` [boolean]
146+
147+
An option to enable the docs showing the author who last updated the doc. Set to `true` to show a line at the bottom right corner of each doc page as `Last updated by <Author Name>`.
148+
149+
#### `enableUpdateTime` [boolean]
150+
151+
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 on <date>`.
125152

126153
#### `facebookAppId` [string]
154+
127155
If you want Facebook Like/Share buttons in the footer and at the bottom of your blog posts, provide a [Facebook application id](https://www.facebook.com/help/audiencenetwork/804209223039296).
128156

129157
#### `facebookComments` [boolean]
158+
130159
Set this to `true` if you want to enable Facebook comments at the bottom of your blog post. `facebookAppId` has to be also set.
131160

132161
#### `facebookPixelId` [string]
162+
133163
[Facebook Pixel](https://www.facebook.com/business/a/facebook-pixel) ID to track page views.
134164

135165
#### `fonts` [object]
166+
136167
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.
137168

138169
In the below example, we have two sets of font configurations, `myFont` and `myOtherFont`. `Times New Roman` is the preferred font in `myFont`. `-apple-system` is the preferred in `myOtherFont`.
@@ -159,26 +190,31 @@ h1 {
159190
```
160191

161192
#### `footerIcon` [string]
193+
162194
URL for a footer icon. Currently used in the `core/Footer.js` file provided as an example, but it can be removed from that file.
163195

164196
#### `gaTrackingId` [string]
197+
165198
Google Analytics tracking ID to track page views.
166199

167200
#### `gaGtag` [boolean]
201+
168202
Set this to `true` if you want to use [global site tags (gtag.js)](https://developers.google.com/gtagjs/) for Google analytics instead of `analytics.js`.
169203

170204
#### `githubHost` [string]
205+
171206
Hostname of your server. Useful if you are using GitHub Enterprise.
172207

173208
#### `highlight`
209+
174210
[Syntax highlighting](api-doc-markdown.md) options:
175211

176212
```js
177213
{
178214
// ...
179215
highlight: {
180216
// The name of the theme used by Highlight.js when highlighting code.
181-
// You can find the list of supported themes here:
217+
// You can find the list of supported themes here:
182218
// https://github.com/isagalaev/highlight.js/tree/master/src/styles
183219
theme: 'default',
184220

@@ -190,7 +226,7 @@ Hostname of your server. Useful if you are using GitHub Enterprise.
190226
// do something here
191227
},
192228

193-
// Default language.
229+
// Default language.
194230
// It will be used if one is not specified at the top of the code block. You can find the list of supported languages here:
195231
// https://github.com/isagalaev/highlight.js/tree/master/src/languages
196232

@@ -203,56 +239,73 @@ Hostname of your server. Useful if you are using GitHub Enterprise.
203239
```
204240

205241
#### `manifest` [string]
242+
206243
Path to your web app manifest (e.g., `manifest.json`). This will add a `<link>` tag to `<head>` with `rel` as `"manifest"` and `href` as the provided path.
207244

208245
#### `markdownPlugins` [array]
246+
209247
An array of plugins to be loaded by Remarkable, the markdown parser and renderer used by Docusaurus. The plugin will receive a reference to the Remarkable instance, allowing custom parsing and rendering rules to be defined.
210248

211249
#### `ogImage` [string]
250+
212251
Local path to an Open Graph image (e.g., `img/myImage.png`). This image will show up when your site is shared on Facebook and other websites/apps where the Open Graph protocol is supported.
213252

214253
#### `onPageNav` [string]
254+
215255
If you want a visible navigation option for representing topics on the current page. Currently, there is one accepted value for this option:
216256

217-
* `separate` - The secondary navigation is a separate pane defaulting on the right side of a document. See http://docusaurus.io/docs/en/translation.html for an example.
257+
- `separate` - The secondary navigation is a separate pane defaulting on the right side of a document. See http://docusaurus.io/docs/en/translation.html for an example.
218258

219259
#### `scripts` [array]
260+
220261
Array of JavaScript sources to load. The values can be either strings or plain objects of attribute-value maps. Refer to the example below. The script tag will be inserted in the HTML head.
221262

222263
#### `separateCss` [string]
264+
223265
Directories inside which any `css` files will not be processed and concatenated to Docusaurus' styles. This is to support static `html` pages that may be separate from Docusaurus with completely separate styles.
224266

225267
#### `scrollToTop` [boolean]
268+
226269
Set this to `true` if you want to enable the scroll to top button at the bottom of your site.
227270

228271
#### `scrollToTopOptions` [object]
272+
229273
Optional options configuration for the scroll to top button. You do not need to use this, even if you set `scrollToTop` to `true`; it just provides you more configuration control of the button. You can find more options [here](https://github.com/vfeskov/vanilla-back-to-top/blob/v7.1.14/OPTIONS.md). By default, we set the zIndex option to 100.
230274

231275
#### `stylesheets` [array]
276+
232277
Array of CSS sources to load. The values can be either strings or plain objects of attribute-value maps. The link tag will be inserted in the HTML head.
233278

234279
#### `translationRecruitingLink` [string]
280+
235281
URL for the `Help Translate` tab of language selection when languages besides English are enabled. This can be included you are using translations but does not have to be.
236282

237283
#### `twitter` [boolean]
284+
238285
Set this to `true` if you want a Twitter social button to appear at the bottom of your blog posts.
239286

240287
#### `twitterUsername` [string]
288+
241289
If you want a Twitter follow button at the bottom of your page, provide a Twitter username to follow. For example: `docusaurus`.
242290

243291
#### `twitterImage` [string]
292+
244293
Local path to your Twitter card image (e.g., `img/myImage.png`). This image will show up on the Twitter card when your site is shared on Twitter.
245294

246295
#### `useEnglishUrl` [string]
296+
247297
If you do not have [translations](guides-translation.md) enabled (e.g., by having a `languages.js` file), but still want a link of the form `/docs/en/doc.html` (with the `en`), set this to `true`.
248298

249299
#### `users` [array]
300+
250301
The `users` array mentioned earlier.
251302

252303
#### `usePrism` [array]
304+
253305
Array of languages to use Prism syntax highlighter. Refer to [Using Prism as additional syntax highlighter](api-doc-markdown.md#using-prism-as-additional-syntax-highlighter). Set it to `true` to use Prism on all languages.
254306

255307
#### `wrapPagesHTML` [boolean]
308+
256309
Boolean flag to indicate whether `html` files in `/pages` should be wrapped with Docusaurus site styles, header and footer. This feature is experimental and relies on the files being `html` fragments instead of complete pages. It inserts the contents of your `html` file with no extra processing. Defaults to `false`.
257310

258311
Users can also add their own custom fields if they wish to provide some data across different files.
@@ -317,7 +370,7 @@ const siteConfig = {
317370
idx,
318371
options,
319372
env,
320-
instance
373+
instance,
321374
) {
322375
return '<div class="foo">bar</div>';
323376
};
@@ -326,16 +379,17 @@ const siteConfig = {
326379
scripts: [
327380
'https://docusaurus.io/slash.js',
328381
{
329-
src: 'https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.0/clipboard.min.js',
330-
async: true
331-
}
382+
src:
383+
'https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.0/clipboard.min.js',
384+
async: true,
385+
},
332386
],
333387
stylesheets: [
334388
'https://docusaurus.io/style.css',
335389
{
336390
href: 'http://css.link',
337-
type: "text/css"
338-
}
391+
type: 'text/css',
392+
},
339393
],
340394
facebookAppId: '1615782811974223',
341395
facebookComments: true,
@@ -352,4 +406,4 @@ const siteConfig = {
352406
};
353407

354408
module.exports = siteConfig;
355-
```
409+
```

v1/examples/basics/siteConfig.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@ const siteConfig = {
9292
ogImage: 'img/docusaurus.png',
9393
twitterImage: 'img/docusaurus.png',
9494

95+
// Show documentation's last contributor's name.
96+
// enableUpdateBy: true,
97+
98+
// Show documentation's last update time.
99+
// enableUpdateTime: true,
100+
95101
// You may provide arbitrary config keys to be used as needed by your
96102
// template. For example, if you need your repo's URL...
97103
// repoUrl: 'https://github.com/facebook/test-site',

v1/lib/core/DocsLayout.js

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const OnPageNav = require('./nav/OnPageNav.js');
1717
const Site = require('./Site.js');
1818
const translation = require('../server/translation.js');
1919
const docs = require('../server/docs.js');
20-
const {idx, getGitLastUpdated} = require('./utils.js');
20+
const {idx, getGitLastUpdatedTime, getGitLastUpdatedBy} = require('./utils.js');
2121

2222
// component used to generate whole webpage for docs, including sidebar/header/footer
2323
class DocsLayout extends React.Component {
@@ -45,16 +45,19 @@ class DocsLayout extends React.Component {
4545
if (this.props.Doc) {
4646
DocComponent = this.props.Doc;
4747
}
48+
const filepath = docs.getFilePath(metadata);
4849

49-
let updateTime;
50-
if (this.props.config.enableUpdateTime) {
51-
const filepath = docs.getFilePath(metadata);
52-
updateTime = getGitLastUpdated(filepath);
53-
}
50+
const updateTime = this.props.config.enableUpdateTime
51+
? getGitLastUpdatedTime(filepath)
52+
: null;
53+
const updateAuthor = this.props.config.enableUpdateBy
54+
? getGitLastUpdatedBy(filepath)
55+
: null;
5456

5557
const title =
5658
idx(i18n, ['localized-strings', 'docs', id, 'title']) || defaultTitle;
5759
const hasOnPageNav = this.props.config.onPageNav === 'separate';
60+
5861
const previousTitle =
5962
idx(i18n, ['localized-strings', metadata.previous_id]) ||
6063
idx(i18n, ['localized-strings', 'previous']) ||
@@ -90,15 +93,16 @@ class DocsLayout extends React.Component {
9093
version={metadata.version}
9194
language={metadata.language}
9295
/>
93-
{this.props.config.enableUpdateTime &&
94-
updateTime && (
95-
<div className="docLastUpdateTimestamp">
96-
<em>
97-
<strong>Last updated: </strong>
98-
{updateTime}
99-
</em>
100-
</div>
101-
)}
96+
{(updateTime || updateAuthor) && (
97+
<div className="docLastUpdate">
98+
<em>
99+
Last updated
100+
{updateTime && ` on ${updateTime}`}
101+
{updateAuthor && ` by ${updateAuthor}`}
102+
</em>
103+
</div>
104+
)}
105+
102106
<div className="docs-prevnext">
103107
{metadata.previous_id && (
104108
<a

0 commit comments

Comments
 (0)