aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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
-rw-r--r--web/templates/home/home.tmpl57
-rw-r--r--web/templates/layout/tyriannav.tmpl7
-rw-r--r--web/templates/recent/recent.tmpl78
8 files changed, 161 insertions, 81 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")))
diff --git a/web/templates/home/home.tmpl b/web/templates/home/home.tmpl
index a46d3fc..15bffea 100644
--- a/web/templates/home/home.tmpl
+++ b/web/templates/home/home.tmpl
@@ -4,10 +4,6 @@
<body>
{{template "header" "home"}}
-<div id="scroll-down-section" class="text-muted" style="z-index: 9999;">
- <br/><br/>
- <i onclick="document.getElementById('lists-section').scrollIntoView(true);" class="fa fa-angle-down" aria-hidden="true"></i>
-</div>
<div class="container mb-5">
<div class="row">
@@ -52,59 +48,6 @@
</div>
- <div id="lists-section" class="col-12 pt-3">
- <p class="lead">
- Here you can find the archives of our most important mailing lists.
- </p>
- <p>
- For a complete list of available archives, see the <a href="/lists" class="btn btn-primary btn-sm px-1 py-0"><i class="fa fa-fw fa-archive"></i> All Archives</a> section.
- </p>
- </div>
-
- <div class="col-12">
- {{range .MailingLists}}
- <hr/>
- <div class="row">
- <div class="col-12 col-md-4">
- <h2 class="stick-top">{{.Name}}</h2>
- <p>
- <tt>{{.Name}}</tt> {{.Description}}.
- </p>
- <p class="ag-index-actions">
- <a class="btn btn-primary btn-block" href="/{{.Name}}/threads/{{ $.CurrentMonth}}/"><span class="fa fa-fw fa-inbox"></span> This Month's Archives</a>
- <a class="btn btn-outline-secondary text-dark btn-block" href="/{{.Name}}/"><span class="fa fa-fw fa-inbox"></span> Complete Archives</a>
- </p>
- </div>
- <div class="col-12 col-md-8">
- <h3 class="ag-mostrecent-header">Most recent messages</h3>
- <div class="table-responsive">
- <table class="table table-sm table-hover ag-mostrecent-table">
- <tbody>
- <tr>
- <th>Subject</th>
- <th class="ag-mostrecent-table-author">Author</th>
- </tr>
- {{$listName:=.Name}}
- {{range .Messages}}
- <tr>
- <td><a href="/{{$listName}}/message/{{.Id}}">{{.GetSubject}}</a></td>
- <td>{{.GetAuthorName}}</td>
- </tr>
- {{end}}
- </tbody>
- </table>
- </div>
- </div>
- </div>
- {{end}}
-
- <hr/>
- <h2>Other Lists</h2>
- <p>
- All other archives are available here: <a href="/lists" class="btn btn-primary"><i class="fa fa-fw fa-archive"></i> All Archives</a>
- </p>
-
- </div>
</div>
</div>
diff --git a/web/templates/layout/tyriannav.tmpl b/web/templates/layout/tyriannav.tmpl
index f7c83da..72b926e 100644
--- a/web/templates/layout/tyriannav.tmpl
+++ b/web/templates/layout/tyriannav.tmpl
@@ -9,9 +9,10 @@
<div class="collapse navbar-collapse navbar-main-collapse" id="navbar-main-collapse">
<ul class="navbar-nav mr-auto">
- <li class="nav-item {{ if (eq . "home")}}active{{end}}"><a class="nav-link" href="/">Home</a></li>
- <li class="nav-item {{ if (eq . "browse")}}active{{end}}"><a class="nav-link" href="/lists"><i class="fa fa-fw fa-archive"></i> All Archives</a></li>
- {{ if not (eq . "home" "search" "browse" "popular") }}
+ <li class="nav-item {{ if (eq . "home" "search")}}active{{end}}"><a class="nav-link" href="/">Search</a></li>
+ <li class="nav-item {{ if (eq . "recent")}}active{{end}}"><a class="nav-link" href="/recent">Recent</a></li>
+ <li class="nav-item {{ if (eq . "browse")}}active{{end}}"><a class="nav-link" href="/lists"><i class="fa fa-fw fa-archive"></i> Browse</a></li>
+ {{ if not (eq . "home" "search" "recent" "browse" "popular") }}
<li class="nav-item active"><a class="nav-link" href="/{{.}}/"><i class="fa fa-fw fa-inbox"></i> {{.}}</a></li>
{{end}}
diff --git a/web/templates/recent/recent.tmpl b/web/templates/recent/recent.tmpl
new file mode 100644
index 0000000..a4d8864
--- /dev/null
+++ b/web/templates/recent/recent.tmpl
@@ -0,0 +1,78 @@
+<!DOCTYPE html>
+<html lang="en">
+{{template "head"}}
+<body>
+{{template "header" "recent"}}
+
+<div id="scroll-down-section" class="text-muted" style="z-index: 9999;">
+ <br/><br/>
+ <i onclick="document.getElementById('lists-section').scrollIntoView(true);" class="fa fa-angle-down" aria-hidden="true"></i>
+</div>
+
+<div class="container mb-5">
+ <div class="row">
+
+ <div id="lists-section" class="col-12 pt-3">
+ <h1 class="first-header">Gentoo Mailing List Archives</h1>
+ <p class="lead">
+ Here you can find the archives of our most important mailing lists.
+ </p>
+ <p>
+ For a complete list of available archives, see the <a href="/lists" class="btn btn-primary btn-sm px-1 py-0"><i class="fa fa-fw fa-archive"></i> All Archives</a> section.
+ </p>
+ </div>
+
+ <div class="col-12">
+ {{range .MailingLists}}
+ <hr/>
+ <div class="row">
+ <div class="col-12 col-md-4">
+ <h2 class="stick-top">{{.Name}}</h2>
+ <p>
+ <tt>{{.Name}}</tt> {{.Description}}.
+ </p>
+ <p class="ag-index-actions">
+ <a class="btn btn-primary btn-block" href="/{{.Name}}/threads/{{ $.CurrentMonth}}/"><span class="fa fa-fw fa-inbox"></span> This Month's Archives</a>
+ <a class="btn btn-outline-secondary text-dark btn-block" href="/{{.Name}}/"><span class="fa fa-fw fa-inbox"></span> Complete Archives</a>
+ </p>
+ </div>
+ <div class="col-12 col-md-8">
+ <h3 class="ag-mostrecent-header">Most recent messages</h3>
+ <div class="table-responsive">
+ <table class="table table-sm table-hover ag-mostrecent-table">
+ <tbody>
+ <tr>
+ <th>Subject</th>
+ <th class="ag-mostrecent-table-author">Author</th>
+ </tr>
+ {{$listName:=.Name}}
+ {{range .Messages}}
+ <tr>
+ <td><a href="/{{$listName}}/message/{{.Id}}">{{.GetSubject}}</a></td>
+ <td>{{.GetAuthorName}}</td>
+ </tr>
+ {{end}}
+ </tbody>
+ </table>
+ </div>
+ </div>
+ </div>
+ {{end}}
+
+ <hr/>
+ <h2>Other Lists</h2>
+ <p>
+ All other archives are available here: <a href="/lists" class="btn btn-primary"><i class="fa fa-fw fa-archive"></i> All Archives</a>
+ </p>
+
+ </div>
+ </div>
+</div>
+
+
+{{template "footer"}}
+
+<script src="/assets/index.js"></script>
+
+</body>
+</html>