103 lines
2.3 KiB
Go
103 lines
2.3 KiB
Go
package domain
|
|
|
|
import (
|
|
"image"
|
|
"net/url"
|
|
"path"
|
|
"path/filepath"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
type Site struct {
|
|
DefaultLanguage Language
|
|
Language Language
|
|
Languages []Language
|
|
BaseURL *url.URL
|
|
Params map[string]any
|
|
TimeZone *time.Location
|
|
File Path
|
|
Title string
|
|
Resources Resources
|
|
}
|
|
|
|
func (s Site) LanguagePrefix() string {
|
|
if s.Language != LanguageUnd {
|
|
return path.Join("/", s.Language.lang, "/")
|
|
}
|
|
|
|
return ""
|
|
}
|
|
|
|
func (s Site) IsMultiLingual() bool {
|
|
return 1 < len(s.Languages)
|
|
}
|
|
|
|
func TestSite(tb testing.TB) *Site {
|
|
tb.Helper()
|
|
|
|
ru := NewLanguage("ru")
|
|
en := NewLanguage("en")
|
|
|
|
return &Site{
|
|
DefaultLanguage: en,
|
|
Language: ru,
|
|
Languages: []Language{en, ru},
|
|
BaseURL: &url.URL{Scheme: "https", Host: "example.com", Path: "/"},
|
|
TimeZone: time.UTC,
|
|
File: NewPath(filepath.Join("content", "index.en.md")),
|
|
Title: "Testing",
|
|
Resources: []*Resource{
|
|
{
|
|
modTime: time.Now().UTC().Add(-1 * time.Hour),
|
|
params: make(map[string]any),
|
|
File: NewPath("photo.png"),
|
|
mediaType: NewMediaType("image/png"),
|
|
key: "photo",
|
|
name: "photo",
|
|
resourceType: ResourceTypeImage,
|
|
title: "",
|
|
image: image.Config{},
|
|
},
|
|
{
|
|
modTime: time.Now().UTC().Add(-2 * time.Hour),
|
|
params: make(map[string]any),
|
|
File: NewPath("logo.jpg"),
|
|
mediaType: NewMediaType("image/jpeg"),
|
|
key: "logo",
|
|
name: "logo",
|
|
resourceType: ResourceTypeImage,
|
|
title: "",
|
|
image: image.Config{},
|
|
},
|
|
},
|
|
Params: map[string]any{
|
|
"server": map[string]any{
|
|
"headers": []any{map[string]any{
|
|
"path": "/**",
|
|
"values": map[string]any{
|
|
"Link": `<https://auth.example.com/>; rel="indieauth-metadata", ` +
|
|
`<https://pub.example.com/>; rel="micropub"`,
|
|
"X-Koroko": "Ya-ha-ha!",
|
|
},
|
|
}, map[string]any{
|
|
"path": "/foo/bar",
|
|
"values": map[string]any{
|
|
"X-Testing": `sample-text`,
|
|
},
|
|
}},
|
|
"redirects": []any{map[string]any{
|
|
"from": "/foo/bar",
|
|
"to": "/bar/foo",
|
|
"status": 302,
|
|
}, map[string]any{
|
|
"from": "/foo",
|
|
"to": "https://example.com/",
|
|
"status": 301,
|
|
"force": true,
|
|
}},
|
|
},
|
|
},
|
|
}
|
|
}
|