mirror of
https://github.com/Eggbertx/gochan.git
synced 2025-09-05 11:06:23 -07:00
Change config.Styles from a string array to a Style struct array and give proper warning
TODO: Use javascript to allow an admin to add/edit themes from the config UI
This commit is contained in:
parent
ed0ee45f5d
commit
ac2b962fa9
10 changed files with 49 additions and 23 deletions
|
@ -34,8 +34,11 @@
|
|||
"SiteWebfolder": "/",
|
||||
"DomainRegex": "(https|http):\\/\\/(gochan\\.lunachan\\.net|gochan\\.org)\\/(.*)",
|
||||
|
||||
"Styles": ["pipes","efchan"],
|
||||
"DefaultStyle": "pipes",
|
||||
"Styles": [
|
||||
{ "Name": "Pipes", "Filename": "pipes.css" },
|
||||
{ "Name": "Burichan", "Filename": "burichan.css" }
|
||||
],
|
||||
"DefaultStyle": "pipes.css",
|
||||
|
||||
"AllowDuplicateImages": true,
|
||||
"AllowVideoUploads": true,
|
||||
|
|
|
@ -399,7 +399,7 @@ $jq(document).ready(function() {
|
|||
topbar = $jq("div#topbar");
|
||||
var settings_html = "<table width=\"100%\"><colgroup><col span=\"1\" width=\"50%\"><col span=\"1\" width=\"50%\"></colgroup><tr><td><b>Style:</b></td><td><select name=\"style\" style=\"min-width:50%\">"
|
||||
for(var i = 0; i < styles.length; i++) {
|
||||
settings_html += "<option value=\""+styles[i]+"\">"+styles[i][0].toUpperCase()+styles[i].substring(1,styles[i].length);
|
||||
settings_html += "<option value=\""+styles[i].Filename+"\">"+styles[i].Name;
|
||||
}
|
||||
settings_html+="</select></td><tr><tr><td><b>Pin top bar:</b></td><td><input type=\"checkbox\" /></td></tr><tr><td><b>Enable post previews on hover</b></td><td><input type=\"checkbox\" /></td></tr></table><div class=\"lightbox-footer\"><hr /><button id=\"save-settings-button\">Save Settings</button></div>"
|
||||
|
||||
|
|
|
@ -249,12 +249,13 @@ var manage_functions = map[string]ManageFunction{
|
|||
config.SiteSlogan = request.PostFormValue("SiteSlogan")
|
||||
config.SiteHeaderURL = request.PostFormValue("SiteHeaderURL")
|
||||
config.SiteWebfolder = request.PostFormValue("SiteWebfolder")
|
||||
Styles_arr := strings.Split(request.PostFormValue("Styles"), "\n")
|
||||
// TODO: Change this to match the new Style type in gochan.json
|
||||
/* Styles_arr := strings.Split(request.PostFormValue("Styles"), "\n")
|
||||
var Styles []string
|
||||
for _, style := range Styles_arr {
|
||||
Styles = append(Styles, strings.Trim(style, " \n\r"))
|
||||
}
|
||||
config.Styles = Styles
|
||||
config.Styles = Styles */
|
||||
config.DefaultStyle = request.PostFormValue("DefaultStyle")
|
||||
config.AllowDuplicateImages = (request.PostFormValue("AllowDuplicateImages") == "on")
|
||||
config.AllowVideoUploads = (request.PostFormValue("AllowVideoUploads") == "on")
|
||||
|
|
29
src/types.go
29
src/types.go
|
@ -350,6 +350,11 @@ type ErrorJSON struct {
|
|||
Message string `json:"error"`
|
||||
}
|
||||
|
||||
type Style struct {
|
||||
Name string
|
||||
Filename string
|
||||
}
|
||||
|
||||
// GochanConfig stores crucial info and is read from/written to gochan.json
|
||||
type GochanConfig struct {
|
||||
ListenIP string
|
||||
|
@ -385,8 +390,8 @@ type GochanConfig struct {
|
|||
SiteDomain string `description:"The server's domain (duh). Do not edit this unless you know what you are doing or BAD THINGS WILL HAPPEN!" default:"127.0.0.1" critical:"true"`
|
||||
DomainRegex string `description:"Regular expression used for incoming request validation. Do not edit this unless you know what you are doing or BAD THINGS WILL HAPPEN!" default:"(https|http):\\\\/\\\\/(gochan\\\\.lunachan\\.net|gochan\\\\.org)\\/(.*)" critical:"true"`
|
||||
|
||||
Styles []string `description:"List of styles (one per line) that should be accessed online at /<SiteWebFolder>/css/<Style>/"`
|
||||
DefaultStyle string `description:"Style used by default (duh). This should appear in the list above or bad things might happen."`
|
||||
Styles []Style `description:"List of styles (one per line) that should be accessed online at <SiteWebFolder>/css/<Style>/"`
|
||||
DefaultStyle string `description:"Filename of the default Style. This should appear in the list above or bad things might happen."`
|
||||
|
||||
AllowDuplicateImages bool `description:"Disabling this will cause gochan to reject a post if the image has already been uploaded for another post.<br />This may end up being removed or being made board-specific in the future." default:"checked"`
|
||||
AllowVideoUploads bool `description:"Allows users to upload .webm videos. <br />This may end up being removed or being made board-specific in the future."`
|
||||
|
@ -438,7 +443,23 @@ func initConfig() {
|
|||
}
|
||||
|
||||
if err = json.Unmarshal(jfile, &config); err != nil {
|
||||
printf(0, "Error parsing \"gochan.json\": %s\n", err.Error())
|
||||
errStr := err.Error()
|
||||
switch errStr {
|
||||
case "json: cannot unmarshal string into Go struct field GochanConfig.Styles of type main.Style":
|
||||
printf(0, `Error parsing gochan.json. config.Styles has been changed from a string array to an object.
|
||||
Each Style in gochan.json must have a Name field that will appear in the style dropdowns and a Filename field. For example
|
||||
{
|
||||
"Styles": [
|
||||
{"Name": "Pipes", "Filename": "pipes.css"},
|
||||
{"Name": "Burichan", "Filename": "burichan.css"}
|
||||
],
|
||||
}
|
||||
DefaultStyle must refer to a given Style's Filename field. If DefaultStyle does not appear in gochan.json, the first element in Styles will be used.
|
||||
`)
|
||||
default:
|
||||
printf(0, "Error parsing \"gochan.json\": %s\n", err.Error())
|
||||
}
|
||||
|
||||
os.Exit(2)
|
||||
}
|
||||
|
||||
|
@ -578,7 +599,7 @@ func initConfig() {
|
|||
}
|
||||
|
||||
if config.DefaultStyle == "" {
|
||||
config.DefaultStyle = config.Styles[0]
|
||||
config.DefaultStyle = config.Styles[0].Filename
|
||||
}
|
||||
|
||||
if config.NewThreadDelay == 0 {
|
||||
|
|
|
@ -4,9 +4,9 @@
|
|||
<title>Banned</title>
|
||||
<link rel="shortcut icon" href="/favicon.png">
|
||||
<link rel="stylesheet" href="{{$.config.SiteWebfolder}}css/global.css" />
|
||||
<link rel="stylesheet" href="{{$.config.SiteWebfolder}}css/{{$.config.DefaultStyle}}.css" />
|
||||
<link rel="stylesheet" href="{{$.config.SiteWebfolder}}css/{{$.config.DefaultStyle}}" />
|
||||
<script type="text/javascript">
|
||||
var styles = [{{range $i, $style := .config.Styles}}{{if gt $i 0}}, {{end}}"{{$style}}"{{end}}];
|
||||
var styles = [{{range $ii, $style := .config.Styles}}{{if gt $ii 0}}, {{end}}{Name: "{{$style.Name}}", Filename: "{{$style.Filename}}"}{{end}}];
|
||||
var webroot = "{{.config.SiteWebfolder}}"
|
||||
</script>
|
||||
<script type="text/javascript" src="/javascript/jquery-3.3.1.min.js"></script>
|
||||
|
|
|
@ -6,14 +6,14 @@
|
|||
<title>{{.config.SiteName}}</title>
|
||||
<script type="text/javascript" src="{{.config.SiteWebfolder}}javascript/jquery-3.3.1.min.js"></script>
|
||||
<script type="text/javascript">
|
||||
var styles = [{{range $ii, $style := .config.Styles}}{{if gt $ii 0}}, {{end}}"{{$style}}"{{end}}];
|
||||
var styles = [{{range $ii, $style := .config.Styles}}{{if gt $ii 0}}, {{end}}{Name: "{{$style.Name}}", Filename: "{{$style.Filename}}"}{{end}}];
|
||||
var webroot = "{{.config.SiteWebfolder}}"
|
||||
</script>
|
||||
<script type="text/javascript" src="{{.config.SiteWebfolder}}javascript/gochan.js"></script>
|
||||
<script type="text/javascript" src="{{.config.SiteWebfolder}}javascript/manage.js"></script>
|
||||
|
||||
<link rel="stylesheet" href="/css/global.css" />
|
||||
<link rel="stylesheet" href="/css/{{.config.DefaultStyle}}.css" />
|
||||
<link rel="stylesheet" href="/css/{{.config.DefaultStyle}}" />
|
||||
<link rel="shortcut icon" href="/favicon.png">
|
||||
</head>
|
||||
<body>
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
{{else}}<title>/{{.board.Dir}}/ - {{.board.Title}}</title>{{end}}
|
||||
<script type="text/javascript" src="{{$.config.SiteWebfolder}}javascript/jquery-3.3.1.min.js"></script>
|
||||
<script type="text/javascript">
|
||||
var styles = [{{range $ii, $style := $.config.Styles}}{{if gt $ii 0}}, {{end}}"{{$style}}"{{end}}];
|
||||
var styles = [{{range $ii, $style := .config.Styles}}{{if gt $ii 0}}, {{end}}{Name: "{{$style.Name}}", Filename: "{{$style.Filename}}"}{{end}}];
|
||||
var webroot = "{{$.config.SiteWebfolder}}";
|
||||
var thread_type = "thread";
|
||||
|
||||
|
@ -23,7 +23,7 @@
|
|||
<script type="text/javascript" src="{{$.config.SiteWebfolder}}javascript/gochan.js"></script>
|
||||
<script type="text/javascript" src="{{$.config.SiteWebfolder}}javascript/manage.js"></script>
|
||||
<link rel="stylesheet" href="{{$.config.SiteWebfolder}}css/global.css" />
|
||||
<link rel="stylesheet" href="{{$.config.SiteWebfolder}}css/{{$.config.DefaultStyle}}.css" />
|
||||
<link rel="stylesheet" href="{{$.config.SiteWebfolder}}css/{{$.config.DefaultStyle}}" />
|
||||
<link rel="shortcut icon" href="{{$.config.SiteWebfolder}}favicon.png" />
|
||||
</head>
|
||||
<body>
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
<title>Gochan Manage page</title>
|
||||
<link rel="stylesheet" href="{{.SiteWebfolder}}css/global.css" />
|
||||
<link rel="stylesheet" href="{{$.SiteWebfolder}}css/{{.DefaultStyle}}.css" />
|
||||
<link rel="stylesheet" href="{{$.SiteWebfolder}}css/{{.DefaultStyle}}" />
|
||||
<link rel="shortcut icon" href="{{.SiteWebfolder}}favicon.png" />
|
||||
<script type="text/javascript">
|
||||
var styles = [{{range $i, $style := .Styles}}{{if gt $i 0}}, {{end}}"{{$style}}"{{end}}];
|
||||
var styles = [{{range $ii, $style := .Styles}}{{if gt $ii 0}}, {{end}}{Name: "{{$style.Name}}", Filename: "{{$style.Filename}}"}{{end}}];
|
||||
var webroot = "{{.SiteWebfolder}}"
|
||||
</script>
|
||||
<script type="text/javascript" src="{{.SiteWebfolder}}javascript/jquery-3.3.1.min.js"></script>
|
||||
|
|
|
@ -6,14 +6,14 @@
|
|||
<title>Edit Post</title>
|
||||
<script type="text/javascript" src="/javascript/jquery-3.3.1.min.js"></script>
|
||||
<script type="text/javascript">
|
||||
var styles = [{{range $ii, $style := $.config.Styles}}{{if gt $ii 0}}, {{end}}"{{$style}}"{{end}}];
|
||||
var styles = [{{range $ii, $style := .config.Styles}}{{if gt $ii 0}}, {{end}}{Name: "{{$style.Name}}", Filename: "{{$style.Filename}}"}{{end}}];
|
||||
var webroot = "{{$.config.SiteWebfolder}}";
|
||||
</script>
|
||||
<script type="text/javascript" src="/javascript/gochan.js"></script>
|
||||
<script type="text/javascript" src="/javascript/manage.js"></script>
|
||||
<link rel="stylesheet" href="/css/global/img.css" />
|
||||
{{range $_, $style := .config.Styles}}
|
||||
<link rel="{{if not (isStyleDefault $style)}}alternate {{end}}stylesheet" href="/css/{{$style}}/img.css" />{{end}}
|
||||
<link rel="stylesheet" href="/css/{{$style.Filename}}" />{{end}}
|
||||
<link rel="shortcut icon" href="/favicon.png" />
|
||||
</head>
|
||||
<body>
|
||||
|
@ -31,7 +31,7 @@
|
|||
<table id="postbox-static" align="center">
|
||||
<tr><th class="postblock">Name</th><td>{{stringAppend .post.Name "#" .post.Tripcode}}</td></tr>
|
||||
<tr><th class="postblock">Email</th><td>{{.post.Email}}</td></tr>
|
||||
<tr><th class="postblock">Subject</th><td><input type="text" name="editsubject" maxlength="100" size="30" autocomplete="off" value="{{.post.Subject}}"/><input type="submit" value="{{with .op}}Reply{{else}}Post{{end}}"/></td></tr>
|
||||
<tr><th class="postblock">Subject</th><td><input type="text" name="editsubject" maxlength="100" size="28" autocomplete="off" value="{{.post.Subject}}"/><input type="submit" value="{{with .op}}Reply{{else}}Post{{end}}"/></td></tr>
|
||||
<tr><th class="postblock">Message</th><td><textarea rows="4" cols="48" name="editmsg" id="editmsg">{{.post.MessageText}}</textarea></td></tr>
|
||||
</table>
|
||||
</form><br />
|
||||
|
|
|
@ -7,9 +7,10 @@
|
|||
<input type="hidden" name="boardid" value="{{$.board.ID}}" />{{end}}
|
||||
<input type="text" name="username" style="display:none" />
|
||||
<table id="postbox-static">
|
||||
<tr><th class="postblock">Name</th><td><input type="text" id="postname" name="postname" maxlength="50" size="28" {{/* value="Name" onFocus="if(this.value=='Name') {this,value= ''}" onBlur="if(this.value == '') {this.value = 'Name'}"*/}}/></td></tr>
|
||||
<tr><th class="postblock">Email</th><td><input type="text" id="postemail" name="postemail" maxlength="50" size="28" /></td></tr>
|
||||
<tr><th class="postblock">Subject</th><td><input type="text" id="postsubject" name="postsubject" maxlength="100" size="30"/><input type="submit" value="{{with .op}}Reply{{else}}Post{{end}}"/></td></tr>
|
||||
<tr><th class="postblock">Name</th><td><input type="text" name="postname" maxlength="100" size="28" /></td></tr>
|
||||
<tr><th class="postblock">Email</th><td><input type="text" name="postemail" maxlength="100" size="28" /></td></tr>
|
||||
<tr><th class="postblock">Subject</th><td><input type="text" name="postsubject" size="28" maxlength="100" autocomplete="off"><input type="submit" value="{{with .op}}Reply{{else}}Post{{end}}" autocomplete="off"/></td></tr>
|
||||
|
||||
<tr><th class="postblock">Message</th><td><textarea rows="4" cols="48" name="postmsg" id="postmsg"></textarea></td></tr>
|
||||
<tr><th class="postblock">File</th><td><input name="imagefile" type="file"><input type="checkbox" id="spoiler" name="spoiler"/><label for="spoiler">Spoiler</label></td></tr>
|
||||
<tr><th class="postblock">Password</th><td><input type="password" id="postpassword" name="postpassword" size="14" /> (for post/file deletion)</td></tr>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue