diff --git a/common-theme/layouts/_default/success.html b/common-theme/layouts/_default/success.html index 1f0e03d46..7ed1994be 100644 --- a/common-theme/layouts/_default/success.html +++ b/common-theme/layouts/_default/success.html @@ -84,11 +84,16 @@ {{ partial "time.html" $pageContext }} - {{ $extractedObjectives := partial "strings/extract-github-objectives.html" $decodedContent }} + {{ $extractedObjectives := partial "strings/extract-github-objectives.html" (dict "URL" $blockData.api "body" $decodedContent) }} {{ if gt (len $extractedObjectives) 0 }}

Learning Objectives

- {{ range $extractedObjectives }} - {{ . | page.RenderString }} - {{ end }} + {{ partial "objectives/block" $extractedObjectives }}
{{ end }}
diff --git a/common-theme/layouts/partials/objectives/for-success.html b/common-theme/layouts/partials/objectives/for-success.html new file mode 100644 index 000000000..e10994dcb --- /dev/null +++ b/common-theme/layouts/partials/objectives/for-success.html @@ -0,0 +1,8 @@ +{{ $scope := . }} +{{ $objectives := $scope.objectives }} +{{ $showTitle := $scope.showTitle }} +{{ $title := $scope.title }} +{{ $links := $scope.links }} + +{{ if $showTitle }}
{{ $title }} {{range $links}}{{.text}}{{end}}
{{ end }} +{{ partial "objectives/block.html" $objectives }} diff --git a/common-theme/layouts/partials/objectives/local.html b/common-theme/layouts/partials/objectives/local.html index 64880055b..ab08df7a3 100644 --- a/common-theme/layouts/partials/objectives/local.html +++ b/common-theme/layouts/partials/objectives/local.html @@ -7,7 +7,6 @@ {{ $localBlock := $pageContext.GetPage $scope.blockData.api }} {{ $showTitle := .showTitle |default false }} -{{ with $localBlock.Page.Params.Objectives }} - {{ if $showTitle }}
{{ $localBlock.Page.Title }}
{{ end }} - {{ partial "objectives/block.html" . }} +{{ if $localBlock.Page.Params.Objectives }} +{{ partial "objectives/for-success.html" (dict "objectives" $localBlock.Page.Params.Objectives "showTitle" $showTitle "title" $localBlock.Page.Title "links" $scope.links) }} {{ end }} diff --git a/common-theme/layouts/partials/objectives/remote.html b/common-theme/layouts/partials/objectives/remote.html index 13a890ba1..40761c42e 100644 --- a/common-theme/layouts/partials/objectives/remote.html +++ b/common-theme/layouts/partials/objectives/remote.html @@ -4,10 +4,12 @@ {{ $response := resources.GetRemote .blockData.api .blockData.headers }} {{ $blockType := .blockData.type }} -{{ $showTitle := .showTitle | default false }} +{{ $title := .title }} +{{ $links := .links }} +{{ $url := .blockData.api }} {{/* 404s lead to GetRemote returning nil rather than an error. */}} {{ if eq $response nil }} - {{ errorf "Couldn't find anything at %s" .blockData.api }} + {{ errorf "Couldn't find anything at %s" $url }} {{ end }} {{ with $response }} @@ -20,11 +22,8 @@ {{ $response = $response.body }} {{ end }} - {{ $extractedObjectives := partial "strings/extract-github-objectives.html" $response }} + {{ $extractedObjectives := partial "strings/extract-github-objectives.html" (dict "URL" $url "body" $response) }} {{ if gt (len $extractedObjectives) 0 }} - {{ if $showTitle }}
{{ $showTitle }}
{{ end }} - {{ range $extractedObjectives }} - {{ . | page.RenderString }} - {{ end }} + {{ partial "objectives/for-success.html" (dict "objectives" $extractedObjectives "showTitle" $title "title" $title "links" $links) }} {{ end }} {{ end }} diff --git a/common-theme/layouts/partials/strings/extract-github-objectives.html b/common-theme/layouts/partials/strings/extract-github-objectives.html index 6d951c184..b7f1ba572 100644 --- a/common-theme/layouts/partials/strings/extract-github-objectives.html +++ b/common-theme/layouts/partials/strings/extract-github-objectives.html @@ -1,11 +1,33 @@ -{{ $strippedText := . | replaceRE "" "" | replaceRE "\r\n" "\n" }} +{{ $url := .URL }} +{{ $body := .body }} + +{{ $strippedText := $body | replaceRE "" "" | replaceRE "\r\n" "\n" }} {{/* Find fenced objectives in text */}} {{ $regexFence := "```objectives\\s*([^`]*?)\\s*```" }} -{{ $extractedObjectives := findRE $regexFence $strippedText }} +{{ $extractedObjectivesBlocks := findRE $regexFence $strippedText }} {{/* Find shortcoded objectives in text */}} {{ $regexShortcode := "{{}}([^`]*?){{}}" }} -{{ $extractedObjectives = $extractedObjectives | append (findRE $regexShortcode $strippedText) }} +{{ $extractedShortcodeBlocks := findRE $regexShortcode $strippedText }} + + +{{ $extractedObjectives := slice }} +{{ range (slice $extractedObjectivesBlocks $extractedShortcodeBlocks) }} + {{ range . }} + {{ range (split . "\n")}} + {{ if or (eq . "{{}}") (eq . "{{}}") (eq . "```objectives") (eq . "```") (eq . "") }} + {{ continue }} + {{ else if hasPrefix . "- [ ] "}} + {{ $extractedObjectives = $extractedObjectives | append (substr . 6) }} + {{ else if hasPrefix . "- "}} + {{ $extractedObjectives = $extractedObjectives | append (printf "- [ ] %s" (substr . 2)) }} + {{ else }} + {{ errorf "Unexpected learning objective from remote content from URL %s: %s" $url . }} + {{ end }} + {{ end }} + {{ end }} +{{ end }} + {{ return $extractedObjectives }}