-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a department filter to the home page, various design improvements…
…, helps with #7
- Loading branch information
1 parent
d6b3bd4
commit 6960ebe
Showing
4 changed files
with
126 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,9 +20,10 @@ def generate(site) | |
new_records = records_from_evergreen site.config | ||
site.data['books'] = new_records | ||
generate_montage site.data['books'], site.config['plugins_dir'] | ||
site.config['departments'] | ||
.map { |department| Department.new department, site.config } | ||
.each { |department| department.email_about site.data['books'] } | ||
site.data['departments'] = site.config['departments'] | ||
.map { |department| Department.new department, site.config, site.data['books'] } | ||
.select(&:enough_books?) | ||
site.data['departments'].each(&:send_email) | ||
end | ||
|
||
private | ||
|
@@ -77,7 +78,7 @@ def send_instagram_email(books, dir) | |
|
||
# A new book | ||
class Book | ||
attr_reader :call_number, :cover_image, :title | ||
attr_reader :call_number, :cover_image, :id, :title | ||
|
||
def initialize(entry) | ||
@author = entry.at_xpath('./atom:author', 'atom' => ATOM_NAMESPACE) | ||
|
@@ -90,6 +91,7 @@ def initialize(entry) | |
|
||
@uri = catalog_url_for entry.at_xpath('./atom:id', 'atom' => ATOM_NAMESPACE).text[/\d+/] | ||
@title = entry.at_xpath('./atom:title', 'atom' => ATOM_NAMESPACE).text | ||
@id = entry.at_xpath('./atom:id', 'atom' => ATOM_NAMESPACE).text.gsub(':', '-') | ||
|
||
@date_cataloged = entry.at_xpath('./atom:updated', 'atom' => ATOM_NAMESPACE) | ||
@date_cataloged = @date_cataloged if @date_cataloged | ||
|
@@ -107,6 +109,7 @@ def to_liquid | |
{ | ||
'author' => @author, | ||
'call_number' => @call_number, | ||
'id' => @id, | ||
'uri' => @uri, | ||
'title' => @title, | ||
'date_cataloged' => @date_cataloged, | ||
|
@@ -148,35 +151,38 @@ def normalize_isbn(isbn) | |
|
||
# An LBCC department | ||
class Department | ||
def initialize(department_config, site_config) | ||
def initialize(department_config, site_config, books) | ||
@name = department_config['name'] | ||
@emails = department_config['emails'] | ||
@regex = department_config['regex'] | ||
@site_config = site_config | ||
end | ||
|
||
def email_about(books) | ||
@books_of_interest = books.select { |book| interested_in? book } | ||
send_email if enough_books? | ||
end | ||
|
||
private | ||
def send_email | ||
mail = Mail.new "To: #{@emails.join(', ')}\r\n"\ | ||
"From: [email protected]\r\n"\ | ||
'Subject: New books at the LBCC Library' | ||
mail.text_part = text_contents | ||
mail.html_part = html_contents | ||
mail.deliver! | ||
end | ||
|
||
def interested_in?(book) | ||
book.call_number.match? @regex | ||
def to_liquid | ||
{ | ||
'name' => @name, | ||
'book_ids' => @books_of_interest.map(&:id) | ||
} | ||
end | ||
|
||
def enough_books? | ||
@books_of_interest.count >= @site_config['min_items_per_email'] | ||
end | ||
|
||
def send_email | ||
mail = Mail.new "To: #{@emails.join(', ')}\r\n"\ | ||
"From: [email protected]\r\n"\ | ||
'Subject: New books at the LBCC Library' | ||
mail.text_part = text_contents | ||
mail.html_part = html_contents | ||
mail.deliver! | ||
private | ||
|
||
def interested_in?(book) | ||
book.call_number.match? @regex | ||
end | ||
|
||
def text_contents | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,62 @@ | ||
--- | ||
--- | ||
|
||
@import "{{ site.theme }}"; | ||
$content-width: 90%; | ||
|
||
.grid { /* Masonry container */ | ||
column-count: 4; | ||
column-gap: 1em; | ||
@import "minima"; | ||
|
||
a, a:visited { | ||
color: #005B94; | ||
} | ||
|
||
.post-content h2 { | ||
font-size: 1.4em; | ||
text-align: center; | ||
} | ||
|
||
.grid { | ||
display: flex; | ||
flex-wrap: wrap; | ||
} | ||
|
||
.grid-item { | ||
margin: 12px auto; | ||
} | ||
|
||
.grid-item img { | ||
width: 100%; | ||
} | ||
|
||
.hidden { | ||
display: none; | ||
} | ||
|
||
#filter { | ||
border: none; | ||
border-bottom: 2px solid #FDB913; | ||
color: #005B94; | ||
font-size: 2em; | ||
} | ||
|
||
|
||
@media (max-width: 767px) { | ||
.only-medium-and-larger { | ||
display: none; | ||
} | ||
.grid-item { | ||
width: 30%; | ||
} | ||
} | ||
|
||
@media (min-width: 768px) { | ||
.grid-item { | ||
width: 21%; | ||
} | ||
|
||
} | ||
|
||
@media only screen { | ||
.post-title { | ||
display: none; | ||
} | ||
|
||
.grid-item { /* Masonry bricks or child elements */ | ||
background-color: #eee; | ||
display: inline-block; | ||
margin: 0 0 1em; | ||
width: 100%; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters