resources/views/chapter.html
このサイトを動かすコードです。どのファイルから読めばよいかは第14章の読み順で確認できます。
{{template "layout" .}}
{{define "content"}}
<div class="wrap reader">
{{template "side-nav" .}}
<article>
<details class="mobile-chapters">
<summary>別の章に移動</summary>
{{template "side-nav" .}}
</details>
<nav class="breadcrumbs" aria-label="現在の位置"><a href="/chapters">全章の目次に戻る</a></nav>
<header class="article-header">
<p class="edition">第{{.Chapter.Number}}章</p>
<h1>{{.Chapter.Title}}</h1>
<p>{{.Chapter.Summary}}</p>
</header>
<details class="mobile-outline">
<summary>この章の見出し</summary>
{{template "outline" .}}
</details>
<div class="prose">{{.Body}}</div>
<section class="chapter-progress" id="chapter-progress" aria-labelledby="chapter-progress-title">
<h2 id="chapter-progress-title">この章の学習記録</h2>
{{with user}}
{{if .MustChangePassword}}
<p><a href="/account/password?next={{$.Chapter.URL}}">パスワードを設定して学習記録を使う</a></p>
{{else}}
<p>{{if $.ChapterCompleted}}読み終えたと記録済みです。{{else}}読み終えたら記録できます。{{end}}</p>
<form method="post" action="{{$.Chapter.URL}}/progress">
{{csrfField}}
{{if $.ChapterCompleted}}
<button class="button button-secondary" name="completed" value="no" type="submit">未読に戻す</button>
{{else}}
<button class="button" name="completed" value="yes" type="submit">読み終えたと記録</button>
{{end}}
</form>
{{end}}
{{else}}
<p><a href="/login?next={{.Chapter.URL}}">ログインして読了を記録する</a></p>
{{end}}
</section>
<nav class="chapter-pager" aria-label="前後の章">
{{if .Previous.Slug}}
<a href="{{.Previous.URL}}"><small>← 前の章</small>{{.Previous.Title}}</a>
{{end}}
{{if .Next.Slug}}
<a class="next" href="{{.Next.URL}}"><small>次の章 →</small>{{.Next.Title}}</a>
{{else}}
<a class="next" href="/chapters"><small>全14章の一覧</small>目次に戻る</a>
{{end}}
</nav>
</article>
<aside class="on-this-page" aria-label="章内目次">
<h2>この章の見出し</h2>
{{template "outline" .}}
</aside>
</div>
{{end}}
{{define "outline"}}
<ul>
{{range .Outline}}<li><a href="#{{.ID}}">{{.Label}}</a></li>{{end}}
</ul>
{{end}}