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 e9dbe7b
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 6 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
25 changes: 19 additions & 6 deletions lib/core/DocsLayout.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,23 @@ 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 @@ -52,9 +69,7 @@ class DocsLayout extends React.Component {
/>
<div className="docs-prevnext">
{metadata.previous_id && (
<a
className="docs-prev button"
href={metadata.previous_id + '.html'}>
<a className="docs-prev button" href={prevLink}>
{' '}
{i18n
? translation[this.props.metadata.language][
Expand All @@ -68,9 +83,7 @@ class DocsLayout extends React.Component {
</a>
)}
{metadata.next_id && (
<a
className="docs-next button"
href={metadata.next_id + '.html'}>
<a className="docs-next button" 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 e9dbe7b

Please sign in to comment.