1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2024-12-12 05:20:26 +00:00

Reorganize templates a little bit

This commit is contained in:
Timur Ismagilov 2020-06-20 14:48:23 +05:00
parent 931bc8bae9
commit c96ba3e08f
12 changed files with 18 additions and 23 deletions

View File

@ -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...")

View File

@ -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()

View File

@ -1,9 +0,0 @@
<div class="naviwrapper">
<form class="naviwrapper__buttons">
<input type="submit" name="action" value="edit"/>
<input type="submit" name="action" value="getBinary"/>
<input type="submit" name="action" value="zen"/>
<input type="submit" name="action" value="raw"/>
</form>
{{ . }}
</div>

View File

@ -1,10 +0,0 @@
<div class="naviwrapper">
<div class="hypha-actions">
<ul>
<li><a href="?action=edit">Edit</a>
<li><a href="?action=getBinary">Download</a>
<li><a href="?action=zen">Zen mode</a>
<li><a href="?action=raw">View raw</a>
</ul>
</div>
</div>

View File

@ -0,0 +1,3 @@
<div class="naviwrapper">
{{ . }}
</div>

View File

@ -0,0 +1,8 @@
<div class="hypha-actions">
<ul>
<li><a href="?action=edit">Edit</a></li>
<li><a href="?action=getBinary">Download</a></li>
<li><a href="?action=zen">Zen mode</a></li>
<li><a href="?action=raw">View raw</a></li>
</ul>
</div>