Skip to content

Commit 178b839

Browse files
Copilotcycomachead
andauthored
fix: validate archive path and use berkeley rose color variable
Agent-Logs-Url: https://github.com/berkeley-cdss/berkeley-class-site/sessions/3cf00aba-dd2e-446c-ba39-1db759bf2bf3 Co-authored-by: cycomachead <1505907+cycomachead@users.noreply.github.com>
1 parent 5e4b626 commit 178b839

5 files changed

Lines changed: 42 additions & 7 deletions

File tree

_config.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,8 @@ logo: /assets/images/berkeley_walking_bear.png
4444
# This should be one of eecs, dsus, stat
4545
# (Future) This will control some footer text, and later custom styling.
4646
course_department: dsus
47-
# This should be the page of all class archives
48-
# Typically just / for DS courses (with a visible index page), or /archives if you're hosting your own, or a link to the inst.eecs page
49-
# If you have no archive page, comment this line out or leave blank.
47+
# This path/URL is used by the archive banner shown when the site date is outside the semester window.
48+
# Keep this key present. Default `/` is fine for class-listing homepages, and `/archive` is also a good option.
5049
# We recommend listing archived offerings as "Archive" or "Not Updated" in course listings.
5150
class_archive_path: /
5251

_plugins/config_validator.rb

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# frozen_string_literal: true
22

33
require 'date'
4+
require 'uri'
45

56
# A UC Berkeley-specific validator for Jekyll sites
67
# This class validates the following options:
@@ -48,7 +49,8 @@ class ConfigValidator
4849
course_department: :inclusion_validator,
4950
color_scheme: :inclusion_validator,
5051
semester_start_date: :validate_iso8601_date,
51-
semester_end_date: :validate_iso8601_date
52+
semester_end_date: :validate_iso8601_date,
53+
class_archive_path: :validate_archive_path
5254
}.freeze
5355

5456
attr_accessor :config, :errors
@@ -73,7 +75,7 @@ def validate
7375
end
7476

7577
def validate_keys!
76-
required_keys = %i[baseurl course_department semester_start_date semester_end_date]
78+
required_keys = %i[baseurl course_department semester_start_date semester_end_date class_archive_path]
7779
required_keys.each do |key|
7880
errors << "#{key} is missing from site config" unless @config.key?(key.to_s)
7981
end
@@ -117,6 +119,19 @@ def validate_semester_date_range
117119
errors << '`semester_start_date` must be on or before `semester_end_date`'
118120
end
119121

122+
def validate_archive_path(_key, value)
123+
path = value.to_s.strip
124+
return errors << '`class_archive_path` cannot be blank' if path.empty?
125+
return if path.match?(%r{^/})
126+
127+
uri = URI.parse(path)
128+
return if uri.is_a?(URI::HTTP) && uri.host
129+
130+
errors << "`class_archive_path` must be an absolute path starting with `/` or a full URL, not '#{value}'"
131+
rescue URI::InvalidURIError
132+
errors << "`class_archive_path` must be an absolute path starting with `/` or a full URL, not '#{value}'"
133+
end
134+
120135
def parse_iso8601_date(value)
121136
Date.iso8601(value.to_s)
122137
rescue Date::Error

_sass/berkeley/variables.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ $serif-font-family: 'Source Serif 4', 'Georiga', 'Baskerville', serif;
1212

1313
$berkeley-blue-old: #003262;
1414
$berkeley-blue: #002676; // rgb(0, 38, 118);
15+
$berkeley-rose-medium: #d02670;
1516

1617
// Colors
1718
$link-color: $berkeley-blue;

_sass/custom/custom.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ p.note::before {
149149
left: 0;
150150
z-index: 999;
151151
padding: 0.75rem 1rem;
152-
background-color: #d02670;
152+
background-color: $berkeley-rose-medium;
153153
color: #fff;
154154
font-weight: 700;
155155
text-align: center;

spec/jekyll/config_validator_spec.rb

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
'baseurl' => '/sp26',
1010
'course_department' => 'dsus',
1111
'semester_start_date' => '2026-01-21',
12-
'semester_end_date' => '2026-05-09'
12+
'semester_end_date' => '2026-05-09',
13+
'class_archive_path' => '/'
1314
}
1415
end
1516

@@ -27,6 +28,25 @@
2728
.to raise_error(ConfigValidationError, /semester_start_date is missing.*semester_end_date is missing/m)
2829
end
2930

31+
it 'requires class_archive_path' do
32+
validator = described_class.new(base_config.except('class_archive_path'))
33+
34+
expect { validator.validate }
35+
.to raise_error(ConfigValidationError, /class_archive_path is missing from site config/)
36+
end
37+
38+
it 'allows class_archive_path as a full URL' do
39+
validator = described_class.new(base_config.merge('class_archive_path' => 'https://c88c.org/archive'))
40+
41+
expect { validator.validate }.not_to raise_error
42+
end
43+
44+
it 'rejects class_archive_path values that are not paths or full URLs' do
45+
validator = described_class.new(base_config.merge('class_archive_path' => 'archive'))
46+
expected = %r{`class_archive_path` must be an absolute path starting with `/` or a full URL}
47+
expect { validator.validate }.to raise_error(ConfigValidationError, expected)
48+
end
49+
3050
it 'validates ISO-8601 semester dates' do
3151
validator = described_class.new(base_config.merge('semester_start_date' => 'spring-2026'))
3252

0 commit comments

Comments
 (0)