Package navtoc

import "gitlab.com/zoralab/bissetii/pkg/internal/navtoc"

Package navtoc is for rendering table of contents navigation list.

The HTML template codes are written in Go’s string format under the corresponding group. This allows one to embed the HTML codes instead of parsing it from file.

Constants

Constants for managing the package as a whole.

const (
	// Name is the block name (`{{- define "this-name" -}}`).
	Name = "nav-toc"

	// AMPName is the AMP HTML block name.
	AMPName = root.AMPPrefix + Name

	// ParametersComment are the list of comment headers
	// describing inputs.
	ParametersComment = `
{{- /* .Class                 = TOC class attribute                    */ -}}
{{- /* .ID                    = TOC id attribute                       */ -}}
{{- /* .Label                 = TOC name used in aria-label            */ -}}
{{- /* .Page.Children         = TOC list of .Page data (slice)         */ -}}
{{- /*    $page.Title         = Page title                             */ -}}
{{- /*    $page.Level         = Page title level (number)              */ -}}
{{- /*    $page.Description   = Page description                       */ -}}
{{- /*    $page.Date.Modified = Page modified date                     */ -}}
{{- /*    $page.Link          = Page .Link data                        */ -}}
{{- /*    $page.Link.URL      = Page URL                               */ -}}
{{- /*    $page.Link.Content  = Page URL content                       */ -}}
`
)

Dependencies are the dependent codes for building independent template.

This is useful for rendering portable template usage like Hugo partials where they do not share a common definition source.

const (
	// DepHTML is the vanilla HTML output type.
	DepHTML = `
{{- define "` + anchor.Name + `" -}}` + anchor.HTML + `{{- end -}}
{{- define "` + image.Name + `" -}}` + image.HTML + `{{- end -}}
`

	// DepAMPHTML is the Accelerated Mobile Pages HTML output
	// type.
	DepAMPHTML = `
{{- define "` + anchor.AMPName + `" -}}` + anchor.AMPHTML + `{{- end -}}
{{- define "` + image.AMPName + `" -}}` + image.AMPHTML + `{{- end -}}
`
)

Full HTML codes for rendering templates without needing to parse file.

const (
	// HTML is the vanilla HTML output type.
	HTML = `
<nav class="nav-toc {{- if .Class }} {{ .Class -}}{{- end -}}"
{{- if .ID }}

	id="{{- .ID -}}"
{{- end }}
{{- if .Label }}

	aria-label="{{- .Label -}}"
{{- end -}}
><ol>

	{{- range $page := .Page.Children }}

	<li>

		<h{{- $page.Level -}}>{{- $page.Title -}}</h{{- $page.Level -}}>

		{{- if $page.Thumbnails -}}

			{{- $image := index $page.Thumbnails "0" -}}

			{{- template "` + image.Name + `" $image -}}

		{{- end }}

		{{- if $page.Description }}

		<p>{{- $page.Description -}}</p>

		{{- end }}

		<p>

			<span>Last Modified:</span>

			<span>

				<b><time>{{- $page.Date.Modified -}}</time></b>

			</span>

		</p>

		<p>

			<span>Link:</span>

			<span><b>

				{{- template "` + anchor.Name + `" $page.Link -}}

			</b></span>

		</p>

	</li>

	{{- end }}
</ol></nav>
`

	// AMPHTML is the Accelerated Mobile Pages HTML output type.
	AMPHTML = `
<nav class="nav-toc {{- if .Class }} {{ .Class -}}{{- end -}}"
{{- if .ID }}

	id="{{- .ID -}}"
{{- end }}
{{- if .Label }}

	aria-label="{{- .Label -}}"
{{- end -}}
><ol>

	{{- range $page := .Page.Children }}

	<li>

		<h{{- $page.Level -}}>{{- $page.Title -}}</h{{- $page.Level -}}>

		{{- if $page.Thumbnails -}}

			{{- if $page.Thumbnails -}}

				{{- $image := index $page.Thumbnails "0" -}}

				{{- template "` + image.AMPName + `" $image -}}

			{{- end }}

		{{- end }}

		<p>{{- $page.Description -}}</p>

		<p>

			<span>Last Modified:</span>

			<span>

				<b><time>{{- $page.Date.Modified -}}</time></b>

			</span>

		</p>

		<p>

			<span>Link:</span>

			<span><b>

				{{- template "` + anchor.AMPName + `" $page.Link -}}

			</b></span>

		</p>

	</li>

	{{- end }}
</ol></nav>
`
)

Data

type Data meta.Page

Data is the data structure for rendering the component.