diff --git a/src/hmnurl/urls.go b/src/hmnurl/urls.go index 2789fff7..8b6b537b 100644 --- a/src/hmnurl/urls.go +++ b/src/hmnurl/urls.go @@ -700,6 +700,13 @@ func (c *UrlContext) BuildBlogPostReply(threadId int, postId int) string { var RegexLibraryAny = regexp.MustCompile(`^/library`) +var RegexLibrary = regexp.MustCompile(`^/library$`) + +func BuildLibrary() string { + defer CatchPanic() + return Url("/library", nil) +} + /* * Episode Guide */ diff --git a/src/templates/src/include/header.html b/src/templates/src/include/header.html index 8346ec01..1bc8687c 100644 --- a/src/templates/src/include/header.html +++ b/src/templates/src/include/header.html @@ -84,7 +84,10 @@
Resources
{{ svg "chevron-down-thick" }}
diff --git a/src/templates/types.go b/src/templates/types.go index 0173c889..e1e70220 100644 --- a/src/templates/types.go +++ b/src/templates/types.go @@ -52,6 +52,7 @@ type Header struct { FishbowlUrl string ForumsUrl string ConferencesUrl string + LibraryUrl string EducationUrl string Project *ProjectHeader diff --git a/src/website/base_data.go b/src/website/base_data.go index a813c744..c9ec89d6 100644 --- a/src/website/base_data.go +++ b/src/website/base_data.go @@ -75,6 +75,7 @@ func getBaseData(c *RequestContext, title string, breadcrumbs []templates.Breadc FishbowlUrl: hmnurl.BuildFishbowlIndex(), ForumsUrl: hmnurl.HMNProjectContext.BuildForum(nil, 1), ConferencesUrl: hmnurl.BuildConferences(), + LibraryUrl: hmnurl.BuildLibrary(), EducationUrl: hmnurl.BuildEducationIndex(), }, Footer: templates.Footer{ diff --git a/src/website/library.go b/src/website/library.go new file mode 100644 index 00000000..17d58c8c --- /dev/null +++ b/src/website/library.go @@ -0,0 +1,9 @@ +package website + +func LibraryNotPortedYet(c *RequestContext) ResponseData { + baseData := getBaseData(c, "Library", nil) + + var res ResponseData + res.MustWriteTemplate("library_not_ported_yet.html", baseData, c.Perf) + return res +} diff --git a/src/website/middlewares.go b/src/website/middlewares.go index d5191fc2..1074d71f 100644 --- a/src/website/middlewares.go +++ b/src/website/middlewares.go @@ -75,6 +75,16 @@ func adminsOnly(h Handler) Handler { } } +func educationBetaTestersOnly(h Handler) Handler { + return func(c *RequestContext) ResponseData { + if c.CurrentUser == nil || !c.CurrentUser.CanSeeUnpublishedEducationContent() { + return FourOhFour(c) + } + + return h(c) + } +} + func educationAuthorsOnly(h Handler) Handler { return func(c *RequestContext) ResponseData { if c.CurrentUser == nil || !c.CurrentUser.CanAuthorEducation() { diff --git a/src/website/routes.go b/src/website/routes.go index a9c165b0..fa85404d 100644 --- a/src/website/routes.go +++ b/src/website/routes.go @@ -117,21 +117,25 @@ func NewWebsiteRoutes(conn *pgxpool.Pool) http.Handler { hmnOnly.GET(hmnurl.RegexFishbowlIndex, FishbowlIndex) hmnOnly.GET(hmnurl.RegexFishbowl, Fishbowl) - hmnOnly.GET(hmnurl.RegexEducationIndex, EducationIndex) - hmnOnly.GET(hmnurl.RegexEducationGlossary, EducationGlossary) - hmnOnly.GET(hmnurl.RegexEducationArticleNew, educationAuthorsOnly(EducationArticleNew)) - hmnOnly.POST(hmnurl.RegexEducationArticleNew, educationAuthorsOnly(EducationArticleNewSubmit)) - hmnOnly.GET(hmnurl.RegexEducationArticle, EducationArticle) // Article stuff must be last so `/glossary` and others do not match as an article slug - hmnOnly.GET(hmnurl.RegexEducationArticleEdit, educationAuthorsOnly(EducationArticleEdit)) - hmnOnly.POST(hmnurl.RegexEducationArticleEdit, educationAuthorsOnly(EducationArticleEditSubmit)) - hmnOnly.GET(hmnurl.RegexEducationArticleDelete, educationAuthorsOnly(EducationArticleDelete)) - hmnOnly.POST(hmnurl.RegexEducationArticleDelete, educationAuthorsOnly(csrfMiddleware(EducationArticleDeleteSubmit))) + educationPrerelease := hmnOnly.WithMiddleware(educationBetaTestersOnly) + { + educationPrerelease.GET(hmnurl.RegexEducationIndex, EducationIndex) + educationPrerelease.GET(hmnurl.RegexEducationGlossary, EducationGlossary) + educationPrerelease.GET(hmnurl.RegexEducationArticleNew, educationAuthorsOnly(EducationArticleNew)) + educationPrerelease.POST(hmnurl.RegexEducationArticleNew, educationAuthorsOnly(EducationArticleNewSubmit)) + educationPrerelease.GET(hmnurl.RegexEducationArticle, EducationArticle) // Article stuff must be last so `/glossary` and others do not match as an article slug + educationPrerelease.GET(hmnurl.RegexEducationArticleEdit, educationAuthorsOnly(EducationArticleEdit)) + educationPrerelease.POST(hmnurl.RegexEducationArticleEdit, educationAuthorsOnly(EducationArticleEditSubmit)) + educationPrerelease.GET(hmnurl.RegexEducationArticleDelete, educationAuthorsOnly(EducationArticleDelete)) + educationPrerelease.POST(hmnurl.RegexEducationArticleDelete, educationAuthorsOnly(csrfMiddleware(EducationArticleDeleteSubmit))) + } hmnOnly.POST(hmnurl.RegexAPICheckUsername, csrfMiddleware(APICheckUsername)) - hmnOnly.GET(hmnurl.RegexLibraryAny, func(c *RequestContext) ResponseData { - return c.Redirect(hmnurl.BuildEducationIndex(), http.StatusFound) - }) + hmnOnly.GET(hmnurl.RegexLibraryAny, LibraryNotPortedYet) + // hmnOnly.GET(hmnurl.RegexLibraryAny, func(c *RequestContext) ResponseData { + // return c.Redirect(hmnurl.BuildEducationIndex(), http.StatusFound) + // }) // Project routes can appear either at the root (e.g. hero.handmade.network/edit) // or on a personal project path (e.g. handmade.network/p/123/hero/edit). So, we