2017-05-22 18:25:04 +02:00
package categories
import (
"github.com/NyaaPantsu/nyaa/config"
)
var categories map [ string ] string
2017-05-26 12:12:52 +02:00
// GetCategories : function to get all categories depending on the actual website from config/categories.go
2017-05-22 18:25:04 +02:00
func GetCategories ( ) map [ string ] string {
if categories != nil {
return categories
}
if config . IsSukebei ( ) {
2017-05-31 04:21:57 +02:00
categories = config . Conf . Torrents . SukebeiCategories
2017-05-22 18:25:04 +02:00
} else {
2017-05-31 04:21:57 +02:00
categories = config . Conf . Torrents . CleanCategories
2017-05-22 18:25:04 +02:00
}
return categories
}
2017-05-26 12:12:52 +02:00
// CategoryExists : Check if a category exist in config
2017-05-22 18:25:04 +02:00
func CategoryExists ( category string ) bool {
_ , exists := GetCategories ( ) [ category ]
return exists
}
2017-05-23 04:05:33 +02:00
2017-05-26 12:12:52 +02:00
// GetCategoriesSelect : Format categories in map ordered alphabetically
2017-06-17 04:24:30 +02:00
func GetCategoriesSelect ( keepParent bool , keepChild bool ) map [ string ] string {
2017-05-24 09:11:13 +02:00
categories := GetCategories ( )
2017-05-23 04:05:33 +02:00
catSelect := make ( map [ string ] string , len ( categories ) )
for k , v := range categories {
2017-06-17 04:24:30 +02:00
if ( keepParent && keepChild ) || ( len ( k ) > 2 && ! keepParent ) || ( len ( k ) <= 2 && ! keepChild ) {
2017-05-23 04:05:33 +02:00
catSelect [ v ] = k
}
}
return catSelect
2017-05-24 09:11:13 +02:00
}