Skip to content

Commit 6c12662

Browse files
committed
Tree file layout in LinkerPlugin + fix #60
1 parent 1f52753 commit 6c12662

File tree

7 files changed

+24
-11
lines changed

7 files changed

+24
-11
lines changed

packages/webdoc-default-template/helper/crawl/crawl-reference-explorer.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function crawlReference(doc /*: Doc */) {
4242
exports.crawlReference = crawlReference;
4343

4444
function getPage(doc /*: Doc */) {
45-
return linker.getURI(doc);
45+
return "/" + linker.getURI(doc);
4646
}
4747

4848
/*::
@@ -161,7 +161,7 @@ function buildExplorerTargetsTree(
161161
parentTitle /*: string */ = "",
162162
) /*: ExplorerTarget */ {
163163
const doc = node.doc;
164-
const page = doc.type !== "RootDoc" ? getPage(doc) : "index.html";
164+
const page = doc.type !== "RootDoc" ? getPage(doc) : "/index.html";
165165

166166
let title = "";
167167

@@ -187,11 +187,11 @@ function buildExplorerTargetsTree(
187187
};
188188

189189
if (node.doc.type === "RootDoc") {
190-
node.children["(overview)"].page = "index.html";
190+
node.children["(overview)"].page = "/index.html";
191191

192192
node.children.ClassIndex = {
193193
title: "Class Index",
194-
page: linker.createURI("Class-Index.html"),
194+
page: "/" + linker.createURI("Class-Index"),
195195
};
196196
}
197197

packages/webdoc-default-template/src/app/components/Explorer/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default function Explorer(props) {
1212
const children = [];
1313

1414
if (!fetched) {
15-
fetch("explorer/reference.json")
15+
fetch("/explorer/reference.json")
1616
.then((response) => {
1717
if (response.ok) {
1818
response.json().then((idata) => {

packages/webdoc-default-template/static/scripts/default-template.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4970,7 +4970,7 @@ function Explorer(props) {
49704970
var children = [];
49714971

49724972
if (!fetched) {
4973-
fetch("explorer/reference.json").then(function (response) {
4973+
fetch("/explorer/reference.json").then(function (response) {
49744974
if (response.ok) {
49754975
response.json().then(function (idata) {
49764976
setData(idata || {});

packages/webdoc-default-template/tmpl/layout.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ const rootData = obj
1010
<meta charset="utf-8" />
1111
<title>webdoc: <?js= title ?></title>
1212

13-
<link type="text/css" rel="stylesheet" href="styles/index.css" />
13+
<link type="text/css" rel="stylesheet" href="/styles/index.css" />
1414
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap" />
1515
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto+Mono:300,400,500,700&display=swap" />
1616
<link type="text/css" rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/10.0.3/styles/googlecode.min.css">
1717

1818
<script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script>
1919
<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
20-
<script src="scripts/default-template.js"></script>
20+
<script src="/scripts/default-template.js"></script>
2121
</head>
2222
<body class="root">
2323
<div class="docs">

packages/webdoc-template-library/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@
4747
"lodash": "^4.17.15",
4848
"missionlog": "1.6.0",
4949
"nanoid": "~3.1.16",
50-
"parse-github-url": "1.0.2"
50+
"parse-github-url": "1.0.2",
51+
"fs-extra": "^9.0.1"
5152
},
5253
"devDependencies": {
5354
"@babel/core": "^7.9.0",

packages/webdoc-template-library/src/pipeline-elements/FlushToFile.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// @flow
22

3+
import * as fse from "fs-extra";
34
import type {TemplatePipelineElement} from "../TemplatePipeline";
4-
import fs from "fs";
55

66
type FlushData = {
77
outputFile: string;
@@ -40,7 +40,7 @@ export class FlushToFile implements TemplatePipelineElement<FlushData> {
4040
throw new Error("No outputFile specified in pipeline-data");
4141
}
4242

43-
fs.writeFile(pipelineData.outputFile, input, (err) => {
43+
fse.outputFile(pipelineData.outputFile, input, (err) => {
4444
if (err) throw err;
4545
});
4646

packages/webdoc-template-library/src/template-plugins/LinkerPlugin.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ export type LinkerFileRecord = {
2121
uri?: string,
2222
};
2323

24+
export type FileLayout = "linear" | "tree";
25+
2426
/**
2527
* Shell wrapper around {@link LinkerPlugin}.
2628
*
@@ -100,6 +102,12 @@ function LinkerPluginShell() {
100102
*/
101103
documentRegistry = new Map<string, LinkerDocumentRecord>();
102104

105+
/**
106+
* The mode with which the path for output files is choosen.
107+
* @protected
108+
*/
109+
fileLayout = "tree";
110+
103111
/**
104112
* This holds all the linker's data on each output file, mapping each URI lowercased.
105113
* @protected
@@ -373,6 +381,10 @@ function LinkerPluginShell() {
373381
// make sure we don't create hidden files, or files whose names start with a dash
374382
.replace(/^[.-]/, "");
375383

384+
if (this.fileLayout === "tree") {
385+
seedURI = seedURI.replace(/[.]/g, "/");
386+
}
387+
376388
// in case we've now stripped the entire basename (uncommon, but possible):
377389
seedURI = seedURI.length ? seedURI : "_";
378390
seedURI += ".html";

0 commit comments

Comments
 (0)