Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions common-theme/layouts/_default/success.html
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,16 @@ <h2 class="e-heading__4 c-objectives__title is-invisible">
{{ partial "block/data.html" (dict "Scratch" $.Page.Scratch "src" $src "name" $name "page" .) }}
{{/* Retrieve the blockData from Scratch */}}
{{ $blockData := $.Page.Scratch.Get "blockData" }}
{{ $links := slice }}
{{ $anchorifiedName := $name | urlize }}
{{ if in $prep.Params.blocks . }}{{ $links = $links | append (dict "href" (printf "../prep#%s" $anchorifiedName) "text" "Prep") }}{{ end }}
{{ if in $issueBlocks . }}{{ $links = $links | append (dict "href" (printf "../backlog#%s" $anchorifiedName) "text" "Backlog") }}{{ end }}
{{ if in $dayplan.Params.blocks . }}{{ $links = $links | append (dict "href" (printf "../day-plan#%s" $anchorifiedName) "text" "Day Plan") }}{{ end }}
{{/* Depending on the type of block, call the appropriate partial */}}
{{ if or (eq $blockData.type "readme") (eq $blockData.type "issue") }}
{{ partial "objectives/remote" (dict "blockData" $blockData "pageContext" $pageContext "showTitle" $blockData.name) }}
{{ partial "objectives/remote" (dict "blockData" $blockData "pageContext" $pageContext "title" $blockData.name "links" $links ) }}
{{ else }}
{{ partial "objectives/local.html" (dict "blockData" $blockData "pageContext" $pageContext "showTitle" true) }}
{{ partial "objectives/local.html" (dict "blockData" $blockData "pageContext" $pageContext "showTitle" true "links" $links) }}
{{ end }}

{{ end }}
Expand Down
6 changes: 2 additions & 4 deletions common-theme/layouts/partials/block/issue.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
{{ end }}

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

Expand All @@ -32,9 +32,7 @@
<summary>
<h3 class="e-heading__4">Learning Objectives</h3>
</summary>
{{ range $extractedObjectives }}
{{ . | page.RenderString }}
{{ end }}
{{ partial "objectives/block" $extractedObjectives }}
</details>
{{ end }}
</header>
Expand Down
6 changes: 2 additions & 4 deletions common-theme/layouts/partials/block/readme.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,11 @@
</h2>
{{ partial "time.html" $pageContext }}
</header>
{{ $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 }}
<details open>
<summary><h3 class="e-heading__5">Learning Objectives</h3></summary>
{{ range $extractedObjectives }}
{{ . | page.RenderString }}
{{ end }}
{{ partial "objectives/block" $extractedObjectives }}
</details>
{{ end }}
<div class="c-block__content c-copy">
Expand Down
8 changes: 8 additions & 0 deletions common-theme/layouts/partials/objectives/for-success.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{{ $scope := . }}
{{ $objectives := $scope.objectives }}
{{ $showTitle := $scope.showTitle }}
{{ $title := $scope.title }}
{{ $links := $scope.links }}

{{ if $showTitle }}<h5>{{ $title }} {{range $links}}<a class="e-button" href="{{ .href }}">{{.text}}</a>{{end}}</h5>{{ end }}
{{ partial "objectives/block.html" $objectives }}
5 changes: 2 additions & 3 deletions common-theme/layouts/partials/objectives/local.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
{{ $localBlock := $pageContext.GetPage $scope.blockData.api }}
{{ $showTitle := .showTitle |default false }}

{{ with $localBlock.Page.Params.Objectives }}
{{ if $showTitle }}<h5>{{ $localBlock.Page.Title }}</h5>{{ 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 }}
13 changes: 6 additions & 7 deletions common-theme/layouts/partials/objectives/remote.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -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 }}<h5>{{ $showTitle }}</h5>{{ end }}
{{ range $extractedObjectives }}
{{ . | page.RenderString }}
{{ end }}
{{ partial "objectives/for-success.html" (dict "objectives" $extractedObjectives "showTitle" $title "title" $title "links" $links) }}
{{ end }}
{{ end }}
Original file line number Diff line number Diff line change
@@ -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 */}}
<!--prettier-ignore-->
{{ $regexShortcode := "{{<objectives>}}([^`]*?){{</objectives>}}" }}
{{ $extractedObjectives = $extractedObjectives | append (findRE $regexShortcode $strippedText) }}
{{ $extractedShortcodeBlocks := findRE $regexShortcode $strippedText }}


{{ $extractedObjectives := slice }}
{{ range (slice $extractedObjectivesBlocks $extractedShortcodeBlocks) }}
{{ range . }}
{{ range (split . "\n")}}
{{ if or (eq . "{{<objectives>}}") (eq . "{{</objectives>}}") (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 }}
Loading