Skip to content

Commit

Permalink
Merge pull request #33 from berkeley-cdss/minor-a11y-templates
Browse files Browse the repository at this point in the history
A11Y + Template Enhancements
  • Loading branch information
cycomachead authored Aug 11, 2024
2 parents 107b3bc + 8c395a0 commit 39231cf
Show file tree
Hide file tree
Showing 51 changed files with 32,234 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ _site/

node_modules/
vendor/
!assets/vendor/
tmp/
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require:
- rubocop-rspec
- rubocop-capybara

AllCops:
NewCops: enable
11 changes: 9 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
# frozen_string_literal: true

source 'https://rubygems.org'
gem 'jekyll-sitemap'
gem 'just-the-docs'

gem 'faraday-retry', '~> 2.2'
gem 'kramdown-parser-gfm'
gem 'webrick'

group :jekyll_plugins do
gem 'jekyll-github-metadata', '~> 2.16'
gem 'jekyll-sitemap'
gem 'just-the-docs'
end

group :development, :test do
gem 'axe-core-capybara'
gem 'axe-core-rspec'
Expand All @@ -18,5 +24,6 @@ end

group :development, :rubocop do
gem 'rubocop', require: false
gem 'rubocop-capybara', require: false
gem 'rubocop-rspec', require: false
end
25 changes: 25 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ GEM
eventmachine (>= 0.12.9)
http_parser.rb (~> 0)
eventmachine (1.2.7)
faraday (2.10.1)
faraday-net_http (>= 2.0, < 3.2)
logger
faraday-net_http (3.1.1)
net-http
faraday-retry (2.2.1)
faraday (~> 2.0)
ffi (1.17.0-arm64-darwin)
ffi (1.17.0-x86_64-darwin)
ffi (1.17.0-x86_64-linux-gnu)
Expand Down Expand Up @@ -74,6 +81,9 @@ GEM
safe_yaml (~> 1.0)
terminal-table (>= 1.8, < 4.0)
webrick (~> 1.7)
jekyll-github-metadata (2.16.1)
jekyll (>= 3.4, < 5.0)
octokit (>= 4, < 7, != 4.4.0)
jekyll-include-cache (0.2.1)
jekyll (>= 3.7, < 5.0)
jekyll-sass-converter (3.0.0)
Expand All @@ -99,15 +109,21 @@ GEM
listen (3.9.0)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
logger (1.6.0)
matrix (0.4.2)
mercenary (0.4.0)
mini_mime (1.1.5)
net-http (0.4.1)
uri
nokogiri (1.16.6-arm64-darwin)
racc (~> 1.4)
nokogiri (1.16.6-x86_64-darwin)
racc (~> 1.4)
nokogiri (1.16.6-x86_64-linux)
racc (~> 1.4)
octokit (6.1.1)
faraday (>= 1, < 3)
sawyer (~> 0.9)
parallel (1.25.1)
parser (3.3.3.0)
ast (~> 2.4.1)
Expand Down Expand Up @@ -161,6 +177,8 @@ GEM
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.31.3)
parser (>= 3.3.1.0)
rubocop-capybara (2.21.0)
rubocop (~> 1.41)
rubocop-rspec (3.0.1)
rubocop (~> 1.61)
ruby-progressbar (1.13.0)
Expand All @@ -172,6 +190,9 @@ GEM
google-protobuf (>= 3.25, < 5.0)
sass-embedded (1.77.5-x86_64-linux-gnu)
google-protobuf (>= 3.25, < 5.0)
sawyer (0.9.2)
addressable (>= 2.3.5)
faraday (>= 0.17.3, < 3)
selenium-webdriver (4.21.1)
base64 (~> 0.2)
rexml (~> 3.2, >= 3.2.5)
Expand All @@ -182,6 +203,7 @@ GEM
unicode-display_width (>= 1.1.1, < 3)
thread_safe (0.3.6)
unicode-display_width (2.5.0)
uri (0.13.0)
virtus (2.0.0)
axiom-types (~> 0.1)
coercible (~> 1.0)
Expand All @@ -200,13 +222,16 @@ DEPENDENCIES
axe-core-capybara
axe-core-rspec
capybara
faraday-retry (~> 2.2)
jekyll-github-metadata (~> 2.16)
jekyll-sitemap
just-the-docs
kramdown-parser-gfm
rack-jekyll (>= 0.5.0)
rackup
rspec
rubocop
rubocop-capybara
rubocop-rspec
selenium-webdriver
webrick
Expand Down
32 changes: 26 additions & 6 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# You can create any custom variable you would like, and they will be accessible
# in the templates via {{ site.myvariable }}.

# TODO(setup): Typically the course number, "DEPT XXX"
title: Berkeley Class Site
tagline: A Jekyll template for course websites
description: A modern, highly customizable, responsive Jekyll template for course websites
Expand All @@ -25,13 +26,27 @@ baseurl: '/berkeley-class-site' # the subpath of your site, e.g. /blog
# TODO(setup): Set this to your course's domain
url: 'https://berkeley-eecs.github.io' # the base hostname & protocol for your site, e.g. http://example.com

# TODO(setup): This should be one of eecs, dsus, stats
# This controls some footer text, and later custom styling.
course_department: dsus

# The sitemap **must** be enabled. It's published as /baseurl/sitemap.xml
plugins:
- jekyll-sitemap
- jekyll-seo-tag
- jekyll-github-metadata
- jekyll-include-cache


# Course variables
# TODO(setup): Set all of these course variables
course: SAMPLE 101
course_email: COURSE_EMAIL@berkeley.edu
gradescope_course_id: 123456 # you can find this in the Gradescope URL after /courses
# This should be the page of all class archives
# 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
# If you have no archive page, comment this line out.
class_archive_path: /

# TODO(setup): Set these auxiliary links as you wish - they show up on the top right
aux_links:
Expand All @@ -41,8 +56,6 @@ aux_links:
- 'https://oh.c88c.org'
Berkeley Class Site on GitHub:
- 'https://github.com/berkeley-eecs/berkeley-class-site'
# TODO(setup): Set copyright/licensing or any other footer content
footer_content: "Copyright &copy; 2024 UC Berkeley"

# Collections for website data
collections:
Expand Down Expand Up @@ -106,20 +119,27 @@ defaults:
layout: announcement


# TODO(setup): Set all of these course variables
course_email: YOUR_COURSE@berkeley.edu
gradescope_course_id: 123456 # you can find this in the Gradescope URL after /courses

#######
# Just the Docs / Berkeley Class Site Common Config
# Options below here will likely not need to be configured..

# Theme settings
theme: just-the-docs
color_scheme: light
search_enabled: true
heading_anchors: true
permalink: pretty

## Footer Content.
# You should probably not change these, but may add to footer_content if necessary.
# Footer *must* included the accessibility text defined in footer_custom.html
footer_content: true
back_to_top: true
back_to_top_text: "Back to Top"
last_edit_timestamp: true
last_edit_time_format: '%m %d, %Y at %H:%M'


compress_html:
clippings: all
comments: all
Expand Down
22 changes: 22 additions & 0 deletions _includes/footer_custom.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!-- This file comes from Just The Docs.
This footer should be included on all EECS/DS sites.
-->

{%- if site.footer_content and site.footer_content != true -%}
<p class="text-small text-grey-dk-100 m-0">{{ site.footer_content }}</p>
{%- endif -%}

<p class="text-small text-grey-dk-100 my-1">
<a rel="nofollow noopener" href="https://dap.berkeley.edu/get-help/report-web-accessibility-issue" target="_blank" class="pr-2">Accessibility <i class="fa-solid fa-external-link" aria-hidden=true></i></a>
<a rel="nofollow noopener" href="https://ophd.berkeley.edu/policies-and-procedures/nondiscrimination-policy-statement" target="_blank" class="px-2">Nondiscrimination <i class="fa-solid fa-external-link" aria-hidden=true></i></a>
</p>

<!-- Use this to add additional content. -->
<p class="text-small text-grey-dk-100 m-0">
Copyright ©{{ "now" | date: "%Y" }}, Regents of the University of Californa and respective authors.
</p>

<p class="fs-1 text-grey-dk-100 my-1">
This site is built following the <a href="https://github.com/just-the-docs/just-the-docs" target="_bank" rel="noopener">Berkeley Class Site <i class="fa-solid fa-external-link" aria-hidden=true></i></a> template, which is generously based on the <a href="https://github.com/kevinl/just-the-class" target="_bank" rel="noopener">Just the Class <i class="fa-solid fa-external-link" aria-hidden=true></i></a>, and <a href="https://github.com/just-the-docs/just-the-docs" target="_bank" rel="noopener">Just the Docs <i class="fa-solid fa-external-link" aria-hidden=true></i></a> templates.
</p>
6 changes: 6 additions & 0 deletions _includes/head_custom.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<!-- Use this to add global CSS/JS utitlties. -->

<!-- Loading the v6 core styles and the Solid and Brands styles -->
<link href="{{ site.baseurl }}/assets/vendor/fontawesome/css/fontawesome.css" rel="stylesheet" />
<link href="{{ site.baseurl }}/assets/vendor/fontawesome/css/brands.css" rel="stylesheet" />
<link href="{{ site.baseurl }}/assets/vendor/fontawesome/css/solid.css" rel="stylesheet" />
9 changes: 9 additions & 0 deletions _includes/nav_footer_custom.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!-- This file adds links at the bottom of the sidebar on the left. -->

{% if site.class_archive_path %}
<footer class="site-footer">
<a href="{{ site.class_archive_path }}"
target="_blank" rel="noopener nofollow">View all course offerings
<i class="fa-solid fa-external-link" aria-hidden="true"></i></a>
</footer>
{% endif %}
95 changes: 95 additions & 0 deletions _plugins/config_validator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# frozen_string_literal: true

# A UC Berkeley-specific validator for Jekyll sites
# This class validates the following options:
# 1) Ensures required attributes are present in the config file.
# 2) Ensures the baseurl is a consistent format based on the semester
# 3) Uses a `course_department` config to implement some shared styling/language.
# Future config validations might make sense, like footer/a11y/etc.

# Implement additional validations by registering an entry in `KEY_VALIDATIONS`
# This is a key_name => function_name map.
# function_name should be defined in the ConfigValidator class, and is called with
# the *value* of the config.
# Note that Jekyll parses the YAML file such that the config keys are *strings* not symbols.

# A simple class for nicer error message formatting.
class ConfigValidationError < StandardError
attr_reader :errors

def initialize(errors)
super
@errors = errors
end

def message
"The config file contained validation errors:\n\t#{errors.join('\n\t')}\n\n"
end
end

module Jekyll
# Jekyll::ConfigValidator class definition (see docs at the top of file)
class ConfigValidator
SEMESTER_REGEXP = /(wi|sp|su|fa)\d\d$/
VALID_DEPTS = %w[eecs dsus stat].freeze
KEY_VALIDATIONS = {
url: :validate_clean_url,
baseurl: :validate_semester_format,
course_department: :validate_department
}.freeze

attr_accessor :config, :errors

def initialize(config)
@config = config
@errors = []
end

def validate
validate_keys!

KEY_VALIDATIONS.each do |key, validator|
send(validator, config[key.to_s]) if @config.key?(key.to_s)
end

raise ConfigValidationError, errors if errors.length.positive?

puts 'Passed Berkeley YAML Config Validations'
end

def validate_keys!
required_keys = %i[baseurl course_department]
required_keys.each do |key|
errors << "#{key} is missing from site config" unless @config.key?(key.to_s)
end
end

private

def validate_clean_url(url)
errors << '`url` should not end with a `/`' if url.end_with?('/')
errors << '`url` should contain a protocol' unless url.match?(%r{https?://})
end

def validate_semester_format(baseurl)
# This is just for consistency of URL presentation.
errors << '`baseurl` must start with a `/`.' unless baseurl.match?(%r{^/})
# skip, just for the template.
return if baseurl == '/berkeley-class-site'

return if baseurl.match?(SEMESTER_REGEXP)

errors << "`baseurl` must be a valid semester (faXX, spXX, suXX or wiXX), not #{baseurl}"
end

def validate_department(dept)
errors << "`course_department` must be one of #{VALID_DEPTS} (not '#{dept}')" unless VALID_DEPTS.include?(dept)
end
end
end

Jekyll::Hooks.register [:site], :after_init do |site|
break if ENV['JEKYLL_ENV'] == 'production'

Jekyll::ConfigValidator.new(site.config).validate
end
Loading

0 comments on commit 39231cf

Please sign in to comment.