From c96ba3e08f03093fe5069864cea3c87ba7e80c7a Mon Sep 17 00:00:00 2001 From: Timur Ismagilov Date: Sat, 20 Jun 2020 14:48:23 +0500 Subject: [PATCH] Reorganize templates a little bit --- main.go | 4 +++- render.go | 7 ++++--- templates/Hypha/view/index.html | 9 --------- templates/Hypha/view/sidebar.html | 10 ---------- {templates => w/templates}/Hypha/edit/header.html | 0 {templates => w/templates}/Hypha/edit/index.html | 0 {templates => w/templates}/Hypha/view/bodybottom.html | 0 w/templates/Hypha/view/index.html | 3 +++ w/templates/Hypha/view/sidebar.html | 8 ++++++++ {templates => w/templates}/base.html | 0 {templates => w/templates}/footer.html | 0 {templates => w/templates}/header.html | 0 12 files changed, 18 insertions(+), 23 deletions(-) delete mode 100644 templates/Hypha/view/index.html delete mode 100644 templates/Hypha/view/sidebar.html rename {templates => w/templates}/Hypha/edit/header.html (100%) rename {templates => w/templates}/Hypha/edit/index.html (100%) rename {templates => w/templates}/Hypha/view/bodybottom.html (100%) create mode 100644 w/templates/Hypha/view/index.html create mode 100644 w/templates/Hypha/view/sidebar.html rename {templates => w/templates}/base.html (100%) rename {templates => w/templates}/footer.html (100%) rename {templates => w/templates}/header.html (100%) diff --git a/main.go b/main.go index b3652eb..522ffae 100644 --- a/main.go +++ b/main.go @@ -37,7 +37,8 @@ func RevInMap(m map[string]string) string { } // `rootWikiDir` is a directory where all wiki files reside. -var rootWikiDir string +// `templatesDir` is where templates are. +var rootWikiDir, templatesDir string // `hyphae` is a map with all hyphae. Many functions use it. var hyphae map[string]*Hypha @@ -52,6 +53,7 @@ func main() { if err != nil { panic(err) } + templatesDir = filepath.Join(filepath.Dir(rootWikiDir), "templates") log.Println("Welcome to MycorrhizaWiki α") log.Println("Indexing hyphae...") diff --git a/render.go b/render.go index 46b267d..9c8b528 100644 --- a/render.go +++ b/render.go @@ -5,6 +5,7 @@ import ( "fmt" "io/ioutil" "path" + "path/filepath" "text/template" ) @@ -26,7 +27,7 @@ func EditHyphaPage(name, textMime, content, tags string) string { // HyphaPage returns HTML page of hypha viewer. func HyphaPage(rev Revision, content string) string { sidebar := DefaultSidebar - bside, err := ioutil.ReadFile("Hypha/view/sidebar.html") + bside, err := ioutil.ReadFile(filepath.Join(templatesDir, "Hypha/view/sidebar.html")) if err == nil { sidebar = string(bside) } @@ -60,7 +61,7 @@ func renderBase(content string, keys map[string]string) string { // renderFromMap applies `data` map to template in `templatePath` and returns the result. func renderFromMap(data map[string]string, templatePath string) string { - filePath := path.Join("templates", templatePath) + filePath := path.Join(templatesDir, templatePath) tmpl, err := template.ParseFiles(filePath) if err != nil { return err.Error() @@ -74,7 +75,7 @@ func renderFromMap(data map[string]string, templatePath string) string { // renderFromMap applies `data` string to template in `templatePath` and returns the result. func renderFromString(data string, templatePath string) string { - filePath := path.Join("templates", templatePath) + filePath := path.Join(templatesDir, templatePath) tmpl, err := template.ParseFiles(filePath) if err != nil { return err.Error() diff --git a/templates/Hypha/view/index.html b/templates/Hypha/view/index.html deleted file mode 100644 index 1126a8f..0000000 --- a/templates/Hypha/view/index.html +++ /dev/null @@ -1,9 +0,0 @@ - \ No newline at end of file diff --git a/templates/Hypha/view/sidebar.html b/templates/Hypha/view/sidebar.html deleted file mode 100644 index 7d3a6b8..0000000 --- a/templates/Hypha/view/sidebar.html +++ /dev/null @@ -1,10 +0,0 @@ - diff --git a/templates/Hypha/edit/header.html b/w/templates/Hypha/edit/header.html similarity index 100% rename from templates/Hypha/edit/header.html rename to w/templates/Hypha/edit/header.html diff --git a/templates/Hypha/edit/index.html b/w/templates/Hypha/edit/index.html similarity index 100% rename from templates/Hypha/edit/index.html rename to w/templates/Hypha/edit/index.html diff --git a/templates/Hypha/view/bodybottom.html b/w/templates/Hypha/view/bodybottom.html similarity index 100% rename from templates/Hypha/view/bodybottom.html rename to w/templates/Hypha/view/bodybottom.html diff --git a/w/templates/Hypha/view/index.html b/w/templates/Hypha/view/index.html new file mode 100644 index 0000000..059f524 --- /dev/null +++ b/w/templates/Hypha/view/index.html @@ -0,0 +1,3 @@ + diff --git a/w/templates/Hypha/view/sidebar.html b/w/templates/Hypha/view/sidebar.html new file mode 100644 index 0000000..e26616d --- /dev/null +++ b/w/templates/Hypha/view/sidebar.html @@ -0,0 +1,8 @@ +
+ +
diff --git a/templates/base.html b/w/templates/base.html similarity index 100% rename from templates/base.html rename to w/templates/base.html diff --git a/templates/footer.html b/w/templates/footer.html similarity index 100% rename from templates/footer.html rename to w/templates/footer.html diff --git a/templates/header.html b/w/templates/header.html similarity index 100% rename from templates/header.html rename to w/templates/header.html