~bigbes/sr-ht-ecore

ref: 3bd158fbb23241df31897f9ba47afac832ee2e1d sr-ht-ecore/chrome/templates/chrome.tmpl -rw-r--r-- 6.9 KiB
3bd158fb — Eugene Blikh mcphttp: pin Flush with a flush that precedes any write 2 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
{{/*
  Shared chrome partials. The dot must expose the chrome.Page fields — either
  a Page itself or a view struct embedding one.

  srht-env-banner renders the non-production warning strip; place it first in
  <body>. srht-nav renders the navbar INNER content (brand + switcher + login
  box); the service's layout owns the <nav> element itself so it can keep its
  own classes.
*/}}

{{/*
  srht-head-links renders the two <link> elements every service's <head>
  carries: the built stylesheet and the favicon. Both are guarded rather than
  emitted empty, because <link href=""> re-requests the page it is on — one
  extra page load per page load, for nothing.
*/}}
{{define "srht-head-links" -}}
{{if .StyleHref}}<link rel="stylesheet" href="{{.StyleHref}}">{{end}}
{{if .FaviconHref}}<link rel="icon" href="{{.FaviconHref}}">{{end}}
{{- end}}

{{define "srht-env-banner" -}}
{{if .ShowBanner}}
<div style="background: #228800; color: white; font-weight: bold; width: 100%; text-align: center">
  {{.Environment}} ENVIRONMENT
</div>
{{end}}
{{- end}}

{{/*
  srht-repo-list renders a listing of projects (repos, databases, spaces) as
  the family's event-list cards. Dot is a chrome.RepoList. The rules the four
  services converged on: h4 title link; visibility as small muted text on the
  right, non-public only, lowercase; description as a paragraph when present.
*/}}
{{define "srht-repo-list" -}}
{{if .Items}}
<div class="event-list">
  {{range .Items}}
  <div class="event">
    <h4>
      <a href="{{.Href}}">{{.Title}}</a>
      {{if and .Visibility (ne .Visibility "PUBLIC")}}
      <small class="pull-right">{{if eq .Visibility "UNLISTED"}}unlisted{{else}}private{{end}}</small>
      {{end}}
    </h4>
    {{if .Description}}
    <p>{{.Description}}</p>
    {{end}}
    {{if or (not .Updated.IsZero) .Meta}}
    <small class="text-muted">
      {{if not .Updated.IsZero}}<span title="{{abstime .Updated}}">{{reltime .Updated}}</span>{{end}}
      {{range .Meta}}<span>{{.}}</span>{{end}}
    </small>
    {{end}}
  </div>
  {{end}}
</div>
{{else}}
<p class="text-muted">{{.Empty}}</p>
{{end}}
{{- end}}

{{/*
  srht-repo-table is the same listing as aligned columns, for a service whose
  list is long enough to scan rather than read. Dot is a chrome.RepoList, so a
  service can switch between the two partials without touching its handler.

  The columns after the name render only when the data carries them: a service
  with no timestamp in its schema (dolt) gets a two-column table rather than a
  column of blanks.
*/}}
{{define "srht-repo-table" -}}
{{if .Items}}
<table class="table">
  <tbody>
    {{range .Items}}
    <tr>
      <td>
        <a href="{{.Href}}">{{.Title}}</a>
        {{if and .Visibility (ne .Visibility "PUBLIC")}}
        <small class="text-muted">{{if eq .Visibility "UNLISTED"}}unlisted{{else}}private{{end}}</small>
        {{end}}
        {{if .Description}}<br><small class="text-muted">{{.Description}}</small>{{end}}
      </td>
      {{range .Meta}}<td class="text-muted">{{.}}</td>{{end}}
      {{if not .Updated.IsZero}}
      <td class="text-right text-muted" title="{{abstime .Updated}}">{{reltime .Updated}}</td>
      {{end}}
    </tr>
    {{end}}
  </tbody>
</table>
{{else}}
<p class="text-muted">{{.Empty}}</p>
{{end}}
{{- end}}

{{/*
  srht-sections renders a service's own navigation row — the second row, below
  the switcher — from Page.Tabs, and nothing at all when that is empty. Place it
  immediately after the <nav> element the layout owns.

  The markup is upstream's for this job, which is why the row costs no service
  any CSS: .header-tabbed wrapping .nav.nav-tabs is what meta puts profile and
  keys in and git puts a repo's tree and log in, and both classes arrive with
  core.sr.ht's base.scss — nav.scss, and the dark half of it — which every
  service here already imports.

  Unlike srht-nav this partial owns its wrapper element. srht-nav renders the
  navbar's inner content because the services disagreed about the <nav>'s own
  classes; nobody disagrees about this row, and a service that had to write the
  wrapper itself is a service that can write it differently — which is how a
  shared chrome stops being shared.
*/}}
{{define "srht-sections" -}}
{{if .Tabs}}
<div class="header-tabbed">
  <div class="container">
    <ul class="nav nav-tabs">
      {{range .Tabs}}
      <li class="nav-item">
        <a class="nav-link{{if .Active}} active{{end}}" href="{{.Href}}">{{.Name}}</a>
      </li>
      {{end}}
    </ul>
  </div>
</div>
{{end}}
{{- end}}

{{define "srht-nav" -}}
{{/*
  The brand carries a fixed min-width so the service switcher starts at the
  same x-coordinate on every service: without it the menu shifts by the width
  of the red service label ("dolt" vs "compare") when hopping between
  services. Sized for the longest label on the instance; inline because the
  services build their CSS from the shared core tree and ecore ships none.

  Two links, not one. Upstream core.sr.ht makes the whole brand a single link
  and has to choose: with hub configured it points the site name at hub and
  drops the service label entirely, without hub it keeps the label and points
  at the service root. Neither half is expendable — hub is excluded from the
  switcher, so the brand is the only route to it, and a page that does not
  name the service it belongs to is worse chrome. So the site name goes to
  hub (falling back to the service root when the instance has no hub) and the
  red label goes to the service root.

  The label stays wrapped in its own <span class="text-danger"> rather than
  becoming a red <a>: the theme colors ".navbar-light .navbar-brand a", which
  outranks .text-danger and would repaint the label white in dark mode.
*/}}
<span class="navbar-brand" style="min-width: 15rem">
  <span class="icon icon-circle" aria-hidden="true"><svg width="22" height="22" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path d="M256 8C119 8 8 119 8 256s111 248 248 248 248-111 248-248S393 8 256 8zm0 448c-110.5 0-200-89.5-200-200S145.5 56 256 56s200 89.5 200 200-89.5 200-200 200z"/></svg></span>
  <a href="{{if .HubOrigin}}{{.HubOrigin}}{{else}}/{{end}}">{{.SiteName}}</a>
  <a href="/"><span class="text-danger">{{.SiteLabel}}</span></a>
</span>
<ul class="navbar-nav">
  {{if .Username}}
  {{range .Nav}}
  <li class="nav-item {{if .Active}}active{{end}}">
    <a class="nav-link" href="{{.Origin}}">{{.Name}}</a>
  </li>
  {{end}}
  {{range .ExtraNav}}
  <li class="nav-item {{if .Active}}active{{end}}">
    <a class="nav-link" href="{{.Origin}}">{{.Name}}</a>
  </li>
  {{end}}
  {{end}}
</ul>
<div class="login">
  {{if .Username}}
  <span class="navbar-text">
    Logged in as
    <a href="{{.ProfileURL}}">{{.Username}}</a>
    &mdash;
    <a href="{{.LogoutURL}}">Log out</a>
  </span>
  {{else}}
  <span class="navbar-text">
    <a href="{{.LoginURL}}" rel="nofollow">Log in</a>
    &mdash;
    <a href="{{.RegisterURL}}">Register</a>
  </span>
  {{end}}
</div>
{{- end}}