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:
parent
931bc8bae9
commit
c96ba3e08f
4
main.go
4
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...")
|
||||
|
@ -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()
|
||||
|
@ -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>
|
@ -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>
|
3
w/templates/Hypha/view/index.html
Normal file
3
w/templates/Hypha/view/index.html
Normal file
@ -0,0 +1,3 @@
|
||||
<div class="naviwrapper">
|
||||
{{ . }}
|
||||
</div>
|
8
w/templates/Hypha/view/sidebar.html
Normal file
8
w/templates/Hypha/view/sidebar.html
Normal 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>
|
Loading…
Reference in New Issue
Block a user