9
"xelbot.com/reprogl/container"
10
"xelbot.com/reprogl/models"
11
"xelbot.com/reprogl/security"
30
type OpenGraph map[string]string
32
type HeaderLineInfo interface {
33
HeaderLineDescription() string
34
HeaderLineText() string
37
type DataWithFlashMessage interface {
38
HasSuccessFlash() bool
40
SetSuccessFlash(string)
43
type flashObjectPart struct {
47
type identityPart struct {
48
identity security.Identity
51
type ArticlePageData struct {
53
Article *models.Article
60
type IndexPageData struct {
62
HeaderInfo HeaderLineInfo
63
Paginator *models.ArticlesPaginator
67
type InfoPageData struct {
69
HeaderInfo HeaderLineInfo
71
Jobs container.JobHistory
74
type SidebarDummyArticle struct {
79
type StatisticsPageData struct {
82
Commentators *models.CommentatorList
83
DummyArticle SidebarDummyArticle
85
MonthArticles []models.ArticleStatItem
86
AllTimeArticles []models.ArticleStatItem
89
type LoginPageData struct {
96
type UnsubscribePageData struct {
98
Settings *models.EmailSubscription
103
type AuthNavigation struct {
107
type MenuAuthData struct {
112
type ProfilePageData struct {
115
SubscriptionsSettings *models.EmailSubscription
116
DummyArticle SidebarDummyArticle
119
type OauthPendingPageData struct {
124
type FragmentCategoriesData struct {
125
Categories *models.CategoryList
128
type FragmentCommentsData struct {
129
Comments models.CommentList
134
type FragmentRecentPostsData struct {
135
RecentPosts *models.RecentPostList
138
func defaultMeta() Meta {
139
cfg := container.GetConfig()
141
ogp := make(OpenGraph)
143
ogp["og:type"] = "website"
144
ogp["og:image"] = cfg.CDNBaseURL + "/images/kravchik.jpg"
145
ogp["og:image:width"] = "752"
146
ogp["og:image:height"] = "376"
147
ogp["og:locale"] = "ru_RU"
149
return Meta{Host: cfg.Host, HeaderText: cfg.HeaderText, Ogp: ogp}
152
func (m *Meta) AppendTitle(str string) {
153
m.titleParts = append(m.titleParts, str)
154
m.SetOpenGraphProperty("og:title", str)
157
func (m *Meta) AppendName(name, content string) {
158
m.MetaParts = append(m.MetaParts, MetaName{Name: name, Content: content})
159
if name == "description" {
160
m.SetOpenGraphProperty("og:description", content)
164
func (m *Meta) SetCanonical(link string) {
166
m.SetOpenGraphProperty("og:url", link)
169
func (m *Meta) SetOpenGraphProperty(property, content string) {
171
m.Ogp[property] = content
173
ogp := make(OpenGraph)
174
ogp[property] = content
179
func (m *Meta) BrowserTitle() string {
181
if len(m.titleParts) > 0 {
182
for _, p := range m.titleParts {
191
func (fo *flashObjectPart) HasSuccessFlash() bool {
192
return len(fo.flashSuccess) > 0
195
func (fo *flashObjectPart) FlashSuccess() string {
196
return fo.flashSuccess
199
func (fo *flashObjectPart) SetSuccessFlash(msg string) {
200
fo.flashSuccess = msg
203
func (ip *identityPart) SetIdentity(identity security.Identity) {
204
ip.identity = identity
207
func (ip *identityPart) HasIdentity() bool {
208
return !ip.identity.IsZero()
211
func (ip *identityPart) IsAdmin() bool {
212
return ip.identity.IsAdmin()
215
func NewArticlePageData(article *models.Article, commentKey, accept string) *ArticlePageData {
216
meta := defaultMeta()
217
if article.Description.Valid {
218
meta.AppendName("description", article.Description.String)
221
return &ArticlePageData{
224
CommentKey: commentKey,
225
AcceptHeader: accept,
229
func NewIndexPageData(paginator *models.ArticlesPaginator) *IndexPageData {
230
meta := defaultMeta()
231
meta.IsIndexPage = true
233
return &IndexPageData{
234
Paginator: paginator,
239
func NewCategoryPageData(paginator *models.ArticlesPaginator, headerInfo HeaderLineInfo) *IndexPageData {
240
var browserTitle, metaDescription string
241
meta := defaultMeta()
242
meta.IsIndexPage = true
244
switch reflect.TypeOf(headerInfo).String() {
245
case "*models.Category":
246
browserTitle = fmt.Sprintf("Категория \"%s\"", headerInfo.HeaderLineText())
247
metaDescription = fmt.Sprintf("Записи из категории \"%s\"", headerInfo.HeaderLineText())
249
browserTitle = fmt.Sprintf("Тег \"%s\"", headerInfo.HeaderLineText())
250
metaDescription = fmt.Sprintf("Записи по тегу \"%s\"", headerInfo.HeaderLineText())
253
if paginator.CurrentPage > 1 {
254
browserTitle += fmt.Sprintf(". Страница %d", paginator.CurrentPage)
255
metaDescription += fmt.Sprintf(". Страница %d", paginator.CurrentPage)
257
meta.AppendTitle(browserTitle)
258
meta.AppendName("description", metaDescription)
259
meta.AppendName("robots", "noindex, follow")
261
return &IndexPageData{Paginator: paginator, HeaderInfo: headerInfo, Meta: meta}
264
func NewInfoPageData() *InfoPageData {
265
meta := defaultMeta()
266
meta.IsAuthorPage = true
267
meta.AppendName("description", "Персональный блог Харченко Александра. Общая информация.")
268
meta.AppendTitle("Обо мне")
270
return &InfoPageData{
272
Jobs: container.GetConfig().Jobs.Sort(),
276
func NewStatisticsPageData() *StatisticsPageData {
277
meta := defaultMeta()
278
meta.AppendName("description", "Статистика посещений и комментариев.")
279
meta.AppendTitle("Статистика")
281
return &StatisticsPageData{
284
DummyArticle: SidebarDummyArticle{RecentPostsID: "0"},
288
func NewLoginPageData(token, errorMessage string, hasError bool) *LoginPageData {
289
meta := defaultMeta()
290
meta.AppendTitle("Вход")
291
meta.AppendName("description", "Страница логина. Описание тут не особо-то и нужно, но Yandex Webmaster настаивает")
293
return &LoginPageData{
296
ErrorMessage: errorMessage,
301
func NewUnsubscribePageData(settings *models.EmailSubscription, avatarLink string, success bool) *UnsubscribePageData {
302
meta := defaultMeta()
303
meta.AppendTitle("Отписка от email-уведомлений")
305
return &UnsubscribePageData{
313
func NewAuthNavigationData() *AuthNavigation {
314
return &AuthNavigation{}
317
func NewMenuAuthData(user *models.User) *MenuAuthData {
318
return &MenuAuthData{User: user}
321
func NewProfilePageData(user *models.User, settings *models.EmailSubscription) *ProfilePageData {
322
meta := defaultMeta()
323
meta.AppendTitle("Профиль")
325
return &ProfilePageData{
328
DummyArticle: SidebarDummyArticle{RecentPostsID: "0"},
330
SubscriptionsSettings: settings,
334
func NewOauthPendingPageData(requsetId string) *OauthPendingPageData {
335
meta := defaultMeta()
336
meta.AppendTitle("Ожидайте...")
338
return &OauthPendingPageData{
340
RequestId: requsetId,
344
func (apd *ArticlePageData) AcceptWebp() bool {
345
return strings.Contains(apd.AcceptHeader, "image/webp")
348
func (apd *ArticlePageData) AcceptAvif() bool {
349
return strings.Contains(apd.AcceptHeader, "image/avif")