From f673e09d8f3bd81e4d085f65e229449e1b03b1d2 Mon Sep 17 00:00:00 2001
From: Volker Schukai <volker.schukai@schukai.com>
Date: Tue, 27 Dec 2022 17:26:20 +0100
Subject: [PATCH] feat: new export

---
 README.md                              | 2 +-
 application/source/html/generate.go    | 7 ++++++-
 application/source/template/prepare.go | 2 ++
 application/source/types/page-data.go  | 1 +
 4 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/README.md b/README.md
index fee68d4..44b914b 100644
--- a/README.md
+++ b/README.md
@@ -42,7 +42,7 @@ Furthermore, it will parse the templates for images, anchors, and text.
 
 ##### Generate
 
-This will generate HTML files from the prepared templates.
+This will generate HTML files from the prepared templates and data YAML.
 
 ```bash
 bob html generate --input ./output/ --output ./output/
diff --git a/application/source/html/generate.go b/application/source/html/generate.go
index a8a5c65..0739aa7 100644
--- a/application/source/html/generate.go
+++ b/application/source/html/generate.go
@@ -30,7 +30,12 @@ func GenerateFiles(dataPath, out string) error {
 			return err
 		}
 
-		outFile := path.Join(out, name)
+		outFile := path.Join(out, page.Export)
+
+		dir := path.Dir(outFile)
+		if err := os.MkdirAll(dir, 0755); err != nil {
+			return err
+		}
 
 		err = os.WriteFile(outFile, []byte(html), 0644)
 		if err != nil {
diff --git a/application/source/template/prepare.go b/application/source/template/prepare.go
index a1424ad..1afea22 100644
--- a/application/source/template/prepare.go
+++ b/application/source/template/prepare.go
@@ -307,7 +307,9 @@ func PrepareHtmlFile(from, to string, storage types.PageDataStorage) error {
 	prepareAnchors(node, pd)
 	prepareTextNodes(node, pd)
 
+	pd.Export = path.Join(pd.Lang, path.Base(from))
 	to = path.Join(to, path.Base(from))
+
 	return util.SaveHtml(to, node)
 
 }
diff --git a/application/source/types/page-data.go b/application/source/types/page-data.go
index 0432fea..5113746 100644
--- a/application/source/types/page-data.go
+++ b/application/source/types/page-data.go
@@ -26,6 +26,7 @@ type PageData struct {
 	Images  []Image           `yaml:"images"`
 	Anchors []Anchor          `yaml:"anchors"`
 	Text    []Text            `yaml:"text"`
+	Export  string            `yaml:"export"`
 }
 
 func NewPageData() *PageData {
-- 
GitLab