Skip to content

Commit

Permalink
implement relative path builder in docslayout next/prev
Browse files Browse the repository at this point in the history
  • Loading branch information
endiliey committed May 31, 2018
1 parent 80e5bc9 commit 8620324
Showing 1 changed file with 15 additions and 19 deletions.
34 changes: 15 additions & 19 deletions lib/core/DocsLayout.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const DocsSidebar = require('./DocsSidebar.js');
const OnPageNav = require('./nav/OnPageNav.js');
const Site = require('./Site.js');
const translation = require('../server/translation.js');
const path = require('path');

// component used to generate whole webpage for docs, including sidebar/header/footer
class DocsLayout extends React.Component {
Expand All @@ -28,23 +29,6 @@ class DocsLayout extends React.Component {
this.props.metadata.localized_id
] || this.props.metadata.title
: this.props.metadata.title;
const prevDir =
metadata.previous_id && metadata.previous_id.includes('/')
? metadata.previous_id.split('/')[0]
: '.';
const curDir = metadata.id.includes('/') ? metadata.id.split('/')[0] : '.';
const nextDir =
metadata.next_id && metadata.next_id.includes('/')
? metadata.next_id.split('/')[0]
: '.';
let prevLink = metadata.previous_id + '.html';
if (prevDir !== curDir && curDir != '.') {
prevLink = '../' + prevLink;
}
let nextLink = metadata.next_id + '.html';
if (nextDir !== curDir && curDir != '.') {
nextLink = '../' + nextLink;
}
return (
<Site
config={this.props.config}
Expand All @@ -69,7 +53,13 @@ class DocsLayout extends React.Component {
/>
<div className="docs-prevnext">
{metadata.previous_id && (
<a className="docs-prev button" href={prevLink}>
<a
className="docs-prev button"
href={
path
.relative(metadata.localized_id, metadata.previous_id)
.replace(/^\.\.\//, '') + '.html'
}>
{' '}
{i18n
? translation[this.props.metadata.language][
Expand All @@ -83,7 +73,13 @@ class DocsLayout extends React.Component {
</a>
)}
{metadata.next_id && (
<a className="docs-next button" href={nextLink}>
<a
className="docs-next button"
href={
path
.relative(metadata.localized_id, metadata.next_id)
.replace(/^\.\.\//, '') + '.html'
}>
{i18n
? translation[this.props.metadata.language][
'localized-strings'
Expand Down

0 comments on commit 8620324

Please sign in to comment.