aboutsummaryrefslogtreecommitdiff
path: root/route.go
diff options
context:
space:
mode:
authorFuwn <[email protected]>2021-07-17 10:58:26 +0000
committerFuwn <[email protected]>2021-07-17 10:58:26 +0000
commitc0cda289d92e75daa599cb7513681103e0a2db57 (patch)
tree3617b5e7918ff9aa642374ae5f5e5c15842d6edd /route.go
parentfix(templates): add blog quick link (diff)
downloadspace-c0cda289d92e75daa599cb7513681103e0a2db57.tar.xz
space-c0cda289d92e75daa599cb7513681103e0a2db57.zip
feat(route): blog handler for multi-blog support
Diffstat (limited to 'route.go')
-rw-r--r--route.go46
1 files changed, 32 insertions, 14 deletions
diff --git a/route.go b/route.go
index f67904a..8f43a05 100644
--- a/route.go
+++ b/route.go
@@ -12,6 +12,8 @@ import (
"github.com/pitr/gig"
)
+var blogs = make(map[string]string)
+
func createRoute(route string, template string, content string) {
// hostInformation, _ := host.Info()
@@ -25,17 +27,7 @@ func createRoute(route string, template string, content string) {
})
})
- // Legacy support?
- endString := ".gmi"
- if route[len(route)-1:] == "/" {
- endString = "index.gmi"
- }
- g.Handle(route+endString, func(c gig.Context) error {
- return c.NoContent(gig.StatusRedirectPermanent, route)
- })
- g.Handle(route+"/", func(c gig.Context) error {
- return c.NoContent(gig.StatusRedirectPermanent, route)
- })
+ legacySupport(route)
}
func createErrorRoute(route string, template string, content string, err string) {
@@ -56,10 +48,31 @@ func createFileRoute(route string, file string) {
})
}
-func createBlogRoute(baseRoute string, postPath string) {
+func createBlogHandler(route string) {
+ g.Handle(route, func(c gig.Context) error {
+ blogList := "# BLOG LIST (" + fmt.Sprintf("%d", len(blogs)) + ")\n\n"
+ for blog, name := range blogs {
+ blogList += fmt.Sprintf("=> %s %s\n", blog, name)
+ }
+ blogList = utilities.TrimLastChar(blogList)
+
+ return c.Render("default.gmi", IndexTemplate{
+ Content: blogList,
+ Quote: utilities.GetRandomQuote(),
+ Hits: database.Get(route) + 1,
+ Copyright: utilities.GetCopyright(),
+ })
+ })
+
+ legacySupport(route)
+}
+
+func createBlogRoute(baseRoute string, postPath string, name string) {
+ baseRoute = "/blog" + baseRoute
+
contents, _ := contentFilesystem.ReadDir("content/" + postPath)
- files := "# BLOG POSTS (" + fmt.Sprintf("%d", (len(contents))) + ")\n\n"
+ files := fmt.Sprintf("# %s (%d)\n\n", strings.ToUpper(name), len(contents))
for _, file := range contents {
fileNameNoExt := strings.Replace(file.Name(), ".gmi", "", -1)
@@ -68,6 +81,8 @@ func createBlogRoute(baseRoute string, postPath string) {
}
files = utilities.TrimLastChar(files)
+ blogs[baseRoute] = name
+
g.Handle(baseRoute, func(c gig.Context) error {
return c.Render("default.gmi", IndexTemplate{
Content: files,
@@ -76,7 +91,10 @@ func createBlogRoute(baseRoute string, postPath string) {
Copyright: utilities.GetCopyright(),
})
})
- // Legacy support?
+ legacySupport(baseRoute)
+}
+
+func legacySupport(baseRoute string) {
endString := ".gmi"
if baseRoute[len(baseRoute)-1:] == "/" {
endString = "index.gmi"