Skip to content

Commit 9d230a9

Browse files
authored
Include links to original sources in success pages (#1730)
This: * Makes it easier to see what things are self-study vs have expected evidence from backlog. * Makes it easier to link back to where the topics were introduced. The way we go about this is: 1. When fetching remote learning objectives, parse out to accumulate the list of LOs, rather than just grabbing the whole markdown block 2. Pass LOs through a `{{<objectives>}}` shortcode, rather than just pulling the shortcode in through the raw markdown. 3. Pass links to the original blocks into the rendering block. 4. Send both local and remote learning objectives through the same rendering block (`common-theme/layouts/partials/objectives/for-success.html`) which now includes links back.
1 parent f171c63 commit 9d230a9

File tree

7 files changed

+52
-23
lines changed

7 files changed

+52
-23
lines changed

common-theme/layouts/_default/success.html

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,16 @@ <h2 class="e-heading__4 c-objectives__title is-invisible">
8585
{{ partial "block/data.html" (dict "Scratch" $.Page.Scratch "src" $src "name" $name "page" .) }}
8686
{{/* Retrieve the blockData from Scratch */}}
8787
{{ $blockData := $.Page.Scratch.Get "blockData" }}
88+
{{ $links := slice }}
89+
{{ $anchorifiedName := $name | urlize }}
90+
{{ if in $prep.Params.blocks . }}{{ $links = $links | append (dict "href" (printf "../prep#%s" $anchorifiedName) "text" "Prep") }}{{ end }}
91+
{{ if in $issueBlocks . }}{{ $links = $links | append (dict "href" (printf "../backlog#%s" $anchorifiedName) "text" "Backlog") }}{{ end }}
92+
{{ if in $dayplan.Params.blocks . }}{{ $links = $links | append (dict "href" (printf "../day-plan#%s" $anchorifiedName) "text" "Day Plan") }}{{ end }}
8893
{{/* Depending on the type of block, call the appropriate partial */}}
8994
{{ if or (eq $blockData.type "readme") (eq $blockData.type "issue") }}
90-
{{ partial "objectives/remote" (dict "blockData" $blockData "pageContext" $pageContext "showTitle" $blockData.name) }}
95+
{{ partial "objectives/remote" (dict "blockData" $blockData "pageContext" $pageContext "title" $blockData.name "links" $links ) }}
9196
{{ else }}
92-
{{ partial "objectives/local.html" (dict "blockData" $blockData "pageContext" $pageContext "showTitle" true) }}
97+
{{ partial "objectives/local.html" (dict "blockData" $blockData "pageContext" $pageContext "showTitle" true "links" $links) }}
9398
{{ end }}
9499

95100
{{ end }}

common-theme/layouts/partials/block/issue.html

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
{{ end }}
2424

2525
{{/* extract objectives */}}
26-
{{ $extractedObjectives := partial "strings/extract-github-objectives.html" $response.body }}
26+
{{ $extractedObjectives := partial "strings/extract-github-objectives.html" (dict "URL" $blockData.api "body" $response.body) }}
2727
{{/* remove "Learning Objectives" heading from remaining text */}}
2828
{{ $strippedBody := replace $response.body "### Learning Objectives" "" }}
2929

@@ -32,9 +32,7 @@
3232
<summary>
3333
<h3 class="e-heading__4">Learning Objectives</h3>
3434
</summary>
35-
{{ range $extractedObjectives }}
36-
{{ . | page.RenderString }}
37-
{{ end }}
35+
{{ partial "objectives/block" $extractedObjectives }}
3836
</details>
3937
{{ end }}
4038
</header>

common-theme/layouts/partials/block/readme.html

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,11 @@
2828
</h2>
2929
{{ partial "time.html" $pageContext }}
3030
</header>
31-
{{ $extractedObjectives := partial "strings/extract-github-objectives.html" $decodedContent }}
31+
{{ $extractedObjectives := partial "strings/extract-github-objectives.html" (dict "URL" $blockData.api "body" $decodedContent) }}
3232
{{ if gt (len $extractedObjectives) 0 }}
3333
<details open>
3434
<summary><h3 class="e-heading__5">Learning Objectives</h3></summary>
35-
{{ range $extractedObjectives }}
36-
{{ . | page.RenderString }}
37-
{{ end }}
35+
{{ partial "objectives/block" $extractedObjectives }}
3836
</details>
3937
{{ end }}
4038
<div class="c-block__content c-copy">
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{{ $scope := . }}
2+
{{ $objectives := $scope.objectives }}
3+
{{ $showTitle := $scope.showTitle }}
4+
{{ $title := $scope.title }}
5+
{{ $links := $scope.links }}
6+
7+
{{ if $showTitle }}<h5>{{ $title }}{{range $links}} (<a class="e-link" href="{{ .href }}">{{.text}}</a>){{end}}</h5>{{ end }}
8+
{{ partial "objectives/block.html" $objectives }}

common-theme/layouts/partials/objectives/local.html

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
{{ $localBlock := $pageContext.GetPage $scope.blockData.api }}
88
{{ $showTitle := .showTitle |default false }}
99

10-
{{ with $localBlock.Page.Params.Objectives }}
11-
{{ if $showTitle }}<h5>{{ $localBlock.Page.Title }}</h5>{{ end }}
12-
{{ partial "objectives/block.html" . }}
10+
{{ if $localBlock.Page.Params.Objectives }}
11+
{{ partial "objectives/for-success.html" (dict "objectives" $localBlock.Page.Params.Objectives "showTitle" $showTitle "title" $localBlock.Page.Title "links" $scope.links) }}
1312
{{ end }}

common-theme/layouts/partials/objectives/remote.html

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44

55
{{ $response := resources.GetRemote .blockData.api .blockData.headers }}
66
{{ $blockType := .blockData.type }}
7-
{{ $showTitle := .showTitle | default false }}
7+
{{ $title := .title }}
8+
{{ $links := .links }}
9+
{{ $url := .blockData.api }}
810
{{/* 404s lead to GetRemote returning nil rather than an error. */}}
911
{{ if eq $response nil }}
10-
{{ errorf "Couldn't find anything at %s" .blockData.api }}
12+
{{ errorf "Couldn't find anything at %s" $url }}
1113
{{ end }}
1214

1315
{{ with $response }}
@@ -20,11 +22,8 @@
2022
{{ $response = $response.body }}
2123
{{ end }}
2224

23-
{{ $extractedObjectives := partial "strings/extract-github-objectives.html" $response }}
25+
{{ $extractedObjectives := partial "strings/extract-github-objectives.html" (dict "URL" $url "body" $response) }}
2426
{{ if gt (len $extractedObjectives) 0 }}
25-
{{ if $showTitle }}<h5>{{ $showTitle }}</h5>{{ end }}
26-
{{ range $extractedObjectives }}
27-
{{ . | page.RenderString }}
28-
{{ end }}
27+
{{ partial "objectives/for-success.html" (dict "objectives" $extractedObjectives "showTitle" $title "title" $title "links" $links) }}
2928
{{ end }}
3029
{{ end }}
Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,33 @@
1-
{{ $strippedText := . | replaceRE "<!--|-->" "" | replaceRE "\r\n" "\n" }}
1+
{{ $url := .URL }}
2+
{{ $body := .body }}
3+
4+
{{ $strippedText := $body | replaceRE "<!--|-->" "" | replaceRE "\r\n" "\n" }}
25

36
{{/* Find fenced objectives in text */}}
47
{{ $regexFence := "```objectives\\s*([^`]*?)\\s*```" }}
5-
{{ $extractedObjectives := findRE $regexFence $strippedText }}
8+
{{ $extractedObjectivesBlocks := findRE $regexFence $strippedText }}
69

710
{{/* Find shortcoded objectives in text */}}
811
<!--prettier-ignore-->
912
{{ $regexShortcode := "{{<objectives>}}([^`]*?){{</objectives>}}" }}
10-
{{ $extractedObjectives = $extractedObjectives | append (findRE $regexShortcode $strippedText) }}
13+
{{ $extractedShortcodeBlocks := findRE $regexShortcode $strippedText }}
14+
15+
16+
{{ $extractedObjectives := slice }}
17+
{{ range (slice $extractedObjectivesBlocks $extractedShortcodeBlocks) }}
18+
{{ range . }}
19+
{{ range (split . "\n")}}
20+
{{ if or (eq . "{{<objectives>}}") (eq . "{{</objectives>}}") (eq . "```objectives") (eq . "```") (eq . "") }}
21+
{{ continue }}
22+
{{ else if hasPrefix . "- [ ] "}}
23+
{{ $extractedObjectives = $extractedObjectives | append (substr . 6) }}
24+
{{ else if hasPrefix . "- "}}
25+
{{ $extractedObjectives = $extractedObjectives | append (printf "- [ ] %s" (substr . 2)) }}
26+
{{ else }}
27+
{{ errorf "Unexpected learning objective from remote content from URL %s: %s" $url . }}
28+
{{ end }}
29+
{{ end }}
30+
{{ end }}
31+
{{ end }}
32+
1133
{{ return $extractedObjectives }}

0 commit comments

Comments
 (0)