Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0

Default & dark theme set in .yml (#1610)

* Update default_config.yml

* Update publicSettings.go

* Update base.jet.html

* Update config.go

* Update structs.go

* Update base.jet.html

* Update base.jet.html

* Update main.js

* Update base.jet.html

* Update base.jet.html

* Update publicSettings.go

* Update template.go

* Update template_test.go

* Update template.go

* Update classic.css

* allow user profile URl to contain just ID

* Update router.go

* Add nyaa.pt to mirrors

* Update main.js

* Update main.js

* Add /username/:username userprofile route

* Update profile.go
Cette révision appartient à :
kilo 2017-09-22 06:54:19 +02:00 révisé par ewhal
Parent 7328a71291
révision 6ca8ffe5fc
12 fichiers modifiés avec 70 ajouts et 22 suppressions

Voir le fichier

@ -39,6 +39,15 @@ func WebAddress() string {
}
}
// DefaultTheme : Return the default theme or default dark theme
func DefaultTheme(dark bool) string {
if !dark {
return Get().DefaultTheme.Theme
} else {
return Get().DefaultTheme.Dark
}
}
var allowedDatabaseTypes = map[string]bool{
"sqlite3": true,
"postgres": true,

Voir le fichier

@ -216,3 +216,7 @@ models:
activities_table_name: activities
# NotificationTableName : Name of scrape table in DB
scrape_table_name: scrape
#Default themes
default_theme:
theme: g
dark: tomorrow

Voir le fichier

@ -48,6 +48,8 @@ type Config struct {
Email EmailConfig `yaml:"email,flow,omitempty"`
// models config
Models ModelsConfig `yaml:"models,flow,omitempty"`
// Default Theme config
DefaultTheme DefaultThemeConfig `yaml:"default_theme,flow,omitempty"`
}
// Tags Config struct for tags in torrent
@ -207,6 +209,11 @@ type ModelsConfig struct {
ScrapeTableName string `yaml:"scrape_table_name,omitempty"`
}
type DefaultThemeConfig struct {
Theme string `yaml:"theme,omitempty"`
Dark string `yaml:"dark,omitempty"`
}
// SearchConfig : Config struct for search
type SearchConfig struct {
EnableElasticSearch bool `yaml:"enable_es,omitempty"`

Voir le fichier

@ -3,6 +3,7 @@ package userController
import (
"strconv"
"time"
"fmt"
"net/http"
@ -56,6 +57,19 @@ func UserProfileHandler(c *gin.Context) {
}
}
func UserGetFromName(c *gin.Context) {
username := c.Param("username")
if(username != "") {
user, _, _, err := users.FindByUsername(username)
if err == nil {
c.Redirect(http.StatusSeeOther, fmt.Sprintf("/user/%d/%s", uint32(user.ID), username))
return
}
}
c.Status(http.StatusNotFound)
}
// UserDetailsHandler : Getting User Profile Details View
func UserDetailsHandler(c *gin.Context) {
id, _ := strconv.ParseUint(c.Param("id"), 10, 32)

Voir le fichier

@ -25,6 +25,7 @@ func init() {
// User Profile specific routes
userRoutes := router.Get().Group("/user")
{
userRoutes.GET("/:id", UserProfileHandler)
userRoutes.GET("/:id/:username", UserProfileHandler)
userRoutes.GET("/:id/:username/follow", UserFollowHandler)
userRoutes.GET("/:id/:username/edit", UserDetailsHandler)
@ -33,4 +34,6 @@ func init() {
userRoutes.GET("/:id/:username/feed", feedController.RSSHandler)
userRoutes.GET("/:id/:username/feed/:page", feedController.RSSHandler)
}
router.Get().Any("/username/:username", UserGetFromName)
}

Voir le fichier

@ -647,6 +647,10 @@ span.tag {
border-radius: 0;
padding: 7px 3px;
}
.upload-tag-table .form-group input, .upload-tag-table .form-group select {
width: 118px!important;
.upload-tag-table .form-group {
margin-right: 8px;
}
.upload-tag-table .form-group input, .upload-tag-table .form-group select {
width: 118px!important;
height: 20px;
}

Voir le fichier

@ -94,6 +94,7 @@ function resetCookies() {
//Get HostName without subDomain
var hostName = window.location.host
var lastDotIndex = hostName.lastIndexOf(".")
var secondLast = -1
@ -102,7 +103,7 @@ function resetCookies() {
secondLast = index
}
hostName = hostName.substr(secondLast == -1 ? 0 : secondLast)
if(!hostName.includes(domain)) domain = window.location.host
for (var i = 0; i < cookies.length; i++) {
var cookieName = (cookies[i].split("=")[0]).trim()
@ -173,28 +174,28 @@ function startupCode() {
document.getElementById("dark-toggle").addEventListener("click", toggleTheme);
if(document.cookie.includes("theme=")) {
UserTheme = [getCookieValue("theme"), "tomorrow"]
//Get user's default theme and set the alternative one as tomorrow
UserTheme = [getCookieValue("theme"), darkTheme]
//Get user's default theme and set the alternative one as dark theme
}
else
UserTheme = ["g", "tomorrow"]
UserTheme = ["g", darkTheme]
//If user has no default theme, set these by default
if(document.cookie.includes("theme2=")) {
UserTheme[1] = getCookieValue("theme2")
//If user already has ran the ToggleTheme() function in the past, we get the value of the second theme (the one the script switches to)
if(!UserTheme.includes("tomorrow"))
UserTheme[1] = "tomorrow"
//If none of the theme are tomorrow, which happens if the user is on dark mode (with theme2 on g.css) and that he switches to classic or g.css in settings, we set the second one as tomorrow
if(!UserTheme.includes(darkTheme))
UserTheme[1] = darkTheme
//If none of the theme are darkTheme, which happens if the user is on dark mode (with theme2 on g.css) and that he switches to classic or g.css in settings, we set the second one as darkTheme
else if(UserTheme[0] == UserTheme[1])
UserTheme[1] = "g"
//If both theme are tomorrow, which happens if theme2 is on tomorrow (always is by default) and that the user sets tomorrow as his theme through settings page, we set secondary theme to g.css
//If both theme are darkTheme, which happens if theme2 is on darkTheme (always is by default) and that the user sets darkTheme as his theme through settings page, we set secondary theme to g.css
}
else {
if(UserTheme[0] == UserTheme[1])
UserTheme[1] = "g"
//If tomorrow is twice in UserTheme, which happens when the user already has tomorrow as his default theme and toggle the dark mode for the first time, we set the second theme as g.css
//If darkTheme is twice in UserTheme, which happens when the user already has darkTheme as his default theme and toggle the dark mode for the first time, we set the second theme as g.css
document.cookie = "theme2=" + UserTheme[1] + ";path=/;expires=" + farFutureString + ";domain=" + domain
//Set cookie for future theme2 uses
}

Voir le fichier

@ -32,12 +32,8 @@
<link rel="stylesheet" id="style" href="/css/main.css?v={{ Config.Version }}{{ Config.Build }}"/>
<!-- nyaacon, custom icon set -->
<link rel="stylesheet" href="/css/nyacon.css?v={{ Config.Version}}{{ Config.Build }}"/>
<!-- User selected theme, if any, defaults to /g/ -->
{{if Theme == ""}}
<link rel="stylesheet" id="theme" href="/css/g.css?v={{ Config.Version }}{{ Config.Build }}"/>
{{else}}
<!-- User selected theme, if empty defaults to theme in nyaa.yml -->
<link rel="stylesheet" id="theme" href="/css/{{Theme}}.css?v={{ Config.Version }}{{ Config.Build }}"/>
{{end}}
<!-- Flags css -->
<link rel="stylesheet" href="/css/flags/flags.min.css"/>
<!-- Search Box for Google -->
@ -96,7 +92,13 @@
</div>
</footer>
</div>
<script type="text/javascript">var commitVersion = "{{ Config.Build }}", websiteVersion = "{{ Config.Version }}", UserID = {{User.ID}}, domain = "{{getDomainName()}}";</script>
<script type="text/javascript">
var commitVersion = "{{ Config.Build }}",
websiteVersion = "{{ Config.Version }}",
UserID = {{User.ID}},
domain = "{{getDomainName()}}",
darkTheme = "{{DarkTheme}}";
</script>
<script type="text/javascript" src="/js/query.js?v={{ Config.Version}}{{ Config.Build }}"></script>
<script type="text/javascript" charset="utf-8" src="/js/main.js?v={{ Config.Version }}{{ Config.Build }}" async></script>
{{block footer_js()}}{{end}}

Voir le fichier

@ -14,8 +14,10 @@
<h2 id="links">{{ T("links_replacement_mirror")}}</h2>
<a href="{{Config.WebAddress.Nyaa}}">Nyaa - {{GetHostname(Config.WebAddress.Nyaa)}}</a><br />
<a href="{{Config.WebAddress.Sukebei}}">Sukebei - {{GetHostname(Config.WebAddress.Sukebei)}}</a><br />
<a href="https://nyoo.moe/">Nyaa - {{GetHostname("https://nyoo.moe/")}} (Mirror)</a><br />
<a href="https://sukebei.nyoo.moe/">Sukebei - {{GetHostname("https://sukebei.nyoo.moe/")}} (Mirror)</a>
<a href="https://nyoo.moe/">Nyaa - https://nyoo.moe/ (Mirror)</a><br />
<a href="https://sukebei.nyoo.moe/">Sukebei - https://sukebei.nyoo.moe/ (Mirror)</a><br />
<a href="https://nyaa.pt/">Nyaa - https://nyaa.pt/ (Mirror)</a><br />
<a href="https://sukebei.nyaa.pt/">Sukebei - https://sukebei.nyaa.pt/ (Mirror)</a>
<h2 id="server_status">{{ T("server_status_link")}}</h2>

Voir le fichier

@ -52,7 +52,8 @@ func Commonvariables(c *gin.Context) jet.VarMap {
variables.Set("Navigation", NewNavigation())
variables.Set("Search", NewSearchForm(c))
variables.Set("T", publicSettings.GetTfuncFromRequest(c))
variables.Set("Theme", publicSettings.GetThemeFromRequest(c))
variables.Set("Theme", publicSettings.GetThemeFromRequest(c, false))
variables.Set("DarkTheme", publicSettings.GetThemeFromRequest(c, true))
variables.Set("AltColors", publicSettings.GetAltColorsFromRequest(c))
variables.Set("OldNav", publicSettings.GetOldNavFromRequest(c))
variables.Set("Mascot", publicSettings.GetMascotFromRequest(c))

Voir le fichier

@ -281,6 +281,7 @@ func mockupCommonvariables(t *testing.T) jet.VarMap {
}
variables.Set("T", T)
variables.Set("Theme", "test")
variables.Set("DarkTheme", "test")
variables.Set("AltColors", "test")
variables.Set("OldNav", "test")
variables.Set("Mascot", "test")

Voir le fichier

@ -171,7 +171,7 @@ func GetTfuncFromRequest(c *gin.Context) TemplateTfunc {
}
// GetThemeFromRequest : Gets the user selected theme from the request
func GetThemeFromRequest(c *gin.Context) string {
func GetThemeFromRequest(c *gin.Context, dark bool) string {
user, _ := getCurrentUser(c)
if user.ID > 0 {
return user.Theme
@ -180,7 +180,7 @@ func GetThemeFromRequest(c *gin.Context) string {
if err == nil {
return cookie
}
return ""
return config.DefaultTheme(dark)
}
// GetAltColorsFromRequest : Return whether user has enabled alt colors or not