From 324b1079e7eb29829bf06ff65299acdc58abf308 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Mon, 9 Jul 2018 19:05:38 +0200 Subject: Add ability to nest doc ref markdown under specific versions --- packages/react-docs/CHANGELOG.json | 8 ++++++++ packages/react-docs/package.json | 3 ++- packages/react-docs/src/components/documentation.tsx | 10 +++++++++- packages/react-docs/src/docs_info.ts | 4 ++-- packages/react-docs/src/types.ts | 6 +++++- 5 files changed, 26 insertions(+), 5 deletions(-) (limited to 'packages/react-docs') diff --git a/packages/react-docs/CHANGELOG.json b/packages/react-docs/CHANGELOG.json index 30e48197d..b36ac9e4f 100644 --- a/packages/react-docs/CHANGELOG.json +++ b/packages/react-docs/CHANGELOG.json @@ -1,4 +1,12 @@ [ + { + "version": "0.0.15", + "changes": [ + { + "note": "Nest MD files under versions so that you can update them for future versions" + } + ] + }, { "timestamp": 1529397769, "version": "0.0.14", diff --git a/packages/react-docs/package.json b/packages/react-docs/package.json index 8c70f4f6d..1a7c016ed 100644 --- a/packages/react-docs/package.json +++ b/packages/react-docs/package.json @@ -52,7 +52,8 @@ "react-dom": "15.6.1", "react-markdown": "^3.2.2", "react-scroll": "^1.5.2", - "react-tooltip": "^3.2.7" + "react-tooltip": "^3.2.7", + "semver": "5.5.0" }, "publishConfig": { "access": "public" diff --git a/packages/react-docs/src/components/documentation.tsx b/packages/react-docs/src/components/documentation.tsx index a4e6f4f6e..7030001e8 100644 --- a/packages/react-docs/src/components/documentation.tsx +++ b/packages/react-docs/src/components/documentation.tsx @@ -12,6 +12,7 @@ import { import * as _ from 'lodash'; import CircularProgress from 'material-ui/CircularProgress'; import * as React from 'react'; +import * as semver from 'semver'; import { DocsInfo } from '../docs_info'; import { @@ -180,7 +181,14 @@ export class Documentation extends React.Component { + return semver.lte(mdVersion, this.props.selectedVersion); + }); + const sortedEligibleVersions = eligibleVersions.sort(semver.rcompare.bind(semver)); + const closestVersion = sortedEligibleVersions[0]; + const markdownFileIfExists = this.props.docsInfo.sectionNameToMarkdownByVersion[closestVersion][sectionName]; if (!_.isUndefined(markdownFileIfExists)) { return ( Date: Mon, 9 Jul 2018 19:53:54 +0200 Subject: Remove comment and add assertion --- packages/react-docs/src/components/documentation.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'packages/react-docs') diff --git a/packages/react-docs/src/components/documentation.tsx b/packages/react-docs/src/components/documentation.tsx index 7030001e8..ff33220d2 100644 --- a/packages/react-docs/src/components/documentation.tsx +++ b/packages/react-docs/src/components/documentation.tsx @@ -182,10 +182,16 @@ export class Documentation extends React.Component { return semver.lte(mdVersion, this.props.selectedVersion); }); + if (_.isEmpty(eligibleVersions)) { + throw new Error( + `No eligible markdown sections found for ${this.props.docsInfo.displayName} version ${ + this.props.selectedVersion + }.`, + ); + } const sortedEligibleVersions = eligibleVersions.sort(semver.rcompare.bind(semver)); const closestVersion = sortedEligibleVersions[0]; const markdownFileIfExists = this.props.docsInfo.sectionNameToMarkdownByVersion[closestVersion][sectionName]; -- cgit v1.2.3 From 1aaf633df883f62fad890b2d87a2dc89067821c5 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Mon, 9 Jul 2018 19:59:26 +0200 Subject: Add missing import --- packages/react-docs/src/docs_info.ts | 1 + 1 file changed, 1 insertion(+) (limited to 'packages/react-docs') diff --git a/packages/react-docs/src/docs_info.ts b/packages/react-docs/src/docs_info.ts index e9f3c13fe..810674d51 100644 --- a/packages/react-docs/src/docs_info.ts +++ b/packages/react-docs/src/docs_info.ts @@ -9,6 +9,7 @@ import { DocsInfoTypeConfigs, DocsMenu, DoxityDocObj, + SectionNameToMarkdownByVersion, SectionsMap, SupportedDocJson, TypeDefinitionByName, -- cgit v1.2.3