Gitfed
bastien-mrq/gitfed / cmd / gitfed-web / handlers_landing.go
package main

import (
	"bytes"
	"html/template"
	"net/http"

	"git.neuromancer.ovh/bastien-mrq/gitfed/internal/i18n"
)

// landingTpl is the philosophy/pitch page served at "/" — what gitfed is
// for, not what it does. The public repo browser lives at /explore.
var landingTpl = newTpl("landing", `
<section class="hero">
  <span class="kicker">{{icon "network"}} {{t .Lang "landing.kicker"}}</span>
  <h1>{{t .Lang "landing.h1_1"}} <em>{{t .Lang "landing.h1_2"}}</em></h1>
  <p class="lead">{{t .Lang "landing.lead"}}</p>
  <div class="hero-actions">
    <a class="btn btn-primary" href="/explore">{{t .Lang "landing.cta_explore"}}</a>
    <a class="btn btn-secondary" href="/security">{{t .Lang "landing.cta_security"}}</a>
  </div>
</section>

<div class="pillars">
  <div class="pillar">
    <div class="picon">{{icon "lock"}}</div>
    <h3>{{t .Lang "landing.pillar1_h"}}</h3>
    <p>{{t .Lang "landing.pillar1_p"}}</p>
  </div>
  <div class="pillar">
    <div class="picon">{{icon "network"}}</div>
    <h3>{{t .Lang "landing.pillar2_h"}}</h3>
    <p>{{t .Lang "landing.pillar2_p"}}</p>
  </div>
  <div class="pillar">
    <div class="picon">{{icon "sliders"}}</div>
    <h3>{{t .Lang "landing.pillar3_h"}}</h3>
    <p>{{t .Lang "landing.pillar3_p"}}</p>
  </div>
</div>

<div class="split">
  <div>
    <h2>{{t .Lang "landing.split_h"}}</h2>
    <p>{{t .Lang "landing.split_p"}}</p>
    <div class="links">
      <a href="/security">{{t .Lang "landing.split_link_security"}} {{icon "arrow"}}</a>
      <a href="/explore">{{t .Lang "landing.split_link_explore"}} {{icon "arrow"}}</a>
    </div>
  </div>
  <div class="fed-diagram">
    <svg viewBox="0 0 340 190" xmlns="http://www.w3.org/2000/svg">
      <rect x="10" y="20" width="130" height="60" rx="4" fill="var(--surface-2)" stroke="var(--border-strong)"/>
      <text x="75" y="45" text-anchor="middle" fill="var(--text)" font-size="11" font-weight="700">{{t .Lang "landing.diagram_you"}}</text>
      <text x="75" y="62" text-anchor="middle" fill="var(--text-dim)" font-size="9" font-family="monospace">alice@chez-moi.fr</text>
      <rect x="200" y="20" width="130" height="60" rx="4" fill="var(--surface-2)" stroke="var(--border-strong)"/>
      <text x="265" y="45" text-anchor="middle" fill="var(--text)" font-size="11" font-weight="700">{{t .Lang "landing.diagram_friend"}}</text>
      <text x="265" y="62" text-anchor="middle" fill="var(--text-dim)" font-size="9" font-family="monospace">bob@ailleurs.net</text>
      <path d="M140 50h56" stroke="var(--accent)" stroke-width="1.5" marker-end="url(#lp-arr1)"/>
      <path d="M200 60l-56 0" stroke="var(--accent)" stroke-width="1.5" marker-end="url(#lp-arr1)" transform="translate(0,10)"/>
      <text x="170" y="45" text-anchor="middle" fill="var(--accent)" font-size="8.5" font-family="monospace">{{t .Lang "landing.diagram_cert"}}</text>
      <text x="170" y="80" text-anchor="middle" fill="var(--ok-fg)" font-size="8.5" font-family="monospace">{{t .Lang "landing.diagram_trust"}}</text>
      <rect x="105" y="120" width="130" height="50" rx="4" fill="var(--surface)" stroke="var(--border)" stroke-dasharray="3 3"/>
      <text x="170" y="140" text-anchor="middle" fill="var(--text-faint)" font-size="9" font-family="monospace">{{t .Lang "landing.diagram_no_account1"}}</text>
      <text x="170" y="154" text-anchor="middle" fill="var(--text-faint)" font-size="9" font-family="monospace">{{t .Lang "landing.diagram_no_account2"}}</text>
      <defs><marker id="lp-arr1" markerWidth="7" markerHeight="7" refX="5" refY="3" orient="auto"><path d="M0,0 L6,3 L0,6 Z" fill="var(--accent)"/></marker></defs>
    </svg>
  </div>
</div>

<div class="changelog-cta">
  <a class="btn btn-secondary" href="/changelog">{{icon "history"}} {{t .Lang "landing.changelog_link"}}</a>
</div>

<div class="cta-band">
  <h2>{{t .Lang "landing.cta_band_h"}}</h2>
  <p>{{t .Lang "landing.cta_band_p"}}</p>
  <div class="hero-actions">
    {{if .LoggedIn}}
    <a class="btn btn-primary" href="/dashboard">{{t .Lang "landing.cta_band_dashboard"}}</a>
    {{else}}
    <a class="btn btn-primary" href="/explore">{{t .Lang "landing.cta_explore"}}</a>
    <a class="btn btn-secondary" href="/login">{{t .Lang "nav.login"}}</a>
    {{end}}
  </div>
</div>
`)

func (s *server) handleLanding(w http.ResponseWriter, r *http.Request) {
	lang := s.lang(r)
	_, loggedIn := s.currentSession(r)

	var buf bytes.Buffer
	_ = landingTpl.Execute(&buf, struct {
		Lang     string
		LoggedIn bool
	}{string(lang), loggedIn})
	s.render(w, r, i18n.T(lang, "landing.title"), "home", template.HTML(buf.String()))
}