2021-10-28 01:35:53 +00:00
|
|
|
package website
|
|
|
|
|
|
|
|
import (
|
|
|
|
"git.handmade.network/hmn/hmn/src/config"
|
|
|
|
"git.handmade.network/hmn/hmn/src/hmnurl"
|
|
|
|
"git.handmade.network/hmn/hmn/src/models"
|
|
|
|
"git.handmade.network/hmn/hmn/src/templates"
|
|
|
|
)
|
|
|
|
|
|
|
|
func getBaseDataAutocrumb(c *RequestContext, title string) templates.BaseData {
|
|
|
|
return getBaseData(c, title, []templates.Breadcrumb{{Name: title, Url: ""}})
|
|
|
|
}
|
|
|
|
|
|
|
|
// NOTE(asaf): If you set breadcrumbs, the breadcrumb for the current project will automatically be prepended when necessary.
|
|
|
|
// If you pass nil, no breadcrumbs will be created.
|
|
|
|
func getBaseData(c *RequestContext, title string, breadcrumbs []templates.Breadcrumb) templates.BaseData {
|
|
|
|
var templateUser *templates.User
|
|
|
|
var templateSession *templates.Session
|
|
|
|
if c.CurrentUser != nil {
|
|
|
|
u := templates.UserToTemplate(c.CurrentUser, c.Theme)
|
|
|
|
s := templates.SessionToTemplate(c.CurrentSession)
|
|
|
|
templateUser = &u
|
|
|
|
templateSession = &s
|
|
|
|
}
|
|
|
|
|
|
|
|
notices := getNoticesFromCookie(c)
|
|
|
|
|
|
|
|
if len(breadcrumbs) > 0 {
|
2021-11-10 04:11:39 +00:00
|
|
|
projectUrl := c.UrlContext.BuildHomepage()
|
2021-10-28 01:35:53 +00:00
|
|
|
if breadcrumbs[0].Url != projectUrl {
|
|
|
|
rootBreadcrumb := templates.Breadcrumb{
|
|
|
|
Name: c.CurrentProject.Name,
|
|
|
|
Url: projectUrl,
|
|
|
|
}
|
|
|
|
breadcrumbs = append([]templates.Breadcrumb{rootBreadcrumb}, breadcrumbs...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
baseData := templates.BaseData{
|
|
|
|
Theme: c.Theme,
|
|
|
|
Title: title,
|
|
|
|
Breadcrumbs: breadcrumbs,
|
|
|
|
|
|
|
|
CurrentUrl: c.FullUrl(),
|
2021-11-10 04:11:39 +00:00
|
|
|
CurrentProjectUrl: c.UrlContext.BuildHomepage(),
|
2021-10-28 01:35:53 +00:00
|
|
|
LoginPageUrl: hmnurl.BuildLoginPage(c.FullUrl()),
|
|
|
|
ProjectCSSUrl: hmnurl.BuildProjectCSS(c.CurrentProject.Color1),
|
|
|
|
|
2021-11-10 04:11:39 +00:00
|
|
|
Project: templates.ProjectToTemplate(c.CurrentProject, c.UrlContext.BuildHomepage(), c.Theme),
|
2021-10-28 01:35:53 +00:00
|
|
|
User: templateUser,
|
|
|
|
Session: templateSession,
|
|
|
|
Notices: notices,
|
|
|
|
|
|
|
|
ReportIssueMailto: "team@handmade.network",
|
|
|
|
|
|
|
|
OpenGraphItems: buildDefaultOpenGraphItems(c.CurrentProject, title),
|
|
|
|
|
|
|
|
IsProjectPage: !c.CurrentProject.IsHMN(),
|
|
|
|
Header: templates.Header{
|
|
|
|
AdminUrl: hmnurl.BuildAdminApprovalQueue(), // TODO(asaf): Replace with general-purpose admin page
|
|
|
|
UserSettingsUrl: hmnurl.BuildUserSettings(""),
|
|
|
|
LoginActionUrl: hmnurl.BuildLoginAction(c.FullUrl()),
|
|
|
|
LogoutActionUrl: hmnurl.BuildLogoutAction(c.FullUrl()),
|
|
|
|
ForgotPasswordUrl: hmnurl.BuildRequestPasswordReset(),
|
|
|
|
RegisterUrl: hmnurl.BuildRegister(),
|
|
|
|
|
|
|
|
HMNHomepageUrl: hmnurl.BuildHomepage(),
|
|
|
|
ProjectIndexUrl: hmnurl.BuildProjectIndex(1),
|
|
|
|
PodcastUrl: hmnurl.BuildPodcast(),
|
2021-11-10 04:11:39 +00:00
|
|
|
ForumsUrl: hmnurl.HMNProjectContext.BuildForum(nil, 1),
|
2021-10-28 01:35:53 +00:00
|
|
|
LibraryUrl: hmnurl.BuildLibrary(),
|
|
|
|
},
|
|
|
|
Footer: templates.Footer{
|
|
|
|
HomepageUrl: hmnurl.BuildHomepage(),
|
|
|
|
AboutUrl: hmnurl.BuildAbout(),
|
|
|
|
ManifestoUrl: hmnurl.BuildManifesto(),
|
|
|
|
CodeOfConductUrl: hmnurl.BuildCodeOfConduct(),
|
|
|
|
CommunicationGuidelinesUrl: hmnurl.BuildCommunicationGuidelines(),
|
|
|
|
ProjectIndexUrl: hmnurl.BuildProjectIndex(1),
|
2021-11-10 04:11:39 +00:00
|
|
|
ForumsUrl: hmnurl.HMNProjectContext.BuildForum(nil, 1),
|
2021-10-28 01:35:53 +00:00
|
|
|
ContactUrl: hmnurl.BuildContactPage(),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.CurrentUser != nil {
|
|
|
|
baseData.Header.UserProfileUrl = hmnurl.BuildUserProfile(c.CurrentUser.Username)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !c.CurrentProject.IsHMN() {
|
|
|
|
episodeGuideUrl := ""
|
|
|
|
defaultTopic, hasAnnotations := config.Config.EpisodeGuide.Projects[c.CurrentProject.Slug]
|
|
|
|
if hasAnnotations {
|
2021-11-10 04:11:39 +00:00
|
|
|
episodeGuideUrl = c.UrlContext.BuildEpisodeList(defaultTopic)
|
2021-10-28 01:35:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
baseData.Header.Project = &templates.ProjectHeader{
|
2021-11-10 17:13:56 +00:00
|
|
|
HasForums: c.CurrentProject.HasForums(),
|
|
|
|
HasBlog: c.CurrentProject.HasBlog(),
|
2021-10-28 01:35:53 +00:00
|
|
|
HasEpisodeGuide: hasAnnotations,
|
2021-11-10 04:11:39 +00:00
|
|
|
ForumsUrl: c.UrlContext.BuildForum(nil, 1),
|
|
|
|
BlogUrl: c.UrlContext.BuildBlog(1),
|
2021-10-28 01:35:53 +00:00
|
|
|
EpisodeGuideUrl: episodeGuideUrl,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return baseData
|
|
|
|
}
|
|
|
|
|
|
|
|
func buildDefaultOpenGraphItems(project *models.Project, title string) []templates.OpenGraphItem {
|
|
|
|
if title == "" {
|
|
|
|
title = "Handmade Network"
|
|
|
|
}
|
|
|
|
|
|
|
|
image := hmnurl.BuildPublic("logo.png", false)
|
|
|
|
if !project.IsHMN() {
|
|
|
|
image = hmnurl.BuildUserFile(project.LogoLight)
|
|
|
|
}
|
|
|
|
|
|
|
|
return []templates.OpenGraphItem{
|
|
|
|
{Property: "og:title", Value: title},
|
|
|
|
{Property: "og:site_name", Value: "Handmade Network"},
|
|
|
|
{Property: "og:type", Value: "website"},
|
|
|
|
{Property: "og:image", Value: image},
|
|
|
|
}
|
|
|
|
}
|