Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade hugo version to latest #1512

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
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
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@16361eb4acea8698b220b76c0d4e84e1fd22c61d # v2
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.119.0",
"hugo-bin-extended": "^0.142.0",
"imports-loader": "^0.8.0",
"inquirer": "^12.0.0",
"jest": "^27.4.7",
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
23 changes: 16 additions & 7 deletions package_scripts/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ 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(),
logLevel: opts.logLevel || "info",
...opts
}
return `hugo server ${u.getOptions(allOpts)}`
Expand Down Expand Up @@ -162,7 +162,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 +200,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 || "info"

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
Loading