Skip to content

Commit

Permalink
enable subdirectory for docs
Browse files Browse the repository at this point in the history
  • Loading branch information
endiliey committed May 26, 2018
1 parent b7be858 commit 06fe96e
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
6 changes: 6 additions & 0 deletions docs/test/feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
id: feature
title: Sub-directory Test
---

Testing subdirectory
18 changes: 16 additions & 2 deletions lib/core/DocsLayout.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,20 @@ 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 @@ -54,7 +68,7 @@ class DocsLayout extends React.Component {
{metadata.previous_id && (
<a
className="docs-prev button"
href={metadata.previous_id + '.html'}>
href={prevLink}>
{' '}
{i18n
? translation[this.props.metadata.language][
Expand All @@ -70,7 +84,7 @@ class DocsLayout extends React.Component {
{metadata.next_id && (
<a
className="docs-next button"
href={metadata.next_id + '.html'}>
href={nextLink}>
{i18n
? translation[this.props.metadata.language][
'localized-strings'
Expand Down
9 changes: 9 additions & 0 deletions lib/server/readMetadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,15 @@ function processMetadata(file) {
if (metadata.id.includes('/')) {
throw new Error('Document id cannot include "/".');
}

// if file is located in subdirectory,
// it will have the directory name appended to it's id
const curDir = path.dirname(file.split(getDocsPath() + '/')[1]);
if (curDir !== '.') {
metadata.id = curDir + '/' + metadata.id;
metadata.source = curDir + '/' + metadata.source;
}

if (!metadata.title) {
metadata.title = metadata.id;
}
Expand Down
3 changes: 3 additions & 0 deletions website/sidebars.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
"doc-markdown",
"api-pages",
"site-config"
],
"Test": [
"test/feature"
]
}
}

0 comments on commit 06fe96e

Please sign in to comment.