Add sidebar support to documentation generator
This commit is contained in:
@@ -23,6 +23,8 @@ class RunScript {
|
|||||||
private static var isMac:Bool;
|
private static var isMac:Bool;
|
||||||
private static var isWindows:Bool;
|
private static var isWindows:Bool;
|
||||||
private static var limeDirectory:String;
|
private static var limeDirectory:String;
|
||||||
|
private static var wikiLinks:EReg = ~/\[\[(.+)\]\]/g;
|
||||||
|
|
||||||
//private static var nmeFilters:Array <String> = [ "obj", ".git", ".gitignore", ".svn", ".DS_Store", "all_objs", "Export", "tools", "project" ];
|
//private static var nmeFilters:Array <String> = [ "obj", ".git", ".gitignore", ".svn", ".DS_Store", "all_objs", "Export", "tools", "project" ];
|
||||||
|
|
||||||
|
|
||||||
@@ -626,9 +628,9 @@ class RunScript {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var links = ~/\[\[(.+)\]\]/g;
|
for (i in 0...targetPaths.length) {
|
||||||
|
|
||||||
for (i in 0...sourcePaths.length) {
|
if (names[i] == "_sidebar") continue;
|
||||||
|
|
||||||
var sourcePath = sourcePaths[i];
|
var sourcePath = sourcePaths[i];
|
||||||
var targetPath = targetPaths[i];
|
var targetPath = targetPaths[i];
|
||||||
@@ -639,60 +641,39 @@ class RunScript {
|
|||||||
PathHelper.mkdir (Path.directory (outputPath));
|
PathHelper.mkdir (Path.directory (outputPath));
|
||||||
|
|
||||||
var content = File.getContent (sourcePath);
|
var content = File.getContent (sourcePath);
|
||||||
|
content = replaceWikiLinks (content, names, targetPaths);
|
||||||
while (links.match (content)) {
|
|
||||||
|
|
||||||
var link = links.matched (0);
|
|
||||||
link = link.substr (2, link.length - 4);
|
|
||||||
var components = link.split ("|");
|
|
||||||
|
|
||||||
var title = "";
|
|
||||||
var target = "";
|
|
||||||
|
|
||||||
if (components.length > 1) {
|
|
||||||
|
|
||||||
title = components[0];
|
|
||||||
target = components[1];
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
title = target = components[0];
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if (StringTools.endsWith (target, ".md")) {
|
|
||||||
|
|
||||||
target = target.substr (0, target.length - 3);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
var replacement = "[" + title + "](/documentation/)";
|
|
||||||
|
|
||||||
for (i in 0...names.length) {
|
|
||||||
|
|
||||||
if (target == names[i]) {
|
|
||||||
|
|
||||||
var path = targetPaths[i];
|
|
||||||
path = path.substr (0, path.lastIndexOf ("/"));
|
|
||||||
|
|
||||||
replacement = "[" + title + "](/documentation/" + path + ")";
|
|
||||||
break;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
content = links.matchedLeft () + replacement + links.matchedRight ();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
var output = File.write (outputPath, false);
|
var output = File.write (outputPath, false);
|
||||||
output.writeString ("---\n");
|
output.writeString ("---\n");
|
||||||
output.writeString ("layout: default\n");
|
output.writeString ("layout: documentation\n");
|
||||||
output.writeString ("title: " + title + "\n");
|
output.writeString ("title: " + title + "\n");
|
||||||
output.writeString ("---\n\n");
|
output.writeString ("---\n\n");
|
||||||
output.writeString ("# " + title + "\n\n");
|
output.writeString ("# " + title + "\n\n");
|
||||||
output.writeString (content);
|
output.writeString (content);
|
||||||
|
|
||||||
|
var components = sourcePath.split ("/");
|
||||||
|
var foundSidebar = false;
|
||||||
|
|
||||||
|
while (!foundSidebar && components.length > 1) {
|
||||||
|
|
||||||
|
components.pop ();
|
||||||
|
var sidebarPath = components.copy ().join ("/") + "/_sidebar.md";
|
||||||
|
|
||||||
|
if (FileSystem.exists (sidebarPath)) {
|
||||||
|
|
||||||
|
foundSidebar = true;
|
||||||
|
output.writeString ("\n\n{% sidebar %}");
|
||||||
|
|
||||||
|
var sidebar = File.getContent (sidebarPath);
|
||||||
|
sidebar = replaceWikiLinks (sidebar, names, targetPaths);
|
||||||
|
|
||||||
|
output.writeString (sidebar);
|
||||||
|
output.writeString ("{% endsidebar %}");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
output.close ();
|
output.close ();
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1033,6 +1014,59 @@ class RunScript {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static function replaceWikiLinks (content:String, names:Array<String>, targetPaths:Array<String>):String {
|
||||||
|
|
||||||
|
while (wikiLinks.match (content)) {
|
||||||
|
|
||||||
|
var link = wikiLinks.matched (0);
|
||||||
|
link = link.substr (2, link.length - 4);
|
||||||
|
var components = link.split ("|");
|
||||||
|
|
||||||
|
var title = "";
|
||||||
|
var target = "";
|
||||||
|
|
||||||
|
if (components.length > 1) {
|
||||||
|
|
||||||
|
title = components[0];
|
||||||
|
target = components[1];
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
title = target = components[0];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (StringTools.endsWith (target, ".md")) {
|
||||||
|
|
||||||
|
target = target.substr (0, target.length - 3);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
var replacement = "[" + title + "](/documentation/)";
|
||||||
|
|
||||||
|
for (i in 0...names.length) {
|
||||||
|
|
||||||
|
if (target == names[i]) {
|
||||||
|
|
||||||
|
var path = targetPaths[i];
|
||||||
|
path = path.substr (0, path.lastIndexOf ("/"));
|
||||||
|
|
||||||
|
replacement = "[" + title + "](/documentation/" + path + ")";
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
content = wikiLinks.matchedLeft () + replacement + wikiLinks.matchedRight ();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return content;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static function runCommand (path:String, command:String, args:Array<String>, throwErrors:Bool = true):Int {
|
public static function runCommand (path:String, command:String, args:Array<String>, throwErrors:Bool = true):Int {
|
||||||
|
|
||||||
var oldPath:String = "";
|
var oldPath:String = "";
|
||||||
|
|||||||
Reference in New Issue
Block a user