Skip to content

Commit

Permalink
Upgrade Hugo version to latest (0.142.0) (#1512)
Browse files Browse the repository at this point in the history
* Upgrade hugo version to 0.142.0

* Replace verbose with logLevel info

* Replace verbose with logLevel info in build.sh
  • Loading branch information
ibrahimjaved12 authored Feb 25, 2025
1 parent 1b05c76 commit 4bd10ce
Show file tree
Hide file tree
Showing 20 changed files with 488 additions and 668 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- name: Setup Hugo
uses: peaceiris/actions-hugo@75d2e84710de30f6ff7268e08f310b60ef14033f # v3
with:
hugo-version: "0.115.4"
hugo-version: "0.142.0"
extended: true

- name: Install dependencies
Expand Down
8 changes: 4 additions & 4 deletions base-theme/layouts/partials/featured_course_cards.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ <h2 class="{{ $klass }}">Featured Courses</h2>
{{ 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))}}
{{ else }}
{{ errorf "Failed to fetch featured course info from %v" $url }}
{{ end }}
{{ else }}
{{ errorf "Failed to fetch featured course info from %v" $url }}
{{ end }}
{{ end }}
</div>
Expand Down
8 changes: 4 additions & 4 deletions base-theme/layouts/partials/get_instructors.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
{{ 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 }}
{{ end }}
{{ end }}
{{ return $instructors }}
8 changes: 4 additions & 4 deletions base-theme/layouts/partials/get_site_metadata.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{{ $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 . }}
{{ else }}
{{ errorf "Failed to fetch course data from %v" $url }}
{{ end }}
{{ else }}
{{ errorf "Failed to fetch course data from %v" $url }}
{{ end }}
{{ return $courseData }}
10 changes: 5 additions & 5 deletions fields/layouts/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,18 @@ <h1>
{{- 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 }}
{{ else with .Value }}
{{- $data := . | unmarshal -}}
{{- $data = merge $data (dict "url_path" $id) -}}
{{- $subfield_data = $subfield_data | append (dict $id $data) -}}
{{ else }}
{{ $errorMessage := printf "Failed to fetch sub-fields through %v on %v" $url site.BaseURL }}
{{ partial "sentry_capture_message.html" $errorMessage }}
{{ end }}
{{ else }}
{{ $errorMessage := printf "Failed to fetch sub-fields through %v on %v" $url site.BaseURL }}
{{ partial "sentry_capture_message.html" $errorMessage }}
{{ end }}
{{- end -}}
{{ end }}
Expand Down
10 changes: 5 additions & 5 deletions fields/layouts/subfields/single.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@
{{- 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) -}}
{{ else }}
{{ $errorMessage := printf "Failed to fetch sub-field through %v on %v" $url site.BaseURL }}
{{ partial "sentry_capture_message.html" $errorMessage }}
{{ end }}
{{ else }}
{{ $errorMessage := printf "Failed to fetch sub-field through %v on %v" $url site.BaseURL }}
{{ partial "sentry_capture_message.html" $errorMessage }}
{{ end }}
{{- end -}}
{{ end }}
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
"clean-webpack-plugin": "^4.0.0",
"cli-table3": "^0.6.3",
"commander": "^12.0.0",
"concurrently": "^9.0.0",
"concurrently": "^6.3.0",
"copy-webpack-plugin": "^11.0.0",
"cross-env": "^7.0.0",
"css-loader": "^3.0.0",
Expand All @@ -113,9 +113,9 @@
"eslint-plugin-react-hooks": "^4.6.0",
"exec-sh": "^0.4.0",
"file-loader": "^5.0.2",
"hugo-bin-extended": "^0.119.0",
"hugo-bin-extended": "^0.142.0",
"imports-loader": "^0.8.0",
"inquirer": "^12.0.0",
"inquirer": "^8.2.5",
"jest": "^27.4.7",
"jest-fetch-mock": "^3.0.3",
"jest-watch-typeahead": "^2.2.0",
Expand Down
2 changes: 1 addition & 1 deletion package_scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ else
npm run build:webpack -- --output-path=$STATIC_PATH
cd $CONTENT_PATH
# Run Hugo build
hugo --config $CONFIG_PATH --themesDir $THEMES_PATH -d dist -v
hugo --config $CONFIG_PATH --themesDir $THEMES_PATH -d dist --logLevel info
GIT_HASH=`git rev-parse HEAD`
printf $GIT_HASH >> $STATIC_PATH/hash.txt
fi
22 changes: 15 additions & 7 deletions package_scripts/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,16 @@ type HugoServerOptions = {
bind: string
config: string
themesDir: string
renderToDisk: boolean
logLevel?: string
}

const hugoServer = (
opts: Partial<HugoServerOptions> & Pick<HugoServerOptions, "config">
) => {
const allOpts: HugoServerOptions = {
port: 3000,
bind: "0.0.0.0",
themesDir: process.cwd(),
renderToDisk: true,
port: 3000,
bind: "0.0.0.0",
themesDir: process.cwd(),
...opts
}
return `hugo server ${u.getOptions(allOpts)}`
Expand Down Expand Up @@ -162,7 +161,13 @@ const makeEnvOpt = (
]
}

const start = program.description("Start ocw-hugo-themes development servers.")
const start = program
.description("Start ocw-hugo-themes development servers.")
.option(
"--logLevel [value]",
"Set the log level for Hugo (options: debug, info, warn, error).",
"info"
)

type StartOptions = {
gitContentSource: string
Expand Down Expand Up @@ -194,10 +199,13 @@ const startSiteAction = async (opts: StartOptions, cliOptNames: string[]) => {

await ensureHugoConfig("COURSE_HUGO_CONFIG_PATH")

const globalOpts = program.opts() as { logLevel: string }
const logLevel = globalOpts.logLevel

startWebpackAnd({
name: "hugo",
cwd: opts.contentDir,
command: hugoServer({ config: opts.config })
command: hugoServer({ config: opts.config, logLevel })
})
}

Expand Down
7 changes: 4 additions & 3 deletions package_scripts/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ type HugoOptions = {
themesDir: string
config: string
destination: string
verbose?: boolean
environment?: "development" | "production"
logLevel?: string
cacheDir?: string
ignoreCache?: boolean
}
Expand All @@ -67,8 +67,9 @@ type HugoOptions = {
* for more.
*/
const hugo = (hugoOptions: HugoOptions, execOptions: SpawnOptions) => {
const flags = getOptions(hugoOptions)
return execSh(`yarn hugo ${flags} --verbose`, execOptions)
const opts = { ...hugoOptions, logLevel: hugoOptions.logLevel || "info" }
const flags = getOptions(opts)
return execSh(`yarn hugo ${flags}`, execOptions)
}

export type { HugoOptions }
Expand Down
3 changes: 1 addition & 2 deletions tests-e2e/LocalOcw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,7 @@ class LocalOCW {
destination: path.join(this.rootDestinationDir, destInTmp),
ignoreCache: true,
config: site.configPath,
baseURL: destInTmp,
verbose: true
baseURL: destInTmp
},
{
cwd: fromRoot(`./test-sites/${site.name}`),
Expand Down
3 changes: 2 additions & 1 deletion tests-e2e/fixtures.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ test("The fixtures are what Hugo would produce.", async () => {
* the test homepage.
*/
"courses/some-featured-course",
"courses/some-new-course"
"courses/some-new-course",
"ocw-ci-test-www/instructors/"
]

const fixtureDir = path.resolve(__dirname, "../test-sites/__fixtures__")
Expand Down
2 changes: 1 addition & 1 deletion tests-e2e/jest/build-failures.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const expectBuildError = async (
}

messages.forEach(msg => {
expect(error!.stdout).toMatch(msg)
expect(error!.stderr).toMatch(msg)
})
}

Expand Down
10 changes: 5 additions & 5 deletions www/layouts/collections/single.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,18 @@ <h1>
{{- 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) -}}
{{ else }}
{{ $errorMessage := printf "Failed to fetch course data from %v. Skipping %v on %v" $url $id $collection }}
{{ partial "sentry_capture_message.html" $errorMessage }}
{{ end }}
{{ else }}
{{ $errorMessage := printf "Failed to fetch course data from %v. Skipping %v on %v" $url $id $collection }}
{{ partial "sentry_capture_message.html" $errorMessage }}
{{ end }}
{{- end -}}
{{ end }}
Expand Down
10 changes: 5 additions & 5 deletions www/layouts/course-lists/single.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@
{{- 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) -}}
{{ else }}
{{ $errorMessage := printf "Failed to fetch course list through %v on %v" $url site.BaseURL }}
{{ partial "sentry_capture_message.html" $errorMessage }}
{{ end }}
{{ else }}
{{ $errorMessage := printf "Failed to fetch course list through %v on %v" $url site.BaseURL }}
{{ partial "sentry_capture_message.html" $errorMessage }}
{{ end }}
{{- end -}}
{{ end }}
Expand Down
18 changes: 10 additions & 8 deletions www/layouts/partials/new_course_cards.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
{{ $courseStarterSlug := getenv "OCW_COURSE_STARTER_SLUG" }}
{{ $coursesQuery := querify "type" $courseStarterSlug "limit" 12 }}
{{ $coursesURL := (print (strings.TrimSuffix "/" $studioBaseUrl) "/api/websites/?" $coursesQuery) }}
{{ with resources.GetRemote $coursesURL }}
{{ if not .Err }}
{{ with try (resources.GetRemote $coursesURL) }}
{{ with .Err }}
{{ errorf "Failed to fetch new courses list from %v with error %v" $coursesURL . }}
{{ else with .Value }}
{{ $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")) }}
Expand All @@ -26,15 +28,15 @@ <h2>New Courses</h2>
{{ range $index, $courseItem := $resultsSlice }}
{{- if $courseItem.url_path -}}
{{- $url := delimit (slice (strings.TrimSuffix "/" $staticApiBaseUrl) "/" $courseItem.url_path "/data.json") "" -}}
{{ with resources.GetRemote $url }}
{{ with try (resources.GetRemote $url) }}
{{ with .Err }}
{{ errorf "Failed to fetch new 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" $courseItem.url_path "numCourses" (len $resultsSlice))}}
{{ else }}
{{ errorf "Failed to fetch new course info from %v" $url }}
{{ end }}
{{ else }}
{{ errorf "Failed to fetch new course info from %v" $url }}
{{ end }}
{{- end -}}
{{ end }}
Expand All @@ -45,8 +47,8 @@ <h2>New Courses</h2>
{{ else }}
No new courses found
{{ end }}
{{ else }}
{{ errorf "Failed to fetch new courses list from %v" $coursesURL }}
{{ end }}
{{ else }}
{{ errorf "Failed to fetch new courses list from %v" $coursesURL }}
{{ end }}
</div>
10 changes: 5 additions & 5 deletions www/layouts/partials/ocw_news.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
{{ $studioBaseUrl := partial "ocw_studio_base_url.html" }}
{{ if $studioBaseUrl }}
{{- $url := (print (strings.TrimSuffix "/" $studioBaseUrl) "/api/news/") -}}
{{ with resources.GetRemote $url }}
{{ with try (resources.GetRemote $url) }}
{{ with .Err }}
{{ $errorMessage := printf "OCW News on %v failed to fetch %v with error: %v" site.BaseURL $url . }}
{{ partial "sentry_capture_message.html" $errorMessage }}
{{ else }}
{{ else with .Value }}
{{ $items := (. | unmarshal).items }}
{{ if $items }}
{{ $breakdowns := (dict "xs-sm" (dict "size" 1 "class" "d-flex d-lg-none") )}}
Expand Down Expand Up @@ -103,10 +103,10 @@ <h3 class="">
{{ else }}
No news items found
{{ end }}
{{ else }}
{{ $errorMessage := printf "Failed to fetch news items through %v on %v" $url site.BaseURL }}
{{ partial "sentry_capture_message.html" $errorMessage }}
{{ end }}
{{ else }}
{{ $errorMessage := printf "Failed to fetch news items through %v on %v" $url site.BaseURL }}
{{ partial "sentry_capture_message.html" $errorMessage }}
{{ end }}
{{ else }}
OCW Studio URL not configured
Expand Down
Loading

0 comments on commit 4bd10ce

Please sign in to comment.