link list displayed

This commit is contained in:
Ross Trottier 2024-06-25 14:17:08 -06:00
parent 9defacc932
commit d1bd9c37b6
6 changed files with 169 additions and 5 deletions

124
cmd/web/app-links.go Normal file
View File

@ -0,0 +1,124 @@
package main
type AppLink struct {
Title string
Url string
Image string
Description string
}
func getAppLinks(tier, baseUri string) []AppLink {
if tier == "enterprise" {
return getEnterpriseLinks(baseUri)
} else if tier == "creator" {
return getCreatorLinks(baseUri)
} else if tier == "teams" {
return getTeamsLinks(baseUri)
}
return getStarterLinks(baseUri)
}
func getStarterLinks(baseUri string) []AppLink {
return []AppLink {
{
Title: "User Management",
Description: "Create users and manage their access",
Image: "/img/panel.jpg",
Url: "https://panel." + baseUri,
},
{
Title: "Nextcloud",
Description: "Email, Files, Documents",
Image: "/img/nextcloud.jpg",
Url: "https://nextcloud." + baseUri,
},
{
Title: "Vaultwarden",
Description: "Password Management",
Image: "/img/vaultwarden.jpg",
Url: "https://vaultwarden." + baseUri,
},
}
}
func getCreatorLinks(baseUri string) []AppLink {
creatorLinks := []AppLink {
{
Title: "Element and Matrix",
Description: "Team Chat",
Image: "/img/element.jpg",
Url: "https://element." + baseUri,
},
{
Title: "Wordpress",
Description: "Your website",
Image: "/img/wordpress.jpg",
Url: "https://" + baseUri,
},
}
return append(creatorLinks, getStarterLinks(baseUri)...)
}
func getTeamsLinks(baseUri string) []AppLink {
teamsLinks := []AppLink {
{
Title: "Espo CRM",
Description: "Customer relationship manager",
Image: "/img/espo.jpg",
Url: "https://espocrm." + baseUri,
},
{
Title: "FreeScout",
Description: "Customer Help Desk",
Image: "/img/freescout.jpg",
Url: "https://freescout." + baseUri,
},
}
return append(teamsLinks, getCreatorLinks(baseUri)...)
}
func getEnterpriseLinks(baseUri string) []AppLink {
enterpriseLinks := []AppLink{
{
Title: "Jitsi",
Description: "Video Chat",
Image: "/img/jitsi.jpg",
Url: "https://jitsi." + baseUri,
},
{
Title: "Listmonk",
Description: "Email Marketing",
Image: "/img/listmonk.jpg",
Url: "https://listmonk." + baseUri,
},
{
Title: "Baserow",
Description: "Visual Databases",
Image: "/img/baserow.jpg",
Url: "https://baserow." + baseUri,
},
{
Title: "Bookstack",
Description: "Wiki Knowledgebase",
Image: "/img/bookstack.jpg",
Url: "https://bookstack." + baseUri,
},
{
Title: "Gitea",
Description: "GIT Source Control",
Image: "/img/gitea.jpg",
Url: "https://gitea." + baseUri,
},
{
Title: "Castopod",
Description: "Podcast Distribution",
Image: "/img/castopod.jpg",
Url: "https://castopod." + baseUri,
},
}
return append(enterpriseLinks, getTeamsLinks(baseUri)...)
}

View File

@ -1,7 +1,25 @@
package main
import "net/http"
import (
"net/http"
"strings"
)
func (app *application) home(writer http.ResponseWriter, request *http.Request) {
app.render(writer, request, http.StatusOK, "home.tmpl.html", templateData{})
domain := request.Host
domainPieces := strings.Split(domain, ".")
var baseURI string
if len(domainPieces) > 1 {
baseURI = domainPieces[len(domainPieces) - 2] + domainPieces[len(domainPieces) - 1]
} else {
baseURI = domain
}
data := templateData{
AppLinks: getAppLinks(app.tier, baseURI),
Tier: app.tier,
BaseUri: baseURI,
}
app.render(writer, request, http.StatusOK, "home.tmpl.html", data)
}

View File

@ -11,11 +11,14 @@ import (
type application struct {
logger *slog.Logger
templateCache map[string]*template.Template
tier string
}
func main() {
//Get env variables
addr := flag.String("addr", ":4000", "HTTP network address")
tier := flag.String("tier", "starter", "tier the core is on")
flag.Parse()
//Set up logger
logger := slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{
AddSource: true,
@ -30,6 +33,7 @@ func main() {
app := application {
logger: logger,
templateCache: templateCache,
tier: *tier,
}
err = http.ListenAndServe(*addr, app.routes())

View File

@ -7,6 +7,8 @@ import (
type templateData struct {
BaseUri string
AppLinks []AppLink
Tier string
}
func newTemplateCache() (map[string]*template.Template, error) {

View File

@ -1,5 +1,19 @@
{{define "title"}}Home{{end}}
{{define "main"}}
yo
<section class="app-links">
<h2 class="app-links-title">Apps for {{.BaseUri}} on the {{.Tier}} tier.</h2>
<div class="app-links-container">
<!-- LOOP HERE -->
{{range .AppLinks}}
<a href="{{.Url}}" class="app-link-card-link">
<div class="app-link-card">
<h3 class="app-link-card__title">{{.Title}}</h3>
<p class="app-link-card__description">{{.Description}}</p>
<img src="{{.Image}}" alt="" class="app-link-card__image">
</div>
</a>
{{end}}
</div>
</section>
{{end}}

View File

@ -1,5 +1,7 @@
{{define "nav"}}
<nav>
<a href="/">Home</a>
<nav class="nav">
<a href="/" class="nav-link">Home</a>
<a href="/" class="nav-link">Login</a>
<a href="/" class="nav-link">VPN</a>
</nav>
{{end}}