1
0
Fork 0
mirror of https://github.com/Eggbertx/gochan.git synced 2025-08-17 10:56:24 -07:00

Finish separating config into separate structs

This commit is contained in:
Eggbertx 2021-07-11 16:30:39 -07:00
parent dfdb926d71
commit 77380750ae
11 changed files with 61 additions and 47 deletions

View file

@ -140,7 +140,7 @@ func BuildBoardPages(board *gcsql.Board) error {
// Render board page template to the file,
// packaging the board/section list, threads, and board info
if err = serverutil.MinifyTemplate(gctemplates.BoardPage, map[string]interface{}{
"config": config.Config,
"webroot": criticalCfg.WebRoot,
"boards": gcsql.AllBoards,
"sections": gcsql.AllSections,
"threads": threads,
@ -183,7 +183,7 @@ func BuildBoardPages(board *gcsql.Board) error {
// Render the boardpage template
if err = serverutil.MinifyTemplate(gctemplates.BoardPage, map[string]interface{}{
"config": config.Config,
"webroot": criticalCfg.WebRoot,
"boards": gcsql.AllBoards,
"sections": gcsql.AllSections,
"threads": pageThreads,
@ -261,8 +261,8 @@ func BuildCatalog(boardID int) string {
if err = board.PopulateData(boardID); err != nil {
return gclog.Printf(gclog.LErrorLog, "Error getting board information (ID: %d)", boardID)
}
catalogPath := path.Join(config.Config.DocumentRoot, board.Dir, "catalog.html")
criticalCfg := config.GetSystemCriticalConfig()
catalogPath := path.Join(criticalCfg.DocumentRoot, board.Dir, "catalog.html")
catalogFile, err := os.OpenFile(catalogPath, os.O_CREATE|os.O_RDWR|os.O_TRUNC, 0777)
if err != nil {
return gclog.Printf(gclog.LErrorLog,
@ -287,7 +287,7 @@ func BuildCatalog(boardID int) string {
if err = serverutil.MinifyTemplate(gctemplates.Catalog, map[string]interface{}{
"boards": gcsql.AllBoards,
"config": config.Config,
"webroot": criticalCfg.WebRoot,
"board": board,
"sections": gcsql.AllSections,
"threads": threadInterfaces,

View file

@ -21,7 +21,6 @@ func BuildFrontPage() error {
"Error loading front page template: ", err.Error()))
}
criticalCfg := config.GetSystemCriticalConfig()
boardCfg := config.GetBoardConfig("")
os.Remove(path.Join(criticalCfg.DocumentRoot, "index.html"))
frontFile, err := os.OpenFile(path.Join(criticalCfg.DocumentRoot, "index.html"), os.O_CREATE|os.O_RDWR|os.O_TRUNC, 0777)
@ -32,7 +31,8 @@ func BuildFrontPage() error {
defer frontFile.Close()
var recentPostsArr []gcsql.RecentPost
recentPostsArr, err = gcsql.GetRecentPostsGlobal(boardCfg.MaxRecentPosts, !config.Config.RecentPostsWithNoFile)
siteCfg := config.GetSiteConfig()
recentPostsArr, err = gcsql.GetRecentPostsGlobal(siteCfg.MaxRecentPosts, !siteCfg.RecentPostsWithNoFile)
if err != nil {
return errors.New(gclog.Print(gclog.LErrorLog,
"Failed loading recent posts: "+err.Error()))
@ -45,7 +45,8 @@ func BuildFrontPage() error {
}
if err = serverutil.MinifyTemplate(gctemplates.FrontPage, map[string]interface{}{
"config": config.Config,
"webroot": criticalCfg.WebRoot,
"site_config": siteCfg,
"sections": gcsql.AllSections,
"boards": gcsql.AllBoards,
"recent_posts": recentPostsArr,
@ -58,7 +59,8 @@ func BuildFrontPage() error {
// BuildBoardListJSON generates a JSON file with info about the boards
func BuildBoardListJSON() error {
boardListFile, err := os.OpenFile(path.Join(config.Config.DocumentRoot, "boards.json"), os.O_CREATE|os.O_RDWR|os.O_TRUNC, 0777)
criticalCfg := config.GetSystemCriticalConfig()
boardListFile, err := os.OpenFile(path.Join(criticalCfg.DocumentRoot, "boards.json"), os.O_CREATE|os.O_RDWR|os.O_TRUNC, 0777)
if err != nil {
return errors.New(
gclog.Print(gclog.LErrorLog, "Failed opening boards.json for writing: ", err.Error()))
@ -69,11 +71,12 @@ func BuildBoardListJSON() error {
"boards": []gcsql.Board{},
}
boardCfg := config.GetBoardConfig("")
// Our cooldowns are site-wide currently.
cooldowns := gcsql.BoardCooldowns{
NewThread: config.Config.NewThreadDelay,
Reply: config.Config.ReplyDelay,
ImageReply: config.Config.ReplyDelay}
NewThread: boardCfg.NewThreadDelay,
Reply: boardCfg.ReplyDelay,
ImageReply: boardCfg.ReplyDelay}
for b := range gcsql.AllBoards {
gcsql.AllBoards[b].Cooldowns = cooldowns
@ -101,7 +104,10 @@ func BuildJS() error {
return errors.New(gclog.Println(gclog.LErrorLog,
"Error loading consts.js template:", err.Error()))
}
constsJSPath := path.Join(config.Config.DocumentRoot, "js", "consts.js")
boardCfg := config.GetBoardConfig("")
criticalCfg := config.GetSystemCriticalConfig()
constsJSPath := path.Join(criticalCfg.DocumentRoot, "js", "consts.js")
constsJSFile, err := os.OpenFile(constsJSPath, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0644)
if err != nil {
return errors.New(gclog.Printf(gclog.LErrorLog,
@ -109,7 +115,14 @@ func BuildJS() error {
}
defer constsJSFile.Close()
if err = serverutil.MinifyTemplate(gctemplates.JsConsts, config.Config, constsJSFile, "text/javascript"); err != nil {
if err = serverutil.MinifyTemplate(gctemplates.JsConsts,
map[string]interface{}{
"webroot": criticalCfg.WebRoot,
"styles": boardCfg.Styles,
"default_style": boardCfg.DefaultStyle,
"timezone": criticalCfg.TimeZone,
},
constsJSFile, "text/javascript"); err != nil {
return errors.New(gclog.Printf(gclog.LErrorLog,
"Error building %q: %s", constsJSPath, err.Error()))
}

View file

@ -162,7 +162,7 @@ var funcMap = template.FuncMap{
postURL += systemCritical.WebRoot
if typeOf == "recent" {
post, ok := postInterface.(*gcsql.RecentPost)
post, ok := postInterface.(gcsql.RecentPost)
if !ok {
return
}

View file

@ -66,7 +66,9 @@ func CallManageFunction(writer http.ResponseWriter, request *http.Request) {
if !handler.isJSON {
managePageBuffer.WriteString("<!DOCTYPE html><html><head>")
criticalCfg := config.GetSystemCriticalConfig()
if err = gctemplates.ManageHeader.Execute(&managePageBuffer, criticalCfg); err != nil {
if err = gctemplates.ManageHeader.Execute(&managePageBuffer, map[string]interface{}{
"webroot": criticalCfg.WebRoot,
}); err != nil {
serverutil.ServeErrorPage(writer, gclog.Print(gclog.LErrorLog|gclog.LStaffLog,
"Error executing manage page header template: ", err.Error()))
return

View file

@ -54,7 +54,6 @@ func BanHandler(writer http.ResponseWriter, request *http.Request) {
}
if err = serverutil.MinifyTemplate(gctemplates.Banpage, map[string]interface{}{
// "config": config.Config,
"systemCritical": systemCritical,
"siteConfig": siteConfig,
"boardConfig": boardConfig,

View file

@ -4,7 +4,7 @@
<span id="board-subtitle">{{$.board.Subtitle}}</span>
</header><hr />
<div id="right-sidelinks">
<a href="{{.config.WebRoot}}{{.board.Dir}}/catalog.html">Board catalog</a><br />
<a href="{{.webroot}}{{.board.Dir}}/catalog.html">Board catalog</a><br />
</div>
{{- template "postbox.html" .}}
<hr />
@ -15,13 +15,13 @@
<div class="op-post" id="op{{$op.ID}}">
{{- if ne $op.Filename "" -}}
{{- if ne $op.Filename "deleted"}}
<div class="file-info">File: <a href="{{$.config.WebRoot}}{{$.board.Dir}}/src/{{$op.Filename}}" target="_blank">{{$op.Filename}}</a> - ({{formatFilesize $op.Filesize}} , {{$op.ImageW}}x{{$op.ImageH}}, {{$op.FilenameOriginal}})</div>
<a class="upload-container" href="{{$.config.WebRoot}}{{$.board.Dir}}/src/{{$op.Filename}}"><img src="{{$.config.WebRoot}}{{$.board.Dir}}/thumb/{{getThreadThumbnail $op.Filename}}" alt="{{$.config.WebRoot}}{{$.board.Dir}}/src/{{$op.Filename}}" width="{{$op.ThumbW}}" height="{{$op.ThumbH}}" class="upload" /></a>
<div class="file-info">File: <a href="{{$.webroot}}{{$.board.Dir}}/src/{{$op.Filename}}" target="_blank">{{$op.Filename}}</a> - ({{formatFilesize $op.Filesize}} , {{$op.ImageW}}x{{$op.ImageH}}, {{$op.FilenameOriginal}})</div>
<a class="upload-container" href="{{$.webroot}}{{$.board.Dir}}/src/{{$op.Filename}}"><img src="{{$.webroot}}{{$.board.Dir}}/thumb/{{getThreadThumbnail $op.Filename}}" alt="{{$.webroot}}{{$.board.Dir}}/src/{{$op.Filename}}" width="{{$op.ThumbW}}" height="{{$op.ThumbH}}" class="upload" /></a>
{{else}}
<div class="file-deleted-box" style="text-align:center;">File removed</div>
{{end}}
{{end}}
<input type="checkbox" id="check{{$op.ID}}" name="check{{$op.ID}}" /><label class="post-info" for="check{{$op.ID}}"> <span class="subject">{{$op.Subject}}</span> <span class="postername">{{if ne $op.Email ""}}<a href="mailto:{{$op.Email}}">{{end}}{{if ne $op.Name ""}}{{$op.Name}}{{else}}{{if eq $op.Tripcode ""}}{{$.board.Anonymous}}{{end}}{{end}}{{if ne $op.Email ""}}</a>{{end}}</span>{{if ne $op.Tripcode ""}}<span class="tripcode">!{{$op.Tripcode}}</span>{{end}} {{formatTimestamp $op.Timestamp}} </label><a href="{{$.config.WebRoot}}{{$.board.Dir}}/res/{{$op.ID}}.html#{{$op.ID}}">No.</a> <a href="javascript:quote({{$op.ID}})" class="backlink-click">{{$op.ID}}</a> <span class="post-links"> <span class="thread-ddown">[<a href="javascript:void(0)">&#9660;</a>]</span> <span>[<a href="{{$.config.WebRoot}}{{$.board.Dir}}/res/{{$op.ID}}.html">View</a>]</span></span><br />
<input type="checkbox" id="check{{$op.ID}}" name="check{{$op.ID}}" /><label class="post-info" for="check{{$op.ID}}"> <span class="subject">{{$op.Subject}}</span> <span class="postername">{{if ne $op.Email ""}}<a href="mailto:{{$op.Email}}">{{end}}{{if ne $op.Name ""}}{{$op.Name}}{{else}}{{if eq $op.Tripcode ""}}{{$.board.Anonymous}}{{end}}{{end}}{{if ne $op.Email ""}}</a>{{end}}</span>{{if ne $op.Tripcode ""}}<span class="tripcode">!{{$op.Tripcode}}</span>{{end}} {{formatTimestamp $op.Timestamp}} </label><a href="{{$.webroot}}{{$.board.Dir}}/res/{{$op.ID}}.html#{{$op.ID}}">No.</a> <a href="javascript:quote({{$op.ID}})" class="backlink-click">{{$op.ID}}</a> <span class="post-links"> <span class="thread-ddown">[<a href="javascript:void(0)">&#9660;</a>]</span> <span>[<a href="{{$.webroot}}{{$.board.Dir}}/res/{{$op.ID}}.html">View</a>]</span></span><br />
<div class="post-text">{{truncateHTMLMessage $op.MessageHTML 2222 18}}</div>
{{- if gt $thread.NumReplies 3}}
<b>{{subtract $thread.NumReplies 3}} post{{if gt $thread.NumReplies 4}}s{{end}} omitted</b>
@ -31,11 +31,11 @@
<div class="reply-container" id="replycontainer{{$reply.ID}}">
<a class="anchor" id="{{$reply.ID}}"></a>
<div class="reply" id="reply{{$reply.ID}}">
<input type="checkbox" id="check{{$reply.ID}}" name="check{{$reply.ID}}" /> <label class="post-info" for="check{{$reply.ID}}"> <span class="subject">{{$reply.Subject}}</span> <span class="postername">{{if ne $reply.Email ""}}<a href="mailto:{{$reply.Email}}">{{end}}{{if ne $reply.Name ""}}{{$reply.Name}}{{else}}{{if eq $reply.Tripcode ""}}{{$.board.Anonymous}}{{end}}{{end}}{{if ne $reply.Email ""}}</a>{{end}}</span>{{if ne $reply.Tripcode ""}}<span class="tripcode">!{{$reply.Tripcode}}</span>{{end}} {{formatTimestamp $reply.Timestamp}} </label><a href="{{$.config.WebRoot}}{{$.board.Dir}}/res/{{$op.ID}}.html#{{$reply.ID}}">No.</a> <a href="javascript:quote({{$reply.ID}})" class="backlink-click">{{$reply.ID}}</a> <span class="post-links"><span class="thread-ddown">[<a href="javascript:void(0)">&#9660;</a>]</span></span><br />
<input type="checkbox" id="check{{$reply.ID}}" name="check{{$reply.ID}}" /> <label class="post-info" for="check{{$reply.ID}}"> <span class="subject">{{$reply.Subject}}</span> <span class="postername">{{if ne $reply.Email ""}}<a href="mailto:{{$reply.Email}}">{{end}}{{if ne $reply.Name ""}}{{$reply.Name}}{{else}}{{if eq $reply.Tripcode ""}}{{$.board.Anonymous}}{{end}}{{end}}{{if ne $reply.Email ""}}</a>{{end}}</span>{{if ne $reply.Tripcode ""}}<span class="tripcode">!{{$reply.Tripcode}}</span>{{end}} {{formatTimestamp $reply.Timestamp}} </label><a href="{{$.webroot}}{{$.board.Dir}}/res/{{$op.ID}}.html#{{$reply.ID}}">No.</a> <a href="javascript:quote({{$reply.ID}})" class="backlink-click">{{$reply.ID}}</a> <span class="post-links"><span class="thread-ddown">[<a href="javascript:void(0)">&#9660;</a>]</span></span><br />
{{if ne $reply.Filename ""}}
{{if ne $reply.Filename "deleted" -}}
<span class="file-info">File: <a href="{{$.config.WebRoot}}{{$.board.Dir}}/src/{{$reply.Filename}}" target="_blank">{{$reply.Filename}}</a> - ({{formatFilesize $reply.Filesize}} , {{$reply.ImageW}}x{{$reply.ImageH}}, {{$reply.FilenameOriginal}})</span><br />
<a class="upload-container" href="{{$.config.WebRoot}}{{$.board.Dir}}/src/{{$reply.Filename}}"><img src="{{$.config.WebRoot}}{{$.board.Dir}}/thumb/{{getThreadThumbnail $reply.Filename}}" alt="{{$.config.WebRoot}}{{$.board.Dir}}/src/{{$reply.Filename}}" width="{{$reply.ThumbW}}" height="{{$reply.ThumbH}}" class="upload" /></a>
<span class="file-info">File: <a href="{{$.webroot}}{{$.board.Dir}}/src/{{$reply.Filename}}" target="_blank">{{$reply.Filename}}</a> - ({{formatFilesize $reply.Filesize}} , {{$reply.ImageW}}x{{$reply.ImageH}}, {{$reply.FilenameOriginal}})</span><br />
<a class="upload-container" href="{{$.webroot}}{{$.board.Dir}}/src/{{$reply.Filename}}"><img src="{{$.webroot}}{{$.board.Dir}}/thumb/{{getThreadThumbnail $reply.Filename}}" alt="{{$.webroot}}{{$.board.Dir}}/src/{{$reply.Filename}}" width="{{$reply.ThumbW}}" height="{{$reply.ThumbH}}" class="upload" /></a>
{{else}}
<div class="file-deleted-box" style="text-align:center;">File removed</div>
{{end}}

View file

@ -4,8 +4,8 @@
<span id="board-subtitle">Catalog</span>
</header><hr />
<div id="catalog-links" style="float: left;">
[<a href="{{$.config.WebRoot}}{{$.board.Dir}}">Return</a>]
[<a href="{{$.config.WebRoot}}{{$.board.Dir}}/catalog.html">Refresh</a>]
[<a href="{{$.webroot}}{{$.board.Dir}}">Return</a>]
[<a href="{{$.webroot}}{{$.board.Dir}}/catalog.html">Refresh</a>]
</div>
<div id="catalog-controls" style="float: right;">
Sort by: <select>
@ -16,9 +16,9 @@
</div><hr />
<div id="content">{{range $_,$thread := .threads}}
<div class="catalog-thread">
<a href="{{$.config.WebRoot}}{{$.board.Dir}}/res/{{$thread.ID}}.html">
<a href="{{$.webroot}}{{$.board.Dir}}/res/{{$thread.ID}}.html">
{{if eq $thread.Filename ""}}(No file){{else if eq $thread.Filename "deleted"}}(File deleted){{else}}
<img src="{{$.config.WebRoot}}{{$.board.Dir}}/thumb/{{getThreadThumbnail $thread.Filename}}" alt="{{$.config.WebRoot}}{{$.board.Dir}}/src/{{$thread.Filename}}" width="{{$thread.ThumbW}}" height="{{$thread.ThumbH}}" />
<img src="{{$.webroot}}{{$.board.Dir}}/thumb/{{getThreadThumbnail $thread.Filename}}" alt="{{$.webroot}}{{$.board.Dir}}/src/{{$thread.Filename}}" width="{{$thread.ThumbW}}" height="{{$thread.ThumbH}}" />
{{end}}</a><br />
<b>{{if eq $thread.Name ""}}Anonymous{{else}}{{$thread.Name}}{{end}}</b> | <b>R:</b> {{numReplies $.board.ID $thread.ID}}<br />
{{$thread.MessageHTML}}

View file

@ -3,11 +3,11 @@
instead of loading them on every HTML page.
*/ -}}
var styles = [
{{- range $ii, $style := .Styles -}}
{{- range $ii, $style := .styles -}}
{{if gt $ii 0}},{{end -}}
{Name: "{{js $style.Name}}", Filename: "{{js $style.Filename}}"}
{{- end -}}
];
var defaultStyle = "{{js .DefaultStyle}}";
var webroot = "{{js .WebRoot}}";
var serverTZ = {{.TimeZone}};
var defaultStyle = "{{js .default_style}}";
var webroot = "{{js .webroot}}";
var serverTZ = {{.timezone}};

View file

@ -1,7 +1,7 @@
{{- template "page_header.html" .}}
<div id="top-pane">
<span id="site-title">{{.config.SiteName}}</span><br />
<span id="site-slogan">{{.config.SiteSlogan}}</span>
<span id="site-title">{{.site_config.SiteName}}</span><br />
<span id="site-slogan">{{.site_config.SiteSlogan}}</span>
</div><br />
<div id="frontpage">
<div class="section-block" style="margin: 16px 64px 16px 64px;">
@ -17,8 +17,8 @@
<ul style="float:left; list-style: none">
<li style="text-align: center; font-weight: bold"><b><u>{{$section.Name}}</u></b></li>
{{range $_, $board := $.boards}}
{{if and (eq $board.Section $section.ID) (ne $board.Dir $.config.Modboard)}}
<li><a href="{{$.config.WebRoot}}{{$board.Dir}}/" title="{{$board.Description}}">/{{$board.Dir}}/</a> — {{$board.Title}}</li>
{{if and (eq $board.Section $section.ID) (ne $board.Dir $.site_config.Modboard)}}
<li><a href="{{$.webroot}}{{$board.Dir}}/" title="{{$board.Description}}">/{{$board.Dir}}/</a> — {{$board.Title}}</li>
{{end}}
{{end}}
</ul>
@ -26,7 +26,7 @@
{{end}}
</div>
</div>
{{- if gt .config.MaxRecentPosts 0}}
{{- if gt .site_config.MaxRecentPosts 0}}
<div class="section-block">
<div class="section-title-block"><b>Recent Posts</b></div>
<div class="section-body">
@ -34,11 +34,11 @@
{{- range $i, $post := $.recent_posts}}{{$postURL := getPostURL $post "recent" false}}
<div class="recent-post">
{{if and (ne $post.Filename "deleted") (ne $post.Filename "") -}}
<a href="{{$postURL}}" class="front-reply" target="_blank"><img src="{{$.config.WebRoot}}{{$post.BoardName}}/thumb/{{getThreadThumbnail $post.Filename}}" alt="post thumbnail"/></a><br />
<a href="{{$postURL}}" class="front-reply" target="_blank"><img src="{{$.webroot}}{{$post.BoardName}}/thumb/{{getThreadThumbnail $post.Filename}}" alt="post thumbnail"/></a><br />
{{else}}
<div class="file-deleted-box" style="text-align:center; float:none;"><a href="{{$postURL}}" class="front-reply" target="_blank">No file</a></div>
{{- end}}<br />
<a href="{{$.config.WebRoot}}{{$post.BoardName}}/">/{{$post.BoardName}}/</a><hr />
<a href="{{$.webroot}}{{$post.BoardName}}/">/{{$post.BoardName}}/</a><hr />
{{truncateMessage (stripHTML $post.Message) 40 4}}
</div>{{end}}
</div>

View file

@ -1,5 +1,5 @@
<div id="footer">
<a href="{{$.systemCritical.WebRoot}}">Home</a> | <a href="{{$.systemCritical.WebRoot}}#boards">Boards</a> | <a href="{{$.config.WebRoot}}#rules">Rules</a> | <a href="{{$.config.WebRoot}}#faq">FAQ</a><br />
<a href="{{$.webroot}}">Home</a> | <a href="{{$.webroot}}#boards">Boards</a> | <a href="{{$.webroot}}#rules">Rules</a> | <a href="{{$.webroot}}#faq">FAQ</a><br />
Powered by <a href="http://github.com/eggbertx/gochan/">Gochan {{version}}</a><br />
</div>
</body>

View file

@ -9,14 +9,14 @@
{{- else if ne $.op.MessageHTML "" -}}<title>/{{$.board.Dir}}/ - {{truncateString $.op.MessageText 20 true}}</title>
{{- else}}<title>/{{$.board.Dir}}/ - #{{$.op.ID}}</title>{{end}}
{{- else}}<title>/{{$.board.Dir}}/ - {{$.board.Title}}</title>{{end}}
{{- else}}<title>{{.config.SiteName}}</title>{{end}}
<link rel="stylesheet" href="{{.config.WebRoot}}css/global.css" />
<link id="theme" rel="stylesheet" href="{{.config.WebRoot}}css/{{.config.DefaultStyle}}" />
<link rel="shortcut icon" href="{{.config.WebRoot}}favicon.png">
<script type="text/javascript" src="{{$.config.WebRoot}}js/consts.js"></script>
<script type="text/javascript" src="{{$.config.WebRoot}}js/gochan.js"></script>
{{- else}}<title>{{.site_config.SiteName}}</title>{{end}}
<link rel="stylesheet" href="{{$.webroot}}css/global.css" />
<link id="theme" rel="stylesheet" href="{{.webroot}}css/{{.board_config.DefaultStyle}}" />
<link rel="shortcut icon" href="{{.webroot}}favicon.png">
<script type="text/javascript" src="{{$.webroot}}js/consts.js"></script>
<script type="text/javascript" src="{{$.webroot}}js/gochan.js"></script>
</head>
<body>
<div id="topbar">
{{range $i, $board := .boards}}<a href="{{$.config.WebRoot}}{{$board.Dir}}/" class="topbar-item">/{{$board.Dir}}/</a>{{end}}
{{range $i, $board := .boards}}<a href="{{$.webroot}}{{$board.Dir}}/" class="topbar-item">/{{$board.Dir}}/</a>{{end}}
</div>