react-native/website/core/DocsSidebar.js
Konstantin Raev 6f1417c849 CI now builds docs website and deploys it to /%version% path
Summary:
Copy of #5760 reverted merge.

We need to preserve history of docs changes on the webserver.
The goal is to allow users to browse outdated versions of docs.
To make things simple all websites will be released to https://facebook.github.io/react-native/releases/version/XX folder when there is a branch cut.

I switched from Travis CI to Cirle CI because it works faster and I am more familiar with it.

How it works:

1. If code is pushed to `master` branch then CI will build a fresh version of docs and put it in https://github.com/facebook/react-native/tree/gh-pages/releases/next folder.
Github will serve this website from https://facebook.github.io/react-native/releases/version/next URL.
All relative URLs will work within that website

2. If code is pushed to `0.20-stable` branch then CI will build a fresh version of docs and put it in https://github.com/facebook/react-native/tree/gh-pages/releases/0.20 folder.
Github will serve this website from https://facebook.github.io/react-native/releases/v
Closes https://github.com/facebook/react-native/pull/5873

Reviewed By: svcscm

Differential Revision: D2926901

Pulled By: androidtrunkagent

fb-gh-sync-id: 16aea430bac815933d9c603f03921cc6353906f1
shipit-source-id: 16aea430bac815933d9c603f03921cc6353906f1
2016-02-11 06:17:42 -08:00

103 lines
2.9 KiB
JavaScript

/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule DocsSidebar
*/
var React = require('React');
var Metadata = require('Metadata');
var DocsSidebar = React.createClass({
getCategories: function() {
var metadatas = Metadata.files.filter(function(metadata) {
return metadata.layout === 'docs' || metadata.layout === 'autodocs';
});
// Build a hashmap of article_id -> metadata
var articles = {};
for (var i = 0; i < metadatas.length; ++i) {
var metadata = metadatas[i];
articles[metadata.id] = metadata;
}
// Build a hashmap of article_id -> previous_id
var previous = {};
for (var i = 0; i < metadatas.length; ++i) {
var metadata = metadatas[i];
if (metadata.next) {
if (!articles[metadata.next]) {
throw '`next: ' + metadata.next + '` in ' + metadata.id + ' doesn\'t exist';
}
previous[articles[metadata.next].id] = metadata.id;
}
}
// Find the first element which doesn't have any previous
var first = null;
for (var i = 0; i < metadatas.length; ++i) {
var metadata = metadatas[i];
if (!previous[metadata.id]) {
first = metadata;
break;
}
}
var categories = [];
var currentCategory = null;
var metadata = first;
var i = 0;
while (metadata && i++ < 1000) {
if (!currentCategory || metadata.category !== currentCategory.name) {
currentCategory && categories.push(currentCategory);
currentCategory = {
name: metadata.category,
links: []
};
}
currentCategory.links.push(metadata);
metadata = articles[metadata.next];
}
categories.push(currentCategory);
return categories;
},
getLink: function(metadata) {
if (metadata.permalink.match(/^https?:/)) {
return metadata.permalink;
}
return metadata.permalink + '#content';
},
render: function() {
return <div className="nav-docs">
{this.getCategories().map((category) =>
<div className="nav-docs-section" key={category.name}>
<h3>{category.name}</h3>
<ul>
{category.links.map((metadata) =>
<li key={metadata.id}>
<a
target={metadata.permalink.match(/^https?:/) && '_blank'}
style={{marginLeft: metadata.indent ? 20 : 0}}
className={metadata.id === this.props.metadata.id ? 'active' : ''}
href={this.getLink(metadata)}>
{metadata.title}
</a>
</li>
)}
</ul>
</div>
)}
</div>;
}
});
module.exports = DocsSidebar;