diff options
-rw-r--r-- | client.go | 7 | ||||
-rw-r--r-- | main.go | 19 | ||||
-rw-r--r-- | static/css/themes/default.css (renamed from static/css/style.css) | 0 | ||||
-rw-r--r-- | static/css/themes/gruvbox.css (renamed from static/css/gruvbox.css) | 0 | ||||
-rw-r--r-- | static/js/themes.js | 6 | ||||
-rw-r--r-- | static/main.html | 13 |
6 files changed, 43 insertions, 2 deletions
@@ -53,6 +53,7 @@ type PageData struct { ReturnTo string NewsItems []NewsItem BoardRemainer []int + Themes *[]string } type AdminPage struct { @@ -271,6 +272,8 @@ func OutboxGet(w http.ResponseWriter, r *http.Request, db *sql.DB, collection Co returnData.Pages = pages returnData.TotalPage = len(returnData.Pages) - 1 + returnData.Themes = &Themes + t.ExecuteTemplate(w, "layout", returnData) } @@ -374,6 +377,8 @@ func ArchiveGet(w http.ResponseWriter, r *http.Request, db *sql.DB, collection C returnData.Posts = collection.OrderedItems + returnData.Themes = &Themes + t.ExecuteTemplate(w, "layout", returnData) } @@ -467,6 +472,8 @@ func PostGet(w http.ResponseWriter, r *http.Request, db *sql.DB) { returnData.PostId = shortURL(returnData.Board.To, returnData.Posts[0].Id) } + returnData.Themes = &Themes + t.ExecuteTemplate(w, "layout", returnData) } @@ -19,6 +19,7 @@ import ( "net/url" "os" "os/exec" + "path" "regexp" "strconv" "strings" @@ -51,6 +52,8 @@ var MediaHashs = make(map[string]string) var ActorCache = make(map[string]Actor) +var Themes []string + func main() { CreatedNeededDirectories() @@ -84,6 +87,22 @@ func main() { } } + // get list of themes + themes, err := ioutil.ReadDir("./static/css/themes") + if err != nil { + panic(err) + } + + for _, f := range themes { + if f.Name() == "default" { + continue + } + + if e := path.Ext(f.Name()); e == ".css" { + Themes = append(Themes, strings.TrimSuffix(f.Name(), e)) + } + } + // Allow access to public media folder fileServer := http.FileServer(http.Dir("./public")) http.Handle("/public/", http.StripPrefix("/public", neuter(fileServer))) diff --git a/static/css/style.css b/static/css/themes/default.css index fa76b50..fa76b50 100644 --- a/static/css/style.css +++ b/static/css/themes/default.css diff --git a/static/css/gruvbox.css b/static/css/themes/gruvbox.css index fb39ea4..fb39ea4 100644 --- a/static/css/gruvbox.css +++ b/static/css/themes/gruvbox.css diff --git a/static/js/themes.js b/static/js/themes.js index 0d9772f..19bdbb4 100644 --- a/static/js/themes.js +++ b/static/js/themes.js @@ -20,5 +20,11 @@ function setTheme(name) { } function applyTheme() { + // HACK: disable all of the themes first. this for some reason makes things work. + for (let i = 0, tags = document.getElementsByTagName("link"); i < tags.length; i++) { + if (tags[i].type === "text/css" && tags[i].title) { + tags[i].disabled = true; + } + } setTheme(getCookie("theme") || "default"); } diff --git a/static/main.html b/static/main.html index 3fa1b66..9a88afc 100644 --- a/static/main.html +++ b/static/main.html @@ -8,8 +8,10 @@ <meta property="og:locale" content="en_US" /> <meta property="og:type" content="website" /> <link rel="icon" type="image/png" href="/static/favicon.png"> - <link rel="stylesheet" type="text/css" href="/static/css/style.css" title="default"> - <link rel="alternate stylesheet" type="text/css" href="/static/css/gruvbox.css" title="gruvbox"> + <link rel="stylesheet" type="text/css" href="/static/css/themes/default.css" title="default"> + {{ range .Themes }} + <link rel="alternate stylesheet" type="text/css" href="/static/css/themes/{{.}}.css" title="{{.}}"> + {{ end }} {{ template "header" . }} </head> <body {{ if not .Board.Restricted }}class="nsfw"{{ end }} onload="applyTheme()"> @@ -38,6 +40,13 @@ {{ template "content" . }} {{ template "bottom" . }} + + <select onchange="setTheme(this.options[this.selectedIndex].value)"> + {{ range .Themes }} + <option value="{{.}}">{{.}}</option> + {{ end }} + </select> + <div align="center" style="width: 500px; margin:0 auto; margin-top: 50px;"> <a href="/">[Home]</a><a href="/static/rules.html">[Rules]</a><a href="/static/faq.html">[FAQ]</a> <p>All trademarks and copyrights on this page are owned by their respective parties.</p> |