|
| 1 | +{{- $site := .site -}} |
| 2 | +{{- $cacheKey := "academy-theme-content-health-report" -}} |
| 3 | +{{- if not ($site.Store.Get $cacheKey) -}} |
| 4 | + |
| 5 | +{{- $registryURL := "" -}} |
| 6 | +{{- with $site.Params.academy.registryURL -}} |
| 7 | + {{- $registryURL = printf "%v" . | strings.TrimSpace -}} |
| 8 | +{{- end -}} |
| 9 | + |
| 10 | +{{- $consoleURL := "" -}} |
| 11 | +{{- with $site.Params.academy.consoleURL -}} |
| 12 | + {{- $consoleURL = printf "%v" . | strings.TrimSpace -}} |
| 13 | +{{- end -}} |
| 14 | +{{- if eq $consoleURL "" -}} |
| 15 | + {{- $consoleURL = "/academy/instructors-console" -}} |
| 16 | +{{- end -}} |
| 17 | +{{- $academyBaseURL := "" -}} |
| 18 | +{{- with $site.Params.academy.domain -}} |
| 19 | + {{- $academyBaseURL = printf "%v" . | strings.TrimSpace -}} |
| 20 | +{{- else -}} |
| 21 | + {{- with $site.Params.academy.baseURL -}} |
| 22 | + {{- $academyBaseURL = printf "%v" . | strings.TrimSpace -}} |
| 23 | + {{- else -}} |
| 24 | + {{- with $site.Params.academy.consoleURL -}} |
| 25 | + {{- $academyBaseURL = printf "%v" . | strings.TrimSpace -}} |
| 26 | + {{- end -}} |
| 27 | + {{- end -}} |
| 28 | +{{- end -}} |
| 29 | +{{- if and (ne $academyBaseURL "") (not (hasPrefix $academyBaseURL "http://")) (not (hasPrefix $academyBaseURL "https://")) -}} |
| 30 | + {{- $academyBaseURL = printf "https://%s" $academyBaseURL -}} |
| 31 | +{{- end -}} |
| 32 | +{{- $academyBaseURL = replaceRE `/academy/.*$` "" $academyBaseURL -}} |
| 33 | +{{- $academyBaseURL = strings.TrimSuffix "/" $academyBaseURL -}} |
| 34 | +{{- if and (ne $academyBaseURL "") (ne $consoleURL "") (not (hasPrefix $consoleURL "http://")) (not (hasPrefix $consoleURL "https://")) -}} |
| 35 | + {{- $consoleURL = printf "%s/academy/instructors-console" $academyBaseURL -}} |
| 36 | +{{- end -}} |
| 37 | + |
| 38 | +{{- $validationMode := "warn" -}} |
| 39 | +{{- with $site.Params.academy.validationMode -}} |
| 40 | + {{- $validationMode = printf "%v" . | strings.TrimSpace | lower -}} |
| 41 | +{{- end -}} |
| 42 | +{{- $registryValidationEnabled := ne $validationMode "off" -}} |
| 43 | + |
| 44 | +{{- $items := slice -}} |
| 45 | +{{- $good := 0 -}} |
| 46 | +{{- $broken := 0 -}} |
| 47 | +{{- $draft := 0 -}} |
| 48 | +{{- $draftWarning := 0 -}} |
| 49 | +{{- $unchecked := 0 -}} |
| 50 | + |
| 51 | +{{- range $site.Pages -}} |
| 52 | + {{- if and .File (partial "academy-validation/is-root-content.html" .) -}} |
| 53 | + {{- $filePath := .File.Path -}} |
| 54 | + {{- $parts := split $filePath "/" -}} |
| 55 | + {{- $orgID := cond (ge (len $parts) 2) (index $parts 1) "" -}} |
| 56 | + {{- $contentID := "" -}} |
| 57 | + {{- with .Params.id -}} |
| 58 | + {{- $contentID = printf "%v" . | strings.TrimSpace -}} |
| 59 | + {{- end -}} |
| 60 | + |
| 61 | + {{- $title := .Title -}} |
| 62 | + {{- if not $title -}} |
| 63 | + {{- $title = replaceRE `[_-]+` " " (replaceRE `\.[^.]+$` "" (path.Base $filePath)) | title -}} |
| 64 | + {{- end -}} |
| 65 | + |
| 66 | + {{- $contentType := replace (index $parts 0) "-" " " | title -}} |
| 67 | + {{- $status := "good" -}} |
| 68 | + {{- $issue := "" -}} |
| 69 | + {{- $fix := "" -}} |
| 70 | + {{- $registryStatus := "" -}} |
| 71 | + {{- $isDraft := or .Draft (eq (printf "%v" .Params.draft | lower) "true") -}} |
| 72 | + {{- if not $isDraft -}} |
| 73 | + {{- $sourcePath := printf "content/%s" $filePath -}} |
| 74 | + {{- $source := try (os.ReadFile $sourcePath) -}} |
| 75 | + {{- if not $source.Err -}} |
| 76 | + {{- $frontMatter := index (findRE `(?s)^---\s.*?\s---` $source.Value 1) 0 | default "" -}} |
| 77 | + {{- if gt (len (findRE `(?m)^draft:\s*true\s*$` $frontMatter 1)) 0 -}} |
| 78 | + {{- $isDraft = true -}} |
| 79 | + {{- end -}} |
| 80 | + {{- end -}} |
| 81 | + {{- end -}} |
| 82 | + |
| 83 | + {{- if $isDraft -}} |
| 84 | + {{- $draft = add $draft 1 -}} |
| 85 | + {{- end -}} |
| 86 | + |
| 87 | + {{- if not (partial "academy-validation/validate-academy-org-id.html" $orgID) -}} |
| 88 | + {{- $status = "broken" -}} |
| 89 | + {{- $issue = "Content is outside a valid organization directory." -}} |
| 90 | + {{- $fix = "Move this root content under content/<type>/<org-id>/<slug>/." -}} |
| 91 | + {{- else if eq $contentID "" -}} |
| 92 | + {{- $status = "broken" -}} |
| 93 | + {{- $issue = "Missing Content ID." -}} |
| 94 | + {{- $fix = "Create or register this content in the Instructor Console, then add the returned ID to front matter." -}} |
| 95 | + {{- else if not $registryValidationEnabled -}} |
| 96 | + {{- $status = "unchecked" -}} |
| 97 | + {{- $issue = "Content health validation is turned off." -}} |
| 98 | + {{- $fix = "Enable Academy content health validation before publishing." -}} |
| 99 | + {{- else -}} |
| 100 | + {{- $registryCacheKey := printf "academy-theme-registry-ids-%s-%s" $orgID (md5 $registryURL) -}} |
| 101 | + {{- partial "academy-validation/validate-academy-registry-ids.html" (dict "site" $site "orgID" $orgID "registryURL" $registryURL) -}} |
| 102 | + {{- $registry := $site.Store.Get $registryCacheKey -}} |
| 103 | + {{- $registryStatus = $registry.status -}} |
| 104 | + {{- if ne $registry.status "ok" -}} |
| 105 | + {{- $status = "unchecked" -}} |
| 106 | + {{- $issue = $registry.message -}} |
| 107 | + {{- $fix = "Configure params.academy.registryURL to check this ID against the Academy registry." -}} |
| 108 | + {{- else if not (in $registry.ids $contentID) -}} |
| 109 | + {{- $status = "broken" -}} |
| 110 | + {{- $issue = printf "Content ID '%s' does not exist in the Academy registry for org '%s'." $contentID $orgID -}} |
| 111 | + {{- $fix = "Use the registered ID from the Instructor Console, or create/register this content before publishing." -}} |
| 112 | + {{- end -}} |
| 113 | + {{- end -}} |
| 114 | + |
| 115 | + {{- if and $isDraft (ne $status "good") -}} |
| 116 | + {{- $status = "draft_warning" -}} |
| 117 | + {{- if eq $issue "" -}} |
| 118 | + {{- $issue = "Draft content could not be fully validated." -}} |
| 119 | + {{- end -}} |
| 120 | + {{- $fix = "This draft will not block publishing, but fix the ID before removing draft mode." -}} |
| 121 | + {{- end -}} |
| 122 | + |
| 123 | + {{- if eq $status "good" -}} |
| 124 | + {{- $good = add $good 1 -}} |
| 125 | + {{- else if eq $status "broken" -}} |
| 126 | + {{- $broken = add $broken 1 -}} |
| 127 | + {{- else if eq $status "unchecked" -}} |
| 128 | + {{- $unchecked = add $unchecked 1 -}} |
| 129 | + {{- else if eq $status "draft_warning" -}} |
| 130 | + {{- $draftWarning = add $draftWarning 1 -}} |
| 131 | + {{- end -}} |
| 132 | + |
| 133 | + {{- $items = $items | append (dict |
| 134 | + "title" $title |
| 135 | + "contentType" $contentType |
| 136 | + "sourcePath" $filePath |
| 137 | + "relPermalink" .RelPermalink |
| 138 | + "productionPermalink" (cond (ne $academyBaseURL "") (printf "%s/academy%s" $academyBaseURL .RelPermalink) "") |
| 139 | + "orgID" $orgID |
| 140 | + "contentID" $contentID |
| 141 | + "status" $status |
| 142 | + "issue" $issue |
| 143 | + "fix" $fix |
| 144 | + "draft" $isDraft |
| 145 | + "registryStatus" $registryStatus |
| 146 | + "registryURL" $registryURL |
| 147 | + ) -}} |
| 148 | + {{- end -}} |
| 149 | +{{- end -}} |
| 150 | + |
| 151 | +{{- $summary := "ready" -}} |
| 152 | +{{- if gt $broken 0 -}} |
| 153 | + {{- $summary = "broken" -}} |
| 154 | +{{- else if gt $unchecked 0 -}} |
| 155 | + {{- $summary = "unchecked" -}} |
| 156 | +{{- end -}} |
| 157 | + |
| 158 | +{{- $report := dict |
| 159 | + "items" $items |
| 160 | + "counts" (dict "good" $good "broken" $broken "draft" $draft "draftWarning" $draftWarning "unchecked" $unchecked "total" (len $items)) |
| 161 | + "summary" $summary |
| 162 | + "registryURLConfigured" (ne $registryURL "") |
| 163 | + "consoleURL" $consoleURL |
| 164 | + "academyBaseURL" $academyBaseURL |
| 165 | +-}} |
| 166 | +{{- $site.Store.Set $cacheKey $report -}} |
| 167 | +{{- end -}} |
0 commit comments