115 lines
3.7 KiB
Go
115 lines
3.7 KiB
Go
package yatwiki3
|
|
|
|
import (
|
|
"fmt"
|
|
"html/template"
|
|
"time"
|
|
)
|
|
|
|
var subresourceNonce = time.Now().Unix()
|
|
|
|
type pageTemplateOptions struct {
|
|
CurrentPageIsArticle bool
|
|
CurrentPageName string
|
|
WikiTitle string
|
|
Content template.HTML
|
|
BaseURL string
|
|
LoadCodeResources bool
|
|
DefaultPage string
|
|
AllowDownload bool
|
|
SessionMessage template.HTML
|
|
}
|
|
|
|
func DefaultPageTemplateOptions(opts *ServerOptions) *pageTemplateOptions {
|
|
return &pageTemplateOptions{
|
|
WikiTitle: opts.PageTitle,
|
|
BaseURL: opts.ExpectBaseURL,
|
|
DefaultPage: opts.DefaultPage,
|
|
AllowDownload: opts.AllowDBDownload,
|
|
}
|
|
}
|
|
|
|
func (this *pageTemplateOptions) NewArticleTitle() string {
|
|
return fmt.Sprintf("untitled-%d", time.Now().Unix())
|
|
}
|
|
|
|
func (this *pageTemplateOptions) SubresourceNonce() int64 {
|
|
return subresourceNonce
|
|
}
|
|
|
|
const pageTemplate string = `<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<title>{{.CurrentPageName}}{{ if len .CurrentPageName }} - {{end}}{{.WikiTitle}}</title>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width">
|
|
<meta name="referrer" content="no-referrer">
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
|
<link rel="alternate" type="application/rss+xml" href="{{.BaseURL}}rss/changes" title="{{.WikiTitle}} - Recent Changes">
|
|
<link rel="stylesheet" type="text/css" href="{{.BaseURL}}wiki.css?_={{.SubresourceNonce}}">
|
|
{{if .LoadCodeResources}}
|
|
<script type="text/javascript" src="{{.BaseURL}}highlight.js?_={{.SubresourceNonce}}"></script>
|
|
<script type="text/javascript">hljs.tabReplace = ' ';hljs.initHighlightingOnLoad();</script>
|
|
{{end}}
|
|
<script type="text/javascript">
|
|
var a = document;
|
|
function tid(id) {
|
|
t(a.getElementById(id));
|
|
}
|
|
function ts(e) {
|
|
t(e.nextSibling);
|
|
}
|
|
function t(e) {
|
|
e.style.display=(e.style.display=='none') ? 'block' : 'none';
|
|
}
|
|
function els(e,s){ // no js exec in innerHTML
|
|
var p = e.parentNode;
|
|
p.className = "";
|
|
p.innerHTML = s;
|
|
var n = "script";
|
|
var z = p.childNodes,
|
|
m = "text/javascript",
|
|
l = function(s){ return s.toLowerCase(); };
|
|
for (var i=0, e=0; e = z[i]; i++) {
|
|
if (e.nodeName && (l(e.nodeName)===n) && (!e.type||l(e.type)===m)) {
|
|
var t = p.removeChild(e),
|
|
d = a.getElementsByTagName("head")[0],
|
|
se = a.createElement(n);
|
|
se.type = m;
|
|
se.appendChild(a.createTextNode((t.text||t.textContent||t.innerHTML||"")));
|
|
d.insertBefore(se,d.firstChild );
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
</head>
|
|
<body>
|
|
<div class="header">
|
|
<a href="{{.BaseURL}}view/{{.DefaultPage}}" title="Home"><div class="sprite hm"></div></a>
|
|
<a href="javascript:;" onclick="tid('spm');tid('tr1');tid('tr2');" title="Menu"><div class="sprite sp"></div></a>
|
|
<a href="{{.BaseURL}}modify/{{.NewArticleTitle}}" title="New Page"><div class="sprite nw"></div></a>
|
|
{{if .CurrentPageIsArticle }}
|
|
<div class="sep"></div>
|
|
<a href="{{.BaseURL}}history/{{.CurrentPageName}}" title="Page History"><div class="sprite hs"></div></a>
|
|
<a href="{{.BaseURL}}modify/{{.CurrentPageName}}" title="Modify Page"><div class="sprite ed"></div></a>
|
|
{{end}}
|
|
</div>
|
|
<div id="tr1" style="display:none;"></div>
|
|
<div id="tr2" style="display:none;"></div>
|
|
<div class="ddmenu" id="spm" style="display:none;">
|
|
<a href="{{.BaseURL}}recent"><div class="sprite no"></div> Recent Changes</a>
|
|
<a href="{{.BaseURL}}random"><div class="sprite rn"></div> Random Page</a>
|
|
<a href="{{.BaseURL}}index"><div class="sprite no"></div> Article Index</a>
|
|
{{if .AllowDownload}}
|
|
<a href="{{.BaseURL}}download-database"><div class="sprite no"></div> Download DB backup</a>
|
|
{{end}}
|
|
</div>
|
|
<div class="content">
|
|
{{if len .SessionMessage}}
|
|
<div class="info">{{.SessionMessage}}</div>
|
|
{{end}}
|
|
{{.Content}}
|
|
</div>
|
|
</body>
|
|
</html>`
|