{{- define "head" -}}
	{{- $current := replaceRE `[^0-9]` "" .File -}}
	{{- .Scratch.Set "title" .Site.Title -}}
	{{- .Scratch.Add "title" " #" -}}
	{{- .Scratch.Add "title" (replaceRE `[^0-9]` "" .File) -}}
	{{- partial "head.html" . -}}
{{- end -}}

{{- define "primary" -}}
	{{- $current := replaceRE `[^0-9]` "" .File -}}
	{{- partial "nav.html" . -}}
	<div id="challenge">
		<header>
			<h3>Tegaki Tuesday #{{- $current -}}</h3>
			<small><ruby>手<rp>(</rp><rt>て</rt><rp>)</rp></ruby><ruby>書<rp>(</rp><rt>が</rt><rp>)</rp></ruby>きの<ruby>火<rp>(</rp><rt>か</rt><rp>)</rp></ruby><ruby>曜<rp>(</rp><rt>よう</rt><rp>)</rp></ruby><ruby>日<rp>(</rp><rt>び</rt><rp>)</rp></ruby>＃{{- $current -}}・<time datetime="{{- .Date.Format " 2006-01-02T15:04:05Z07:00" -}}">{{- .Date.Format "2006年01月02日" -}}</time></small>
		</header>
		<div id="challenge-container">
			<div id="challenge-horizontal">
				<div id="challenge-vocab" lang="ja">
					<!-- Vocab view -->
					<!-- Outer list: lines -->
					{{- range.Params.japanese -}}
						<!-- Inner list: sublines -->
						{{- range. -}}
							<!-- Innermost list: words -->
							<p>{{- range. -}}
								{{- if eq (printf "%T" .text) "string" -}}
									{{- $.Scratch.Set "dictionary" .text -}}
									{{- $.Scratch.Set "html" .text -}}
								{{- else -}}
									{{- $.Scratch.Set "dictionary" "" -}}
									{{- $.Scratch.Set "html" "" -}}
									{{- range.text -}}
										{{- if reflect.IsMap . -}}
											{{- range $kanji, $furigana := . -}}
												{{- $.Scratch.Add "dictionary" $kanji -}}
												{{- $.Scratch.Add "html" "<ruby>" -}}
												{{- $.Scratch.Add "html" $kanji -}}
												{{- $.Scratch.Add "html" "<rp>(</rp><rt>" -}}
												{{- $.Scratch.Add "html" $furigana -}}
												{{- $.Scratch.Add "html" "</rt><rp>)</rp></ruby>" -}}
											{{- end -}}
										{{- else -}}
											{{- $.Scratch.Add "dictionary" . -}}
											{{- $.Scratch.Add "html" . -}}
										{{- end -}}
									{{- end -}}
									{{- if .dictionary -}}
										{{- $.Scratch.Set "dictionary" .dictionary -}}
									{{- end -}}
								{{- end -}}
								{{- if and (not .dictionary) (not .pos) -}}
									{{- $.Scratch.Get "html" | safeHTML -}}
								{{- else -}}
									<a href="https:/jisho.org/word/{{- $.Scratch.Get "dictionary" -}}" class="{{- .pos -}}" title="{{- .pos -}}" target="_blank">{{- $.Scratch.Get "html" | safeHTML -}}</a>
								{{- end -}}
							{{- end -}}</p>
						{{- end -}}
					{{- end -}}
				</div>
				<div id="challenge-english">
					<!-- English view -->
					{{- range.Params.english -}}
						<p>{{- $.RenderString . -}}</p>
					{{- end -}}
				</div>
			</div>
			<div id="challenge-kanji" lang="ja">
				<!-- Kanji view -->
				<!-- Outer list: lines -->
				{{- range.Params.japanese -}}
					<!-- Inner list: sublines -->
					{{- range. -}}
						<!-- Innermost list: words -->
						<p>{{- range. -}}
							{{- if eq (printf "%T" .text) "string" -}}
								{{- .text -}}
							{{- else -}}
								{{- range.text -}}
									{{- if reflect.IsMap . -}}
										{{- range $kanji, $furigana := . -}}
											<a href="https://jisho.org/search/{{- $kanji -}} #kanji" target="_blank"><ruby>{{- $kanji -}}<rp>(</rp><rt>{{- $furigana -}}</rt><rp>)</rp></ruby></a>
										{{- end -}}
									{{- else -}}
										{{- . -}}
									{{- end -}}
								{{- end -}}
							{{- end -}}
						{{- end -}}</p>
					{{- end -}}
				{{- end -}}
			</div>
		</div>
	</div>
	<div class="content">
		{{- partial "content.html" . -}}
	</div>
{{- end -}}

{{- define "secondary" -}}
	{{- $current := replaceRE `[^0-9]` "" .File -}}
	<div id="submissions">
		{{- range index .Site.Data.challenges ($current) -}}
			{{- $submission := . -}}
			{{- range.images -}}
				{{- $path := printf "%s" . | printf "%s%s" "/" | printf "%s%s" $current | printf "%s" -}}
				{{- $image := resources.Get $path -}}
				{{- partial "submission.html" (dict "submission" $submission "challenge" $current "image" $image) -}}
			{{- end -}}
		{{- end -}}
	</div>
{{- end -}}

{{- define "secondaryFooter" -}}
	{{- partial "footer.html" (partial "footers/submissions.html" .) -}}
{{- end -}}