aboutsummaryrefslogtreecommitdiff
path: root/pkg/app
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/app')
-rw-r--r--pkg/app/cache/update.go5
-rw-r--r--pkg/app/home/home.go21
-rw-r--r--pkg/app/recent/recent.go52
-rw-r--r--pkg/app/recent/utils.go19
-rw-r--r--pkg/app/serve.go3
5 files changed, 79 insertions, 21 deletions
diff --git a/pkg/app/cache/update.go b/pkg/app/cache/update.go
index 7918b78..5e5bc8d 100644
--- a/pkg/app/cache/update.go
+++ b/pkg/app/cache/update.go
@@ -4,6 +4,7 @@ import (
"archives/pkg/app/home"
"archives/pkg/app/list"
"archives/pkg/app/popular"
+ "archives/pkg/app/recent"
"archives/pkg/cache"
"archives/pkg/config"
"fmt"
@@ -28,6 +29,10 @@ func Update(){
fmt.Println("> Updated '/' in " + time.Now().Sub(startTime).String())
startTime = time.Now()
+ cache.Put("/recent", recent.ComputeTemplateData())
+ fmt.Println("> Updated '/recent' in " + time.Now().Sub(startTime).String())
+
+ startTime = time.Now()
cache.Put("/lists", list.ComputeBrowseTemplateData())
fmt.Println("> Updated '/lists' in " + time.Now().Sub(startTime).String())
diff --git a/pkg/app/home/home.go b/pkg/app/home/home.go
index ced6ec6..0fbcf0b 100644
--- a/pkg/app/home/home.go
+++ b/pkg/app/home/home.go
@@ -5,8 +5,6 @@ package home
import (
"archives/pkg/app/popular"
"archives/pkg/cache"
- "archives/pkg/config"
- "archives/pkg/database"
"archives/pkg/models"
"archives/pkg/utils"
"net/http"
@@ -25,23 +23,6 @@ func Show(w http.ResponseWriter, r *http.Request) {
}
func ComputeTemplateData() interface{} {
- var mailingLists []models.MailingList
-
- for _, mailingList := range config.IndexMailingLists() {
- var messages []*models.Message
- database.DBCon.Model(&messages).
- Where("list = ?", mailingList[0]).
- Where("not date is null").
- Order("date DESC").
- Limit(5).
- Select()
-
- mailingLists = append(mailingLists, models.MailingList{
- Name: mailingList[0],
- Description: mailingList[1],
- Messages: messages,
- })
- }
//
// Get popular threads
@@ -55,12 +36,10 @@ func ComputeTemplateData() interface{} {
}
return struct {
- MailingLists []models.MailingList
PopularThreads []*models.Message
MessageCount string
CurrentMonth string
}{
- MailingLists: mailingLists,
PopularThreads: popularThreads,
MessageCount: utils.FormatMessageCount(strconv.Itoa(getAllMessagesCount())),
CurrentMonth: time.Now().Format("2006-01"),
diff --git a/pkg/app/recent/recent.go b/pkg/app/recent/recent.go
new file mode 100644
index 0000000..b07d78e
--- /dev/null
+++ b/pkg/app/recent/recent.go
@@ -0,0 +1,52 @@
+// Used to show the landing page of the application
+
+package recent
+
+import (
+ "archives/pkg/cache"
+ "archives/pkg/config"
+ "archives/pkg/database"
+ "archives/pkg/models"
+ "net/http"
+ "time"
+)
+
+// Show renders a template to show the landing page of the application
+func Show(w http.ResponseWriter, r *http.Request) {
+ templateData := cache.Get("/recent")
+ if templateData == nil {
+ http.NotFound(w,r)
+ return
+ }
+ renderRecentTemplate(w, templateData)
+}
+
+func ComputeTemplateData() interface{} {
+ var mailingLists []models.MailingList
+
+ for _, mailingList := range config.IndexMailingLists() {
+ var messages []*models.Message
+ database.DBCon.Model(&messages).
+ Where("list = ?", mailingList[0]).
+ Where("not date is null").
+ Order("date DESC").
+ Limit(5).
+ Select()
+
+ mailingLists = append(mailingLists, models.MailingList{
+ Name: mailingList[0],
+ Description: mailingList[1],
+ Messages: messages,
+ })
+ }
+
+ return struct {
+ MailingLists []models.MailingList
+ PopularThreads []*models.Message
+ MessageCount string
+ CurrentMonth string
+ }{
+ MailingLists: mailingLists,
+ CurrentMonth: time.Now().Format("2006-01"),
+ }
+}
diff --git a/pkg/app/recent/utils.go b/pkg/app/recent/utils.go
new file mode 100644
index 0000000..53c0e32
--- /dev/null
+++ b/pkg/app/recent/utils.go
@@ -0,0 +1,19 @@
+// miscellaneous utility functions used for the landing page of the application
+
+package recent
+
+import (
+ "html/template"
+ "net/http"
+)
+
+// renderIndexTemplate renders all templates used for the landing page
+func renderRecentTemplate(w http.ResponseWriter, templateData interface{}) {
+ templates := template.Must(
+ template.Must(
+ template.New("Show").
+ ParseGlob("web/templates/layout/*.tmpl")).
+ ParseGlob("web/templates/recent/recent.tmpl"))
+
+ templates.ExecuteTemplate(w, "recent.tmpl", templateData)
+}
diff --git a/pkg/app/serve.go b/pkg/app/serve.go
index fed6435..01e3ce9 100644
--- a/pkg/app/serve.go
+++ b/pkg/app/serve.go
@@ -8,6 +8,7 @@ import (
"archives/pkg/app/list"
"archives/pkg/app/message"
"archives/pkg/app/popular"
+ "archives/pkg/app/recent"
"archives/pkg/app/search"
"archives/pkg/config"
"fmt"
@@ -37,6 +38,8 @@ func Serve() {
setRoute("/search", search.Search)
+ setRoute("/recent", recent.Show)
+
setRoute("/", home.Show)
fs := http.StripPrefix("/assets/", http.FileServer(http.Dir("assets")))