~huyngo/yue

ref: b50ae276f4fe44a2ffdb8bfe33dbec379b126ab2 yue/structs.go -rw-r--r-- 1.7 KiB
b50ae276Huy Ngo Add about page to footer 11 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package main

import (
	"time"

	"github.com/leonelquinteros/gotext"
)

type RequestContext struct {
	Lang     string
	Loc      *gotext.Locale
	Page     *PageData
	Setting  *Preference
	LoggedIn *User
	Yue      *Meta
	Data     interface{}
}

type PageData struct {
	Title       string
	Description string
}

type Preference struct {
	Theme string
}

type TimelinePage struct {
	Name  string
	Posts []Post
	Next  string
}

type Post struct {
	Id        int
	Title     string
	Content   string
	Author    User
	Comm      Community
	Created   time.Time
	Local     bool
	Instance  string
	RemoteURL string
	Score     int
	Sticky    bool
	Comments  []Comment
}

type Comment struct {
	Id              int
	Content         string
	Author          User
	Created         time.Time
	Local           bool
	Instance        string
	RemoteURL       string
	Score           int
	PostId          int
	ParentCommentId int
	Replies         []Comment
}

type Community struct {
	Id        int
	Name      string
	Local     bool
	Instance  string
	RemoteURL string
}

type User struct {
	Id        int
	Username  string
	Bot       bool
	AvatarURL string
	Local     bool
	Instance  string
	RemoteURL string
}

type Meta struct {
	Version string
}

func CreateRequestContext(lang string, title string,
	description string, theme string, data interface{}) RequestContext {
	if lang == "" {
		lang = gotext.GetLanguage()
	}
	locale := gotext.NewLocale("./locales", lang)
	pageData := PageData{
		Title:       locale.Get(title),
		Description: locale.Get(description),
	}
	setting := Preference{Theme: theme}
	meta := Meta{Version: CurrentVersion}
	return RequestContext{
		Lang:     lang,
		Loc:      locale,
		Page:     &pageData,
		Setting:  &setting,
		LoggedIn: nil,
		Yue:      &meta,
		Data:     data,
	}
}