diff --git a/base-theme/layouts/partials/featured_course_cards.html b/base-theme/layouts/partials/featured_course_cards.html index 10b85b9a6..e23cf7dc1 100644 --- a/base-theme/layouts/partials/featured_course_cards.html +++ b/base-theme/layouts/partials/featured_course_cards.html @@ -23,10 +23,10 @@

Featured Courses

{{ range $index, $courseItem := $courses }} {{- $urlPath := partial "site_root_url.html" $courseItem.id -}} {{- $url := delimit (slice (strings.TrimSuffix "/" $staticApiBaseUrl) $urlPath "/data.json") "" -}} - {{ with resources.GetRemote $url }} + {{ with try (resources.GetRemote $url) }} {{ with .Err }} {{ errorf "Failed to fetch featured course info from %v with error %v" $url . }} - {{ else }} + {{ else with .Value }} {{- $courseData := . | unmarshal -}} {{ partial "course_carousel_card.html" (dict "itemsInCarousel" $itemsInCarousel "courseData" $courseData "index" $index "urlPath" $urlPath "numCourses" (len $courses))}} {{ end }} diff --git a/base-theme/layouts/partials/get_instructors.html b/base-theme/layouts/partials/get_instructors.html index 912c3e11c..e5448672b 100644 --- a/base-theme/layouts/partials/get_instructors.html +++ b/base-theme/layouts/partials/get_instructors.html @@ -2,14 +2,16 @@ {{ range . }} {{ $staticApiBaseUrl := getenv "STATIC_API_BASE_URL" }} {{ $url := (print (strings.TrimSuffix "/" $staticApiBaseUrl) "/instructors/" . "/index.json") }} - {{ with resources.GetRemote $url }} + {{ with try (resources.GetRemote $url) }} {{ with .Err }} {{ errorf "Failed to fetch instructors from %v with error %v" $url . }} - {{ else }} + {{ else with .Value }} {{ $data := (. | unmarshal).data }} {{ $searchUrl := partial "get_search_url.html" (dict "key" "instructors" "value" (title $data.title)) }} {{ $instructor := merge $data (dict "url" $searchUrl) }} {{ $instructors = $instructors | append $instructor }} + {{ else }} + {{ errorf "Failed to fetch instructors from %v" $url }} {{ end }} {{ else }} {{ errorf "Failed to fetch instructors from %v" $url }} diff --git a/base-theme/layouts/partials/get_site_metadata.html b/base-theme/layouts/partials/get_site_metadata.html index ce60c8288..c687a257c 100644 --- a/base-theme/layouts/partials/get_site_metadata.html +++ b/base-theme/layouts/partials/get_site_metadata.html @@ -1,10 +1,10 @@ {{ $courseData := slice }} {{ $staticApiBaseUrl := getenv "STATIC_API_BASE_URL" }} {{ $url := (print (strings.TrimSuffix "/" $staticApiBaseUrl) "/" . "/data.json") }} -{{ with resources.GetRemote $url }} +{{ with try (resources.GetRemote $url) }} {{ with .Err }} {{ errorf "Failed to fetch course data from %v with error %v" $url . }} - {{ else }} + {{ else with .Value }} {{ $courseData = unmarshal . }} {{ end }} {{ else }} diff --git a/fields/layouts/home.html b/fields/layouts/home.html index 3738a7a24..943b66fad 100644 --- a/fields/layouts/home.html +++ b/fields/layouts/home.html @@ -37,14 +37,14 @@

{{- range (first 5 $subfield.Params.courses) -}} {{- $id := .id -}} {{- $url := delimit (slice (strings.TrimSuffix "/" $staticApiBaseUrl) "/" $id "/data.json") "" -}} - {{ with resources.GetRemote $url }} + {{ with try (resources.GetRemote $url) }} {{ with .Err }} {{- $errorMessage := printf "Failed to fetch sub-fields on %v via %v with error: %v" site.BaseURL $url . -}} - {{- partial "sentry_capture_message.html" $errorMessage -}} - {{ else }} + {{- partial "sentry_capture_message.html" $errorMessage -}} + {{ else with .Value }} {{- $data := . | unmarshal -}} - {{- $data = merge $data (dict "url_path" $id) -}} - {{- $subfield_data = $subfield_data | append (dict $id $data) -}} + {{- $data = merge $data (dict "url_path" $id) -}} + {{- $subfield_data = $subfield_data | append (dict $id $data) -}} {{ end }} {{ else }} {{ $errorMessage := printf "Failed to fetch sub-fields through %v on %v" $url site.BaseURL }} diff --git a/fields/layouts/subfields/single.html b/fields/layouts/subfields/single.html index d2eca5356..9c9a46829 100644 --- a/fields/layouts/subfields/single.html +++ b/fields/layouts/subfields/single.html @@ -14,11 +14,11 @@ {{- range $courselist.Params.courses -}} {{- $id := .id -}} {{- $url := delimit (slice (strings.TrimSuffix "/" $staticApiBaseUrl) "/" .id "/data.json") "" -}} - {{ with resources.GetRemote $url }} + {{ with try (resources.GetRemote $url) }} {{ with .Err }} {{- $errorMessage := printf "Failed to fetch sub-field on %v via %v with error: %v" site.BaseURL $url . -}} {{- partial "sentry_capture_message.html" $errorMessage -}} - {{ else }} + {{ else with .Value }} {{- $data := . | unmarshal -}} {{- $data = merge $data (dict "url_path" $id) -}} {{- $courseListData = $courseListData | append (dict $id $data) -}} diff --git a/package.json b/package.json index 6b2a19ca8..99ae4d34b 100644 --- a/package.json +++ b/package.json @@ -113,7 +113,7 @@ "eslint-plugin-react-hooks": "^4.6.0", "exec-sh": "^0.4.0", "file-loader": "^5.0.2", - "hugo-bin-extended": "^0.139.0", + "hugo-bin-extended": "^0.141.0", "imports-loader": "^0.8.0", "inquirer": "^12.0.0", "jest": "^27.4.7", diff --git a/www/layouts/collections/single.html b/www/layouts/collections/single.html index 86ce001da..b8f6c1207 100644 --- a/www/layouts/collections/single.html +++ b/www/layouts/collections/single.html @@ -37,11 +37,11 @@

{{- range (first 5 $course_list.Params.courses) -}} {{- $id := .id -}} {{- $url := delimit (slice (strings.TrimSuffix "/" $staticApiBaseUrl) "/" $id "/data.json") "" -}} - {{ with resources.GetRemote $url }} + {{ with try (resources.GetRemote $url) }} {{ with .Err }} {{- $errorMessage := printf "Failed to fetch collections on %v via %v with error: %v" site.BaseURL $url . -}} {{- partial "sentry_capture_message.html" $errorMessage -}} - {{ else }} + {{ else with .Value }} {{- $data := . | unmarshal -}} {{- $data = merge $data (dict "url_path" $id) -}} {{- $course_list_data = $course_list_data | append (dict $id $data) -}} diff --git a/www/layouts/course-lists/single.html b/www/layouts/course-lists/single.html index 8bd9504f5..b704d484d 100644 --- a/www/layouts/course-lists/single.html +++ b/www/layouts/course-lists/single.html @@ -14,11 +14,11 @@ {{- range $courselist.Params.courses -}} {{- $id := .id -}} {{- $url := delimit (slice (strings.TrimSuffix "/" $staticApiBaseUrl) "/" $id "/data.json") "" -}} - {{ with resources.GetRemote $url }} + {{ with try (resources.GetRemote $url) }} {{ with .Err }} {{- $errorMessage := printf "Something went wrong while fetching course list on %v via %v with error: %v" site.BaseURL $url . -}} {{- partial "sentry_capture_message.html" $errorMessage -}} - {{ else }} + {{ else with .Value }} {{- $data := . | unmarshal -}} {{- $data = merge $data (dict "url_path" $id) -}} {{- $courseListData = $courseListData | append (dict $id $data) -}} @@ -35,4 +35,4 @@ window.courseListsData = JSON.parse("{{ $courseListsData | jsonify }}"); -{{ end }} \ No newline at end of file +{{ end }} diff --git a/www/layouts/partials/new_course_cards.html b/www/layouts/partials/new_course_cards.html index 414047276..e9dbbd518 100644 --- a/www/layouts/partials/new_course_cards.html +++ b/www/layouts/partials/new_course_cards.html @@ -4,46 +4,48 @@ {{ $courseStarterSlug := getenv "OCW_COURSE_STARTER_SLUG" }} {{ $coursesQuery := querify "type" $courseStarterSlug "limit" 12 }} {{ $coursesURL := (print (strings.TrimSuffix "/" $studioBaseUrl) "/api/websites/?" $coursesQuery) }} -{{ with resources.GetRemote $coursesURL }} +{{ with try (resources.GetRemote $coursesURL) }} {{ if not .Err }} - {{ $results := (. | unmarshal).results }} - {{ if $results }} - {{ $breakdowns := (dict "xs-sm" (dict "size" 1 "class" "d-flex d-md-none") "md" (dict "size" 2 "class" "d-none d-md-flex d-lg-none") "lg" (dict "size" 3 "class" "d-none d-lg-flex d-xl-none") "xl" (dict "size" 4 "class" "d-none d-xl-flex")) }} - - {{ range $breakpoint, $carouselInfo := $breakdowns }} - {{ $itemsInCarousel := index $carouselInfo "size" }} - {{ $breakpointVisibilityClass := index $carouselInfo "class" }} - {{ $isMobile := (eq $itemsInCarousel 1) }} - {{ $carouselId := (printf "new-course-carousel-%v" $breakpoint) }} -
- -{{ end }} \ No newline at end of file +{{ end }} diff --git a/www/layouts/sitemap.xml b/www/layouts/sitemap.xml index 6a8b3f3b2..b45f97fe2 100644 --- a/www/layouts/sitemap.xml +++ b/www/layouts/sitemap.xml @@ -10,20 +10,26 @@ {{- if and $studioBaseUrl (ne $apiBearerToken "") -}} {{- $apiUrl := printf "%v/api/publish?%v" (strings.TrimSuffix "/" $studioBaseUrl) $queryString -}} {{- $apiHeaders := dict "headers" (dict "Authorization" (printf "Bearer %v" $apiBearerToken)) -}} - {{- $coursesJson := resources.GetRemote $apiUrl $apiHeaders -}} - {{- with transform.Unmarshal $coursesJson -}} - {{- $sites := .sites -}} - {{- if $sites -}} - {{ range $index, $courseItem := $sites }} - {{- $path := strings.TrimPrefix "/" (strings.TrimSuffix "/" $courseItem.base_url) -}} - {{- if not (eq $path "") -}} - {{- $url := printf "https://%v/%v/sitemap.xml" $sitemapDomain $path -}} - - {{ $url }} - + {{- with try (resources.GetRemote $apiUrl $apiHeaders) -}} + {{- with .Err -}} + {{ errorf "Failed to fetch sitemap from studio: %v" . }} + {{- end -}} + {{- with .Value -}} + {{- with transform.Unmarshal . -}} + {{- $sites := .sites -}} + {{- if $sites -}} + {{ range $index, $courseItem := $sites }} + {{- $path := strings.TrimPrefix "/" (strings.TrimSuffix "/" $courseItem.base_url) -}} + {{- if not (eq $path "") -}} + {{- $url := printf "https://%v/%v/sitemap.xml" $sitemapDomain $path -}} + + {{ $url }} + + {{- end -}} + {{ end }} {{- end -}} - {{ end }} + {{- end -}} {{- end -}} {{- end -}} {{- end -}} - \ No newline at end of file + diff --git a/yarn.lock b/yarn.lock index ea7698866..35812b1cc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8096,15 +8096,15 @@ __metadata: languageName: node linkType: hard -"hugo-bin-extended@npm:^0.139.0": - version: 0.139.4 - resolution: "hugo-bin-extended@npm:0.139.4" +"hugo-bin-extended@npm:^0.141.0": + version: 0.141.0 + resolution: "hugo-bin-extended@npm:0.141.0" dependencies: "@xhmikosr/bin-wrapper": ^13.0.5 package-config: ^5.0.0 bin: hugo: bin/cli.js - checksum: 64919c80a22663c85ab0650522785066c077eff06a3e2dbaf027908e42448005de0649b41140fdb91fa0ff29fd32ea5d06772764cef3b10e3e8534091d49e424 + checksum: 4885b9e79e88acc89123bad47c24a8b7f30ae9393c687b9dbecedc6fe912a525fe535eddc55aeca9790ff0cda58f9e1e87f9f8017b37743931e6fc95eda74919 languageName: node linkType: hard @@ -11277,7 +11277,7 @@ __metadata: file-loader: ^5.0.2 fuse.js: ^6.6.2 history: ^5.3.0 - hugo-bin-extended: ^0.139.0 + hugo-bin-extended: ^0.141.0 imports-loader: ^0.8.0 inquirer: ^12.0.0 isomorphic-fetch: ^3.0.0