Skip to content

Commit

Permalink
Merge pull request #5 from CollectionBuilder/retreat-additions
Browse files Browse the repository at this point in the history
Pulling in updates from CB-CSV
  • Loading branch information
dcnb authored Nov 20, 2024
2 parents 5106dd5 + fbcfd9d commit c3bf0f8
Show file tree
Hide file tree
Showing 45 changed files with 2,009 additions and 428 deletions.
15 changes: 9 additions & 6 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

source 'https://rubygems.org'

# needed for Jekyll
gem 'jekyll'
gem 'webrick', '~> 1.7'

# needed for Rake tasks
gem 'rake'
gem 'csv'
gem 'fileutils'
gem 'mini_magick'
unless Gem.win_platform?
gem 'image_optim'
gem 'image_optim_pack'
end
gem 'csv'
gem 'jekyll'
gem 'mini_magick'
gem 'rake'

gem 'webrick', '~> 1.7'
146 changes: 8 additions & 138 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
# frozen_string_literal: true

# CollectionBuilder-CSV helper tasks

require 'csv'
require 'fileutils'
require 'image_optim' unless Gem.win_platform?
require 'mini_magick'

###############################################################################
# TASK: deploy
#
# CollectionBuilder Rake Utilities
#
# See "docs/rake_tasks/" for documentation.
# See "rakelib" for individual rake tasks!
#
###############################################################################

desc 'Build site with production env'
task :deploy do
ENV['JEKYLL_ENV'] = 'production'
system('bundle', 'exec', 'jekyll', 'build')
end
require 'csv'
require 'fileutils'

###############################################################################
# Helper Functions
Expand All @@ -36,128 +31,3 @@ def prompt_user_for_confirmation(message)
end
response
end

def process_and_optimize_image(filename, file_type, output_filename, size, density)
image_optim = ImageOptim.new(svgo: false) unless Gem.win_platform?
if filename == output_filename && file_type == :image && !Gem.win_platform?
puts "Optimizing: #{filename}"
begin
image_optim.optimize_image!(output_filename)
rescue StandardError => e
puts "Error optimizing #{filename}: #{e.message}"
end
elsif filename == output_filename && file_type == :pdf
puts "Skipping: #{filename}"
else
puts "Creating: #{output_filename}"
begin
if file_type == :pdf
inputfile = "#{filename}[0]"
magick = MiniMagick::Tool::Convert.new
magick.density(density)
magick << inputfile
magick.resize(size)
magick.flatten
magick << output_filename
magick.call
else
image = MiniMagick::Image.open(filename)
image.format('jpg')
image.resize(size)
image.flatten
image.write(output_filename)
end
image_optim.optimize_image!(output_filename) unless Gem.win_platform?
rescue StandardError => e
puts "Error creating #{filename}: #{e.message}"
end
end
end

###############################################################################
# TASK: generate_derivatives
###############################################################################

desc 'Generate derivative image files from collection objects'
task :generate_derivatives, [:thumbs_size, :small_size, :density, :missing, :compress_originals] do |_t, args|
# set default arguments
# default image size is based on max pixel width they will appear in the base template features
args.with_defaults(
thumbs_size: '450x',
small_size: '800x800',
density: '300',
missing: 'true',
compress_originals: 'false'
)

# set the folder locations
objects_dir = 'objects'
thumb_image_dir = 'objects/thumbs'
small_image_dir = 'objects/small'

# Ensure that the output directories exist.
[thumb_image_dir, small_image_dir].each do |dir|
FileUtils.mkdir_p(dir) unless Dir.exist?(dir)
end

# support these file types
EXTNAME_TYPE_MAP = {
'.jpeg' => :image,
'.jpg' => :image,
'.pdf' => :pdf,
'.png' => :image,
'.tif' => :image,
'.tiff' => :image
}.freeze

# CSV output
list_name = File.join(objects_dir, 'object_list.csv')
field_names = 'filename,object_location,image_small,image_thumb'.split(',')
CSV.open(list_name, 'w') do |csv|
csv << field_names

# Iterate over all files in the objects directory.
Dir.glob(File.join(objects_dir, '*')).each do |filename|
# Skip subdirectories and the README.md file.
if File.directory?(filename) || File.basename(filename) == 'README.md' || File.basename(filename) == 'object_list.csv'
next
end

# Determine the file type and skip if unsupported.
extname = File.extname(filename).downcase
file_type = EXTNAME_TYPE_MAP[extname]
unless file_type
puts "Skipping file with unsupported extension: #{filename}"
csv << ["#{File.basename(filename)}", "/#{filename}", nil, nil]
next
end

# Get the lowercase filename without any leading path and extension.
base_filename = File.basename(filename, '.*').downcase

# Optimize the original image.
if args.compress_originals == 'true'
puts "Optimizing: #{filename}"
process_and_optimize_image(filename, file_type, filename, nil, nil)
end

# Generate the thumb image.
thumb_filename = File.join(thumb_image_dir, "#{base_filename}_th.jpg")
if args.missing == 'false' || !File.exist?(thumb_filename)
process_and_optimize_image(filename, file_type, thumb_filename, args.thumbs_size, args.density)
else
puts "Skipping: #{thumb_filename} already exists"
end

# Generate the small image.
small_filename = File.join([small_image_dir, "#{base_filename}_sm.jpg"])
if (args.missing == 'false') || !File.exist?(small_filename)
process_and_optimize_image(filename, file_type, small_filename, args.small_size, args.density)
else
puts "Skipping: #{small_filename} already exists"
end
csv << ["#{File.basename(filename)}", "/#{filename}", "/#{small_filename}", "/#{thumb_filename}"]
end
end
puts "\e[32mSee '#{list_name}' for list of objects and derivatives created.\e[0m"
end
4 changes: 2 additions & 2 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ tagline: Prototype for working with Oral History as Data items in CollectionBuil
# this description might appear in search result lists, keep around 160 characters max
description: "CB-OHD is a mix of CollectionBuilder-CSV and Oral History as Data (OHD)."
# if you want a different description to appear in the footer only, define it here, or leave blank to use description
footer_description: "cb-oralhistory rocks!"
# footer_description: "cb-oralhistory rocks!"
# keywords, a short list of subjects describing the collection, separated by semicolon, to appear in rich markup
keywords: oral histories;digital collections
# creator of the digital collection, to appear in meta tags; we typically use our GitHub usernames but feel free to just use your name
Expand Down Expand Up @@ -80,7 +80,7 @@ organization-logo-nav: https://cdil.lib.uidaho.edu/assets/img/logo.png
# (this is done automatically by gh-pages build)
#
# ignore stuff
exclude: [docs/, Rakefile, README.md, LICENSE, CITATION.cff, CODE_OF_CONDUCT.md, CONTRIBUTING.md, SECURITY.md]
exclude: [docs/, Rakefile, rakelib/, README.md, LICENSE, CITATION.cff, CODE_OF_CONDUCT.md, CONTRIBUTING.md, SECURITY.md]
# compress CSS output
sass:
style: compressed
Expand Down
2 changes: 1 addition & 1 deletion _data/demo-compoundobjects-metadata.csv
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ demo_014,demo_013,Peeled Tree View 1,,,,,,,,,,,Image;StillImage,image/jpeg,,,,im
demo_015,demo_013,Peeled Tree View 2,,,,,,,,,,,Image;StillImage,image/jpeg,,,,image,https://webpages.uidaho.edu/Library/twrs/objects/DSC_0137.JPG,https://webpages.uidaho.edu/Library/twrs/objects/small/dsc_0137_sm.jpg,https://webpages.uidaho.edu/Library/twrs/objects/thumbs/dsc_0137_th.jpg,log cross section showing where tree bark was peeled,
demo_016,demo_013,Peeled Tree View 3,,,,,,,,,,,Image;StillImage,image/jpeg,,,,image,https://webpages.uidaho.edu/Library/twrs/objects/DSC_0138.JPG,https://webpages.uidaho.edu/Library/twrs/objects/small/dsc_0138_sm.jpg,https://webpages.uidaho.edu/Library/twrs/objects/thumbs/dsc_0138_th.jpg,log cross section showing where tree bark was peeled,
demo_017,,Hell's Half Acre Lookout 360 Image,Keeping Watch,2021-07-13,,Example panorama. 360 Image of the Interior of Hell's Half Acre Fire Tower,,Hell's Half Acre,45.64579,-114.62838,,,Image;StillImage,image/jpeg,eng,,,panorama,/objects/hells_half_theta.jpg,https://cdil.lib.uidaho.edu/keeping-watch/objects/small/hells_half_theta_sm.jpg,https://cdil.lib.uidaho.edu/keeping-watch/objects/thumbs/hells_half_theta_th.jpg,interior of a fire lookout tower with map in center and windows in all directions,
demo_018,,"Spokane's Great Restaurant, Washington","Mitchell, Edward H.",1909,,"Example postcard using display template 'multiple.' Postcard is of the Davenport Hotel's Restaurant in Spokane, Washington.",restaurants; automobiles; buildings; picture postcards; flagpoles; flags,"Spokane, WA",47.65710758,-117.4249084,"PG 9, Postcard Collection, University of Idaho Library Special Collections and Archives, http://www.lib.uidaho.edu/special-collections/",Postcard_038,record,postcard,eng,"Educational use includes non-commercial use of text and images in materials for teaching and research purposes. Digital reproduction rights granted by University of Idaho Library. For other uses beyond educational use, please contact University of Idaho Library Special Collections and Archives Department at [email protected].",http://rightsstatements.org/vocab/InC-EDU/1.0/,multiple,,/objects/small/210a_sm.jpg,/objects/thumbs/210a_th.jpg,historic colorized postcard depicting a fancy multi-story white building with several early cars parked in front,
demo_018,,"Spokane's Great Restaurant, Washington","Mitchell, Edward H.",1909,,"Example postcard using display template 'multiple.' Postcard is of the Davenport Hotel's Restaurant in Spokane, Washington.",restaurants; automobiles; buildings; picture postcards; flagpoles; flags,"Spokane, WA",47.65710758,-117.4249084,"PG 9, Postcard Collection, University of Idaho Library Special Collections and Archives, http://www.lib.uidaho.edu/special-collections/",Postcard_038,record,multiple,eng,"Educational use includes non-commercial use of text and images in materials for teaching and research purposes. Digital reproduction rights granted by University of Idaho Library. For other uses beyond educational use, please contact University of Idaho Library Special Collections and Archives Department at [email protected].",http://rightsstatements.org/vocab/InC-EDU/1.0/,multiple,,/objects/small/210a_sm.jpg,/objects/thumbs/210a_th.jpg,historic colorized postcard depicting a fancy multi-story white building with several early cars parked in front,
demo_019,demo_018,postcard front,,,,,,,,,,210a,Image;StillImage,image/jpeg,,,,image,/objects/210a.jpg,/objects/small/210a_sm.jpg,/objects/thumbs/210a_th.jpg,historic colorized postcard depicting a fancy multi-story white building with several early cars parked in front,
demo_020,demo_018,postcard back,,,,,,,,,,210b,Image;StillImage,image/jpeg,,,,image,/objects/210b.jpg,/objects/small/210b_sm.jpg,/objects/thumbs/210b_th.jpg,"back of historic postcard dated Sept 5, 1909 with very difficult to read cursive writing in pencil",
demo_021,,"Jennie Eva Hughes, the First Black Graduate of the University of Idaho",,1899,yes,"Example compound object. Items from the Black History at University of Idaho that feature Jennie Eva Hughes, the first black graduate of the University of Idaho",Jennie Eva Hughes; Black History; University of Idaho,"Moscow, ID",46.725562,-117.009633,<a href='https://www.lib.uidaho.edu/blackhistory/' target='_blank'>Black History at the University of Idaho Digital Collection</a>,,record,compound_object,eng,,,compound_object,,https://www.lib.uidaho.edu/blackhistory/objects/small/ma2000_29_001_sm.jpg,https://www.lib.uidaho.edu/blackhistory/objects/thumbs/ma2000_29_001_th.jpg,"University of Idaho enrollment form filled in with handwritten cursive script saying ""Jennie Eva Hughes, Sept 23, 1898""",
Expand Down
1 change: 0 additions & 1 deletion _data/theme.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ metadata-facets-fields: "subject,interviewer,format"
map-child-objects: true # true / false - if true, and if child item has latitude and longitude, child objects will be displayed on map
timeline-child-objects: true # true / false - if true, and if child object has date, child objects will appear as thumbnails on timeline page
data-child-objects: false # true / false - if true, child objects will appear linked in table on data page
carousel-child-objects: false # true / false - if true, child objects will appear on homepage carousel
browse-child-objects: false # true / false - if true, child objects will appear on browse page and child objects' metadata will populate cloud pages like Subjects page and Locations page, as well as featured terms boxes on the home page
search-child-objects: true # true / false - if true, child objects will appear on on search page along with parent objects

Expand Down
2 changes: 1 addition & 1 deletion _includes/collection-nav.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<div class="collapse navbar-collapse" id="page-nav">
<ul class="navbar-nav me-auto">
{%- assign navItems = site.data.config-nav | where_exp: 'item', 'item.dropdown_parent == nil' -%}
{%- assign navItems = site.data.config-nav | where_exp: 'item', 'item.display_name and item.dropdown_parent == nil' -%}
{% for nav in navItems %}
{% if nav.stub %}
<li class="nav-item">
Expand Down
73 changes: 73 additions & 0 deletions _includes/feature/gallery.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{% comment %}
Gallery, grid of images to be used as it's own page or within an about page.

E.G. --> (3 examples below)

{% include feature/gallery.html image-heading="demo_008" heading="Items after 1900" captions=false filter="item.date > '1900'" %}

{% include feature/gallery.html heading="All the Videos" child-objects=true gallery-type="video" %}

{% include feature/gallery.html image-heading="demo_018" heading="Items that have the subject postcard and are in Spokane" context="This uses a complex liquid filter to specify specif items." filter="item.subject contains 'postcard' and item.location contains 'Spokane'" %}

*Note that filters are CASE-SENSITIVE so if you're constructing one, either using the filter itself or the filter-field and filter-value you will need to match the case of the string search. this is unlike our browse page.*

Options:
- "filter" = logic statement (in the templating language liquid -- non liquid option indented below) that filters out most of the collection to display only select items. The first part of the statement must start with an "item." and then the category you'd like filtered, followed by an operator (https://shopify.github.io/liquid/basics/operators/) and the string or value you'd like to filter by e.g. "item.date contains '2019'".
If needed you can use the below options to construct a filter statement
- "filter-field" = the metadata field by which you'd like to filter items in your collection. i.e. title, subject, date, etc.
- "filter-value" = logic statement (in liquid) that filters out most of the collection to display only select items.
- "heading" = the heading text above the gallery (optional)
- "image-heading" = one objectid for a photo object in this collection, a relative path to an image in this project, or a full url to any image. This will include a feature/jumbotron.html includes at the top of the gallery
- "context" = a paragraph explanation of the gallery contents (optional)
- "caption" = If you don't want captions for your items, add --> captions=false with no quotations. Captions are on by default
- "item-size" = tiny, small, medium, large; default is medium, which is 3 items per row on a laptop screen size.
- "gallery-type" = this will determine how the items appear, so choosing 'video' will cause the gallery to display all items as embedded videos options: image, video, pdf, audio. Default is "image" (optional)
- container-styles = adds css classes to allow you to style the container in which the gallery appears, e.g. "w-75 mx-auto"
- item-styles = adds css classes to allow you to style the container in which the individual items appears, e.g. "card py-3"
- "image-size" - will adjust the size of the images used in the gallery, options: original, small, thumb. Default is "small" (optional)
- "child-objects" = include child items in count or only parents, true or false (optional, default false)
- "limit" will limit the number of items featured to the number included, default 50 (optional)

{%- endcomment -%}

{% if include.child-objects == true %}
{%- assign gallery-items = site.data[site.metadata] | where_exp: 'item','item.objectid' -%}
{% else %}
{%- assign gallery-items = site.data[site.metadata] | where_exp: 'item','item.objectid and item.parentid == nil' -%}
{% endif %}
{% if include.gallery-type %}
{%- assign gallery-items = gallery-items | where_exp: "item","item.display_template == include.gallery-type" -%}
{% else %}
{%- assign gallery-items = gallery-items | where_exp: "item","item.image_small != nil or item.image_thumb != nil" -%}
{% endif %}
{%- if include.filter-field and include.filter-value -%}
{%- assign gallery-items = gallery-items | where_exp: 'item','item[include.filter-field] contains include.filter-value' -%}
{%- elsif include.filter -%}
{%- assign gallery-items = gallery-items | where_exp: 'item',include.filter -%}
{% endif %}
{% assign gallery-limit = include.limit | default: 50 %}
{% capture captions %}{{ include.captions | default: "true" }}{% endcapture %}


{% if include.image-heading and include.heading%}
{% include feature/jumbotron.html objectid=include.image-heading heading=include.heading text=false padding="5rem" %}
{% elsif include.image-heading %}
{% include feature/jumbotron.html objectid=include.image-heading %}
{% elsif include.heading %}
<h2>{{ include.heading }}</h2>{% endif %}
<div class="row my-3 py-3 {{ include.container-styles }}">
{% if include.context %}<p> {{include.context}} </p>{% endif %}
{% for item in gallery-items limit:gallery-limit %}
<div class="{% if include.item-size == 'tiny' %}col-lg-2 col-sm-4 col-xs-6{% elsif include.item-size == 'small' %}col-lg-3 col-sm-6{% elsif include.item-size == 'large' %}col-xl-4 col-lg-6{% else %}col-lg-4 col-sm-6{% endif %} {{ include.item-styles }}">
{% if include.gallery-type == "video" %}
{% include feature/video.html objectid=item.objectid caption=include.captions %}
{% elsif include.gallery-type == "pdf" %}
{% include feature/pdf.html objectid=item.objectid caption=include.captions %}
{% elsif include.gallery-type == "audio" %}
{% include feature/audio.html objectid=item.objectid caption=include.captions %}
{% else %}
{% include feature/image.html objectid=item.objectid caption=include.captions %}{% endif %}
</div>
{% endfor %}
</div>

1 change: 1 addition & 0 deletions _includes/head/page-meta.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<meta name="description" content="{{ site.description | escape }}">
{% if site.author or site.organization-name %}<meta name="author" content="{% if site.author %}{{ site.author | escape }}; {% endif %}{{ site.organization-name | escape }}" >{% endif %}
{% if site.keywords %}<meta name="keywords" content="{{ site.keywords | escape }}">{% endif %}
<!-- DC meta -->
<link rel="schema.DCTERMS" href="http://purl.org/dc/terms/" />
<meta name="DCTERMS.title" content="{{ page.title | escape }}, {{ site.title | escape }}" xml:lang="en" />
Expand Down
Loading

0 comments on commit c3bf0f8

Please sign in to comment.