Skip to content

Commit

Permalink
re-implement to support nested subdirectories
Browse files Browse the repository at this point in the history
  • Loading branch information
endiliey committed May 31, 2018
1 parent bf8e43d commit 80e5bc9
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 11 deletions.
10 changes: 10 additions & 0 deletions docs/projectA/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
id: readme
title: README
---

## Docs
Welcome to Project A, here are some available docs

1. [Architecture](projectA/docs/architecture.md)
2. [Contributors](projectA/docs/contributors.md)
8 changes: 8 additions & 0 deletions docs/projectA/docs/architecture.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
id: architecture
title: Architecture
---

## Lorem ipsum

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
8 changes: 8 additions & 0 deletions docs/projectA/docs/contributors.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
id: contributors
title: Contributors
---

![Introducing Slash](/img/slash-introducing.png)

But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure
15 changes: 15 additions & 0 deletions docs/projectB/guides/install.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
id: install
title: Install
---

Project B was designed from the ground up to be easily installed and used to get your website up and running quickly.

### Launching the server behind a proxy

If you are behind a corporate proxy, you need to disable it for the development server requests. It can be done using the `NO_PROXY` environment variable.

```sh
SET NO_PROXY=localhost
yarn start (or npm run start)
```
6 changes: 0 additions & 6 deletions docs/test/feature.md

This file was deleted.

19 changes: 17 additions & 2 deletions lib/server/readMetadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,18 @@ function processMetadata(file) {
);

const match = regexSubFolder.exec(file);
let language = match ? match[1] : 'en';
let language = 'en';

// Avoid misinterpreting subdirectory as language
if (match && env.translation.enabled) {
const enabledLanguages = env.translation
.enabledLanguages()
.map(language => language.tag);

if (enabledLanguages.indexOf(match[1]) !== -1) {
language = match[1];
}
}

const metadata = {};
for (const fieldName of Object.keys(result.metadata)) {
Expand All @@ -153,7 +164,11 @@ function processMetadata(file) {

// 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]);
const relativeFile = path.relative(
path.join(CWD, '../', getDocsPath()),
file
);
const curDir = path.dirname(relativeFile);
if (curDir !== '.') {
metadata.id = curDir + '/' + metadata.id;
metadata.source = curDir + '/' + metadata.source;
Expand Down
2 changes: 1 addition & 1 deletion lib/server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ function execute(port) {
// handle all requests for document pages
const app = express();

app.get(/docs\/.*html$/, (req, res, next) => {
app.get(/^\/docs\/.*html$/, (req, res, next) => {
let url = req.path.toString().replace(siteConfig.baseUrl, '');

// links is a map from a permalink to an id for each document
Expand Down
9 changes: 7 additions & 2 deletions website/sidebars.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,13 @@
"api-pages",
"site-config"
],
"Test": [
"test/feature"
"Project A": [
"projectA/readme",
"projectA/docs/architecture",
"projectA/docs/contributors"
],
"Project B": [
"projectB/guides/install"
]
}
}

0 comments on commit 80e5bc9

Please sign in to comment.