Make prev links work in guides and APIs.

Summary:
We had rendering support for prev links, but we never had any previous links in our metadata. Only next links. This adds that support to both Guides and APIs.

**For guides**: `previous` is manually inserted into the metadata of the actual markdown file.
**For APIs/Components**: `previous` is established via code within `extractDocs.js`

> This isn't totally perfect. For example, the transition from the last guide to the first API/component has a next link from the guide, but not a previous link from the API since the way you get the previous links are different from guides and APIs. But this gets us really close.
Closes https://github.com/facebook/react-native/pull/8754

Differential Revision: D3557972

Pulled By: hramos

fbshipit-source-id: e270bb51e7a4f59f61dad28ae0928d27d0af3d4a
This commit is contained in:
Joel Marcey
2016-07-13 14:45:53 -07:00
committed by Facebook Github Bot 1
parent 8612d7640d
commit b1e49832ef
41 changed files with 57 additions and 2 deletions

View File

@@ -165,6 +165,19 @@ function getNextComponent(idx) {
return null;
}
function getPreviousComponent(idx) {
if (all[idx - 1]) {
const previousComponentName = getNameFromPath(all[idx - 1]);
if (shouldDisplayInSidebar(previousComponentName)) {
return slugify(previousComponentName);
} else {
return getPreviousComponent(idx - 1);
}
}
return null;
}
function componentsToMarkdown(type, json, filepath, idx, styles) {
const componentName = getNameFromPath(filepath);
const componentPlatform = getPlatformFromPath(filepath);
@@ -189,6 +202,7 @@ function componentsToMarkdown(type, json, filepath, idx, styles) {
// Put styles (e.g. Flexbox) into the API category
const category = (type === 'style' ? 'apis' : type + 's');
const next = getNextComponent(idx);
const previous = getPreviousComponent(idx);
const res = [
'---',
@@ -199,6 +213,7 @@ function componentsToMarkdown(type, json, filepath, idx, styles) {
'permalink: docs/' + slugify(componentName) + '.html',
'platform: ' + componentPlatform,
'next: ' + next,
'previous: ' + previous,
'sidebar: ' + shouldDisplayInSidebar(componentName),
'runnable:' + isRunnable(componentName, componentPlatform),
'path:' + json.filepath,