* Add themeToggle handler to router.go * Create themeToggle/router.go & ThemeToggle.go * Add link to /dark in footer, remove display = none on toggle dark mode * Remove JS that ordered toggle dark mode link to show as it is now constantly visible * Rollback to fix errors * Add some comments * Create redirectUrl variable & set it's content then use it to redirect user * Remove useless log * Remove usage of fmt * Add redirect get parameter to toggle link * Add another url for toggleTheme * wooo * Update base.jet.html * Update base.jet.html
41 lignes
1,1 Kio
Go
41 lignes
1,1 Kio
Go
package themeToggleController
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/NyaaPantsu/nyaa/config"
|
|
"github.com/NyaaPantsu/nyaa/utils/timeHelper"
|
|
"github.com/gin-gonic/gin"
|
|
|
|
)
|
|
|
|
// toggleThemeHandler : Controller to switch between theme1 & theme2
|
|
func toggleThemeHandler(c *gin.Context) {
|
|
|
|
//Get theme1 & theme2 value, set g.css & tomorrow.css by default
|
|
theme, err := c.Cookie("theme")
|
|
if err != nil {
|
|
theme = "g"
|
|
}
|
|
theme2, err := c.Cookie("theme2")
|
|
if err != nil {
|
|
theme2 = "tomorrow"
|
|
}
|
|
|
|
//Switch theme & theme2 value
|
|
http.SetCookie(c.Writer, &http.Cookie{Name: "theme", Value: theme2, Domain: getDomainName(), Path: "/", Expires: timeHelper.FewDaysLater(365)})
|
|
http.SetCookie(c.Writer, &http.Cookie{Name: "theme2", Value: theme, Domain: getDomainName(), Path: "/", Expires: timeHelper.FewDaysLater(365)})
|
|
|
|
//Redirect user to page he was beforehand
|
|
c.Redirect(http.StatusSeeOther, c.Param("redirect") + "#footer")
|
|
return
|
|
}
|
|
|
|
func getDomainName() string {
|
|
domain := config.Get().Cookies.DomainName
|
|
if config.Get().Environment == "DEVELOPMENT" {
|
|
domain = ""
|
|
}
|
|
return domain
|
|
}
|