Skip to content

Commit

Permalink
fix all anchor links in docs
Browse files Browse the repository at this point in the history
Summary: Closes facebook#6213

Differential Revision: D2989119

Pulled By: vjeux

fb-gh-sync-id: 3a069dcebbf8dec40702a7bab5268ce4a82db731
shipit-source-id: 3a069dcebbf8dec40702a7bab5268ce4a82db731
  • Loading branch information
skv-headless authored and Facebook Github Bot 5 committed Feb 29, 2016
1 parent fcd468d commit 5a53d90
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 5 deletions.
7 changes: 4 additions & 3 deletions website/core/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,19 @@ var React = require('React');
var slugify = require('slugify');

var Header = React.createClass({
getDefaultProps: function() {
return {permalink: ''};
contextTypes: {
permalink: React.PropTypes.string
},

render: function() {
var slug = slugify(this.props.toSlug || this.props.children);
var H = 'h' + this.props.level;
var base = this.context.permalink || '';
return (
<H {...this.props}>
<a className="anchor" name={slug}></a>
{this.props.children}
{' '}<a className="hash-link" href={this.props.permalink + '#' + slug}>#</a>
{' '}<a className="hash-link" href={base + '#' + slug}>#</a>
</H>
);
}
Expand Down
12 changes: 10 additions & 2 deletions website/layout/AutodocsLayout.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ var ComponentDoc = React.createClass({
renderProp: function(name, prop) {
return (
<div className="prop" key={name}>
<Header level={4} className="propTitle" toSlug={name} permalink={this.props.permalink}>
<Header level={4} className="propTitle" toSlug={name}>
{prop.platforms && prop.platforms.map(platform =>
<span className="platform">{platform}</span>
)}
Expand Down Expand Up @@ -448,6 +448,14 @@ var Modal = React.createClass({
});

var Autodocs = React.createClass({
childContextTypes: {
permalink: React.PropTypes.string
},

getChildContext: function() {
return {permalink: this.props.metadata.permalink};
},

renderFullDescription: function(docs) {
if (!docs.fullDescription) {
return;
Expand Down Expand Up @@ -488,7 +496,7 @@ var Autodocs = React.createClass({
var metadata = this.props.metadata;
var docs = JSON.parse(this.props.children);
var content = docs.type === 'component' || docs.type === 'style' ?
<ComponentDoc content={docs} permalink={metadata.permalink}/> :
<ComponentDoc content={docs} /> :
<APIDoc content={docs} apiName={metadata.title} />;

return (
Expand Down
8 changes: 8 additions & 0 deletions website/layout/DocsLayout.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ var React = require('React');
var Site = require('Site');

var DocsLayout = React.createClass({
childContextTypes: {
permalink: React.PropTypes.string
},

getChildContext: function() {
return {permalink: this.props.metadata.permalink};
},

render: function() {
var metadata = this.props.metadata;
var content = this.props.children;
Expand Down
8 changes: 8 additions & 0 deletions website/layout/PageLayout.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ var Site = require('Site');
var Marked = require('Marked');

var support = React.createClass({
childContextTypes: {
permalink: React.PropTypes.string
},

getChildContext: function() {
return {permalink: this.props.metadata.permalink};
},

render: function() {
var metadata = this.props.metadata;
var content = this.props.children;
Expand Down
7 changes: 7 additions & 0 deletions website/src/react-native/support.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ var center = require('center');
var H2 = require('H2');

var support = React.createClass({
childContextTypes: {
permalink: React.PropTypes.string
},

getChildContext: function() {
return {permalink: 'support.html'};
},
render: function() {
return (
<Site section="support" title="Support">
Expand Down

0 comments on commit 5a53d90

Please sign in to comment.