penguin/flatgit

flatgit showcase

internal/render/templates.go

raw · 4665 bytes

package render

const layoutTemplate = `{{define "layout"}}<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{{template "pageTitle" .}}</title>
<link rel="stylesheet" href="{{.RepoManifest.Repository.SitePath}}style.css">
<link rel="alternate" type="application/json" title="flatgit repository manifest" href="{{.RepoManifest.Repository.SitePath}}manifest.json">
<link rel="alternate" type="application/json" title="flatgit refs" href="{{.RepoManifest.Repository.SitePath}}refs.json">
<link rel="alternate" type="application/json" title="flatgit commits" href="{{.RepoManifest.Repository.SitePath}}commits.json">
</head>
<body>
<header>
<h1><a href="{{.RepoManifest.Repository.SitePath}}">{{.RepoManifest.Repository.FullName}}</a></h1>
{{if .RepoManifest.Repository.Description}}<p class="muted">{{.RepoManifest.Repository.Description}}</p>{{end}}
<nav>
<a href="{{.RepoManifest.Repository.SitePath}}">summary</a>
<a href="{{.RepoManifest.Repository.SitePath}}log.html">log</a>
<a href="{{.RepoManifest.Repository.SitePath}}refs.html">refs</a>
<a href="{{.RepoManifest.Repository.SitePath}}tree/{{.RepoManifest.Repository.DefaultRefSlug}}/index.html">files</a>
<a href="{{.RepoManifest.Repository.SitePath}}manifest.json" title="express view for bots and agents">json</a>
</nav>
</header>
<main>
{{template "content" .}}
</main>
<footer>
<p class="muted">generated by flatgit at {{.GeneratedAt}}</p>
</footer>
</body>
</html>{{end}}
`

const indexTemplate = `{{define "pageTitle"}}{{.RepoManifest.Repository.FullName}} - flatgit{{end}}
{{define "content"}}
<h2>summary</h2>
<table>
<tr><th>default branch</th><td class="mono">{{.RepoManifest.Repository.DefaultBranch}}</td></tr>
<tr><th>default commit</th><td class="mono">{{.RepoManifest.Repository.DefaultCommit}}</td></tr>
</table>

<h2>recent commits</h2>
<table>
<tr><th>commit</th><th>date</th><th>author</th><th>subject</th></tr>
{{range .Commits}}
<tr><td class="mono"><a href="{{$.RepoManifest.Repository.SitePath}}commit/{{.Hash}}.html">{{.Short}}</a></td><td>{{.Date}}</td><td>{{.Author}}</td><td>{{.Subject}}</td></tr>
{{end}}
</table>

<h2>files</h2>
<table>
<tr><th>path</th><th>size</th></tr>
{{range .Files}}
<tr><td class="mono"><a href="{{$.RepoManifest.Repository.SitePath}}blob/{{$.RepoManifest.Repository.DefaultRefSlug}}/{{.Path}}.html">{{.Path}}</a></td><td>{{.Size}}</td></tr>
{{end}}
</table>
{{end}}
`

const refsTemplate = `{{define "pageTitle"}}{{.RepoManifest.Repository.FullName}} refs{{end}}
{{define "content"}}
<h2>refs</h2>
<table>
<tr><th>kind</th><th>name</th><th>commit</th></tr>
{{range .Refs}}
<tr>
<td><span class="pill">{{.Kind}}</span></td>
<td class="mono"><a href="{{$.RepoManifest.Repository.SitePath}}commit/{{.Commit}}.html">{{.Short}}</a></td>
<td class="mono"><a href="{{$.RepoManifest.Repository.SitePath}}commit/{{.Commit}}.html">{{.Commit}}</a></td></tr>
{{end}}
</table>
{{end}}
`

const logTemplate = `{{define "pageTitle"}}{{.RepoManifest.Repository.FullName}} log{{end}}
{{define "content"}}
<h2>commit log</h2>
<table>
<tr><th>commit</th><th>date</th><th>author</th><th>subject</th></tr>
{{range .Commits}}
<tr><td class="mono"><a href="{{$.RepoManifest.Repository.SitePath}}commit/{{.Hash}}.html">{{.Short}}</a></td><td>{{.Date}}</td><td>{{.Author}}</td><td>{{.Subject}}</td></tr>
{{end}}
</table>
{{end}}
`

const treeTemplate = `{{define "pageTitle"}}{{.RepoManifest.Repository.FullName}} files{{end}}
{{define "content"}}
<h2>files: {{.Ref}}</h2>
<table>
<tr><th>mode</th><th>type</th><th>path</th><th>size</th></tr>
{{range .Files}}
<tr><td class="mono">{{.Mode}}</td><td>{{.Type}}</td><td class="mono"><a href="{{$.RepoManifest.Repository.SitePath}}blob/{{$.RepoManifest.Repository.DefaultRefSlug}}/{{.Path}}.html">{{.Path}}</a></td><td>{{.Size}}</td></tr>
{{end}}
</table>
{{end}}
`

const commitTemplate = `{{define "pageTitle"}}{{.RepoManifest.Repository.FullName}} commit {{.Commit.Short}}{{end}}
{{define "content"}}
<h2>commit <span class="mono">{{.Commit.Hash}}</span></h2>
<table>
<tr><th>author</th><td>{{.Commit.Author}} &lt;{{.Commit.Email}}&gt;</td></tr>
<tr><th>date</th><td>{{.Commit.Date}}</td></tr>
<tr><th>subject</th><td>{{.Commit.Subject}}</td></tr>
</table>
<pre>{{.Show}}</pre>
{{end}}
`

const blobTemplate = `{{define "pageTitle"}}{{.RepoManifest.Repository.FullName}} {{.Blob.Path}}{{end}}
{{define "content"}}
<h2 class="mono">{{.Blob.Path}}</h2>
<p><a href="{{.Blob.RawHref}}">raw</a> · {{.Blob.Size}} bytes</p>
{{if .Blob.Binary}}
<p>Binary or large file; HTML preview skipped.</p>
{{else}}
<pre>{{.Blob.Text}}</pre>
{{end}}
{{end}}
`