Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into fix/deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
tobil4sk committed Jul 27, 2024
2 parents 3ccb3e2 + 7b281d4 commit dd9be63
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 40 deletions.
3 changes: 0 additions & 3 deletions highlighting.hxml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,5 @@
-main Highlighting
-lib hxnodejs
-lib highlighter
-lib markdown:git:https://github.com/HaxeFoundation/haxe-markdown.git
-lib hxtemplo:git:https://github.com/Simn/hxtemplo.git
-lib hxparse
-js bin/patch.js
-cmd node bin/patch.js
22 changes: 22 additions & 0 deletions src/Config.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import haxe.io.Path;

class Config {
public static final contentPath = "./assets/content/";
public static final outputPath = "./output/";
public static final repositoryUrl = switch (Sys.getEnv("REPO_URL")) {
case null: "https://github.com/HaxeFoundation/code-cookbook/";
case v: v;
};
public static final repositoryBranch = switch (Sys.getEnv("REPO_BRANCH")) {
case null: "master";
case v: v;
};
public static final basePath = switch (Sys.getEnv("BASEPATH")) {
case null: "";
case v: v;
};
public static final titlePostFix = " - Haxe programming language cookbook";
public static final cookbookFolder = Path.addTrailingSlash("cookbook");
public static final assetsFolderName = "assets";
public static final snippetsFolder = Path.addTrailingSlash("snippets");
}
11 changes: 1 addition & 10 deletions src/Generator.hx
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,14 @@ import sys.FileSystem;
import sys.io.File;
import templo.Template;
import util.GitUtil.GitAuthorInfo;
import Config.*;

using StringTools;

/**
* @author Mark Knol
*/
class Generator {
public var contentPath = "./assets/content/";
public var outputPath = "./output/";
public var repositoryUrl = "";
public var repositoryBranch = "";
public var basePath = "";
public var titlePostFix = "";
public var cookbookFolder = Path.addTrailingSlash("cookbook");
public var assetsFolderName = "assets";
public var snippetsFolder = Path.addTrailingSlash("snippets");

private var _pages:Array<Page> = new Array<Page>();
private var _folders:StringMap<Array<Page>> = new StringMap<Array<Page>>();
private var _templates:StringMap<Template> = new StringMap<Template>();
Expand Down
6 changes: 2 additions & 4 deletions src/Highlighting.hx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ class Highlighting {
public static function main() {
Sys.println("Applying syntax highlighting ...");

var g = new Generator();

// Convert CSON grammar to json for vscode-textmate
File.saveContent("bin/javascript.json", Json.stringify(CSON.parse(File.getContent("grammars/language-javascript/grammars/javascript.cson"))));

Expand All @@ -25,7 +23,7 @@ class Highlighting {
];

// Go over the generated HTML file and apply syntax highlighting
var missingGrammars = Highlighter.patchFolder(g.outputPath, grammars, function (classList) {
var missingGrammars = Highlighter.patchFolder(Config.outputPath, grammars, function (classList) {
return classList.substr(12);
});

Expand All @@ -34,7 +32,7 @@ class Highlighting {
}

// Add CSS rules for highlighting
var path = g.outputPath + "/css/haxe-nav.min.css";
var path = Config.outputPath + "/css/haxe-nav.min.css";
var baseStyle = File.getContent(path);
var syntaxStyle = haxeGrammar.runCss();
File.saveContent(path, baseStyle + syntaxStyle);
Expand Down
19 changes: 3 additions & 16 deletions src/Main.hx
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,11 @@ class Main {
public static function main() {
haxe.Timer.measure(function() {
var generator = new Generator();
generator.titlePostFix = " - Haxe programming language cookbook";
generator.basePath = switch (Sys.getEnv("BASEPATH")){
case null: "";
case v: v;
};
generator.repositoryUrl = switch (Sys.getEnv("REPO_URL")) {
case null: "https://github.com/HaxeFoundation/code-cookbook/";
case v: v;
}
generator.repositoryBranch = switch (Sys.getEnv("REPO_BRANCH")) {
case null: "master";
case v: v;
}


generator.build();
generator.includeDirectory("assets/includes");
Redirections.generate(generator);

Redirections.generate();
});
}
}
14 changes: 7 additions & 7 deletions src/Redirections.hx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import sys.io.File;
*/
class Redirections
{
public static function generate(generator:Generator)
public static function generate()
{
var list = [
"category/abstract-types/rounded float.html" => "/category/abstract-types/rounded-float.html",
Expand All @@ -30,17 +30,17 @@ class Redirections
];

for (page in list.keys()) {
var template = new Template(File.getContent(generator.contentPath + "redirection.mtt"));
var template = new Template(File.getContent(Config.contentPath + "redirection.mtt"));
var content = template.execute({
redirectionLink: list.get(page)
});

// make sure directory exists
FileSystem.createDirectory(generator.outputPath + Path.directory(page));
FileSystem.createDirectory(Config.outputPath + Path.directory(page));

// save to output
File.saveContent(generator.outputPath + page, content);
File.saveContent(Config.outputPath + page, content);

}
}

Expand Down

0 comments on commit dd9be63

Please sign in to comment.