From 1a572757f1118802fb7cd2dbc698b9ef2affb2f8 Mon Sep 17 00:00:00 2001 From: Shubham Bansal Date: Wed, 29 Aug 2018 18:45:18 +0530 Subject: [PATCH] feat: last updated time in docs (#913) * Adding last updated time for docs * Making file path general and other suggested changes * Checking if time returned is null due to absence of git or some other issue * Adding option to enable/disable update time feature and test-doc * Adding simple unit tests for getGitUpdateTime() * nits & rewrote failing test * consistent test naming * Adding optional updateEnableTime in documentation * package-lock & yarn.lock --- docs/api-site-config.md | 2 + lib/core/DocsLayout.js | 16 ++++- lib/core/__tests__/__fixtures__/test.md | 5 ++ lib/core/__tests__/utils.test.js | 25 +++++++ lib/core/utils.js | 13 ++++ lib/server/docs.js | 11 ++- package-lock.json | 94 ++++++++++++++++++++++--- package.json | 1 + website/siteConfig.js | 1 + yarn.lock | 16 ++++- 10 files changed, 170 insertions(+), 14 deletions(-) create mode 100644 lib/core/__tests__/__fixtures__/test.md diff --git a/docs/api-site-config.md b/docs/api-site-config.md index 2164c0f526..17ede83f20 100644 --- a/docs/api-site-config.md +++ b/docs/api-site-config.md @@ -98,6 +98,8 @@ customDocsPath: 'website-docs'; `editUrl` - 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. +`enableUpdateTime` - 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`. + `facebookAppId` - 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). `facebookComments` - Set this to `true` if you want to enable Facebook comments at the bottom of your blog post. `facebookAppId` has to be also set. diff --git a/lib/core/DocsLayout.js b/lib/core/DocsLayout.js index 0f28006f16..d859e6b353 100644 --- a/lib/core/DocsLayout.js +++ b/lib/core/DocsLayout.js @@ -16,7 +16,8 @@ const DocsSidebar = require('./DocsSidebar.js'); const OnPageNav = require('./nav/OnPageNav.js'); const Site = require('./Site.js'); const translation = require('../server/translation.js'); -const {idx} = require('./utils.js'); +const docs = require('../server/docs.js'); +const {idx, getGitLastUpdated} = require('./utils.js'); // component used to generate whole webpage for docs, including sidebar/header/footer class DocsLayout extends React.Component { @@ -43,6 +44,12 @@ class DocsLayout extends React.Component { if (this.props.Doc) { DocComponent = this.props.Doc; } + let updateTime; + if (this.props.config.enableUpdateTime) { + const filepath = docs.getFilePath(metadata); + updateTime = getGitLastUpdated(filepath); + } + const title = idx(i18n, ['localized-strings', 'docs', id, 'title']) || defaultTitle; const hasOnPageNav = this.props.config.onPageNav === 'separate'; @@ -100,6 +107,13 @@ class DocsLayout extends React.Component { )} + {this.props.config.enableUpdateTime && + updateTime && ( +

+ Last updated: + {updateTime} +

+ )} {hasOnPageNav && (