| 1 | {{define "admin_templates.html"}}{{template "admin_base.html" .}}{{end}} |
| 2 | {{define "title"}}Admin — Templates{{end}} |
| 3 | {{define "content"}} |
| 4 | <h2>Templates</h2> |
| 5 | <nav class="form-actions template-tabs"> |
| 6 | {{range .Kinds}} |
| 7 | <a href="/admin/templates?t={{.Kind}}" class="btn" {{if eq .Kind $.Kind}}aria-current="page"{{end}}>{{.Label}}</a> |
| 8 | {{end}} |
| 9 | </nav> |
| 10 | {{if .Success}}<p class="success">Template saved.</p>{{end}} |
| 11 | {{if .Error}}<p class="error">{{.Error}}</p>{{end}} |
| 12 | <form method="POST" action="/admin/templates/{{.Kind}}" class="form"> |
| 13 | <div class="switch-row"> |
| 14 | <label class="switch"> |
| 15 | <input type="checkbox" id="custom_template_toggle" {{if .Custom}}checked{{end}}> |
| 16 | <span class="switch-slider"></span> |
| 17 | </label> |
| 18 | <span class="switch-label">custom template</span> |
| 19 | </div> |
| 20 | <div id="custom_template_section" {{if not .Custom}}class="hidden"{{end}}> |
| 21 | <label for="template">page body (Go html/template, replaces the default content inside <main>)</label> |
| 22 | <textarea id="template" name="template" class="post-content">{{.Template}}</textarea> |
| 23 | <details class="available-fields"> |
| 24 | <summary>available fields</summary> |
| 25 | <div class="fields-list"> |
| 26 | <span>.BlogTitle, .SiteURL, .FaviconURL, .OGImageURL</span> |
| 27 | <span>.NavLinks (range: .Label, .URL)</span> |
| 28 | <span>.HeaderHTML, .FooterHTML</span> |
| 29 | {{if eq .Kind "index"}} |
| 30 | <span>.BlogDescription</span> |
| 31 | <span>.IntroHTML</span> |
| 32 | <span>.Posts (range: see post fields)</span> |
| 33 | {{else if eq .Kind "posts"}} |
| 34 | <span>.Posts (range: see post fields)</span> |
| 35 | {{else if eq .Kind "page"}} |
| 36 | <span>.Page.Title, .Page.Slug, .Page.Content, .Page.CreatedAt, .Page.UpdatedAt</span> |
| 37 | <span>.RenderedContent</span> |
| 38 | {{else if eq .Kind "post"}} |
| 39 | <span>.Post (see post fields)</span> |
| 40 | <span>.RenderedContent</span> |
| 41 | <span>.Weather.Icon, .Weather.Conditions, .Weather.Temperature, .Weather.Location</span> |
| 42 | {{end}} |
| 43 | {{if ne .Kind "page"}} |
| 44 | <span>post fields: .Slug, .DisplayTitle, .TitleStr, .HasTitle, .PublishedDateStr, .MetaDescriptionStr, .MetaImageStr, .CanonicalURLStr, .TagList, .Lang, .Content</span> |
| 45 | {{end}} |
| 46 | </div> |
| 47 | </details> |
| 48 | </div> |
| 49 | <button type="submit">save</button> |
| 50 | </form> |
| 51 | <script> |
| 52 | var toggle = document.getElementById('custom_template_toggle'); |
| 53 | var section = document.getElementById('custom_template_section'); |
| 54 | var textarea = document.getElementById('template'); |
| 55 | toggle.addEventListener('change', function() { |
| 56 | section.classList.toggle('hidden', !this.checked); |
| 57 | }); |
| 58 | document.querySelector('form').addEventListener('submit', function() { |
| 59 | if (!toggle.checked) { textarea.value = ''; } |
| 60 | }); |
| 61 | </script> |
| 62 | {{end}} |