{{ define "main" }}

UniNotes

Contents

{{/* Build full tree: semester → subjectcode → units → self/live */}} {{ $semesters := site.Taxonomies.semester.Alphabetical }}
{{ range $semesters }} {{ $semName := .Page.Title }} {{ $semPages := .Pages }} {{/* Collect unique subject codes for this semester */}} {{ $subjectCodes := slice }} {{ range $semPages }} {{ $raw := .Params.subjectcode }} {{ $code := "" }} {{ if reflect.IsSlice $raw }}{{ $code = index $raw 0 }}{{ else }}{{ $code = $raw }}{{ end }} {{ if and $code (not (in $subjectCodes $code)) }} {{ $subjectCodes = $subjectCodes | append $code }} {{ end }} {{ end }} {{/* Sort subject codes numerically by extracting the number from the code (e.g. "BO DCM1109" → 1109) */}} {{ $codeDicts := slice }} {{ range $subjectCodes }} {{ $code := . }} {{ $parts := split $code " " }} {{ $lastPart := index $parts (sub (len $parts) 1) }} {{/* Extract digits only from the last part */}} {{ $numStr := "" }} {{ range (split $lastPart "") }} {{ if ge . "0" }}{{ if le . "9" }}{{ $numStr = printf "%s%s" $numStr . }}{{ end }}{{ end }} {{ end }} {{ $num := int ($numStr | default "0") }} {{ $codeDicts = $codeDicts | append (dict "code" $code "num" $num) }} {{ end }} {{ $sortedCodeDicts := sort $codeDicts "num" }} {{ if $sortedCodeDicts }}
{{ $semName }} {{ range $sortedCodeDicts }} {{ $code := .code }} {{ $subPage := site.GetPage (printf "/subjectcode/%s" ($code | urlize)) }} {{/* Collect one representative page per unit for this subject, then sort numerically */}} {{ $unitDicts := slice }} {{ $seenUnits := slice }} {{ range $semPages.ByWeight }} {{ $raw := .Params.subjectcode }} {{ $sc := "" }} {{ if reflect.IsSlice $raw }}{{ $sc = index $raw 0 }}{{ else }}{{ $sc = $raw }}{{ end }} {{ if eq $sc $code }} {{ $unitLabel := (.Params.unit | default .Title) }} {{ if not (in $seenUnits $unitLabel) }} {{ $seenUnits = $seenUnits | append $unitLabel }} {{/* Extract unit number for numeric sort, e.g. "Unit 11" → 11 */}} {{ $uParts := split $unitLabel " " }} {{ $uLast := index $uParts (sub (len $uParts) 1) }} {{ $uNumStr := "" }} {{ range (split $uLast "") }} {{ if ge . "0" }}{{ if le . "9" }}{{ $uNumStr = printf "%s%s" $uNumStr . }}{{ end }}{{ end }} {{ end }} {{ $uNum := int ($uNumStr | default "0") }} {{ if eq (upper $unitLabel) "QNA" }}{{ $uNum = 999999 }}{{ end }} {{ $unitDicts = $unitDicts | append (dict "label" $unitLabel "page" . "num" $uNum) }} {{ end }} {{ end }} {{ end }} {{ $sortedUnitDicts := sort $unitDicts "num" }}
{{ if $subPage }} {{ $code }} {{ else }} {{ $code }} {{ end }}
    {{ range $sortedUnitDicts }} {{ $unitLabel := .label }} {{ $repPage := .page }} {{ $unitUrl := $repPage.Params.uniturl }} {{ if not $unitUrl }}{{ $unitUrl = $repPage.RelPermalink }}{{ end }} {{/* Find Self and Live URLs for this unit */}} {{ $selfUrl := "" }} {{ $liveUrl := "" }} {{ range $semPages }} {{ $raw := .Params.subjectcode }} {{ $sc := "" }} {{ if reflect.IsSlice $raw }}{{ $sc = index $raw 0 }}{{ else }}{{ $sc = $raw }}{{ end }} {{ $ul := (.Params.unit | default .Title) }} {{ if and (eq $sc $code) (eq $ul $unitLabel) }} {{ $cat := lower .Params.notecategory }} {{ if eq $cat "self" }}{{ $selfUrl = .RelPermalink }}{{ end }} {{ if eq $cat "live" }}{{ $liveUrl = .RelPermalink }}{{ end }} {{ end }} {{ end }}
  • {{ if eq (upper $unitLabel) "QNA" }} {{ $unitLabel }} {{ else }} {{ $unitLabel }} {{ if $selfUrl }} Self {{ else }} Self {{ end }} {{ if $liveUrl }} Live {{ else }} Live {{ end }} {{ end }}
  • {{ end }}
{{ end }}
{{ end }} {{ end }}
{{ end }}