Skip to content
Merged
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
1 change: 1 addition & 0 deletions app/assets/config/manifest.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//= link_tree ../images
//= link bootstrap.css
//= link application.css
//= link print.css
//= link_tree ../../javascript .js
//= link blacklight-range-limit/index.js
//= link blacklight/manifest.js
143 changes: 143 additions & 0 deletions app/assets/stylesheets/print.scss

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noticed the generated PDF has a duplicated title on each item, plus a checkbox at the beginning. I don't think we need the checkbox in the PDF — something related to the new print.scss?

Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
html,
body {
font-family: "Mulish", Calibri, Candara, Arial, sans-serif;
font-size: 16px;
}

#sidebar,
.skip-link,
.element-invisible,
.sr-only,
.visually-hidden {
display: none;
}

h1 {
font-family: "Crimson Text",serif;
font-size: 48px;
}

header {
background: #00274C;
color: #F7F8F9;
position: static;
display: block;
}

header>div.website-header-container {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: horizontal;
-webkit-box-direction: normal;
-ms-flex-direction: row;
flex-direction: row;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
gap: 0.5rem;
padding: 1rem;
font-size: 1.5rem;
}

header>div.website-header-container a {
color: white;
text-decoration: none;
text-transform: uppercase;
letter-spacing: 0.5px;
line-height: 1.1;
}

header>div.repository a {
color: #06080A;
text-decoration: none;
}

.card {
position: relative;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-ms-flex-direction: column;
flex-direction: column;
min-width: 0;
word-wrap: break-word;
background-color: #fff;
background-clip: border-box;
}

.card-horizontal {
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-ms-flex-direction: column;
flex-direction: column;
}

.card-body {
padding: 1.25rem;
}

.card-footer {
padding: 1.25rem;
background-color: rgba(0, 0, 0, 0.03);
border-left: 1px solid rgba(0, 0, 0, 0.125);
border-top: unset;
line-height: 1.2;
}

.checkbox.request-checkbox {
display: none;
}

.component-wrapper h3 {
display: table !important;
width: 100%;
}

.component-title {
display: table !important;
width: 100%;

span.title {
display: table-cell;
width: 70%;
}

span.box {
display: table-cell;
text-align: right;
}
}

.d-flex {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: horizontal;
-webkit-box-direction: normal;
-ms-flex-direction: row;
flex-direction: row;
-webkit-box-pack: start;
-ms-flex-pack: start;
justify-content: flex-start;
}

.flex-grow-1 {
flex-grow: 1;
}

.collection-banner {
i.fas {
display: none;
}
}

#sidebar {
display: none;
}

.modal {
display: none;
}
3 changes: 2 additions & 1 deletion app/controllers/concerns/um_arclight/catalog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ def html_download
self.response_body = Enumerator.new do |output|
File.foreach(html_filename) do |line|
if line.index('<style id="placeholder"></style>')
output << helpers.stylesheet_link_tag("bootstrap", media: "all")
output << helpers.stylesheet_link_tag("application", media: "all")
output << helpers.javascript_include_tag("application")
output << helpers.javascript_importmap_tags
output << helpers.csrf_meta_tags
next
end
Expand Down
9 changes: 9 additions & 0 deletions app/models/solr_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ def is_linkable?
online_content? || number_of_children > 0 || restricted_component?
end

# This count includes all descendant components' DAOs
def total_digital_object_count
first("total_digital_object_count_isim") || 0
end

def has_digital_objects?
total_digital_object_count.positive?
end

def collection_has_requestable_components?
repository_config.request_config_present_for_type?("aeon_hidden_form_request")
end
Expand Down
91 changes: 74 additions & 17 deletions app/services/package/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,13 @@ def build_pdf_html

def generate_pdf_html
build_pdf_html
local_html_filename = generate_local_html_filename # "#{collection.document_id}.local.html"
local_html_filename = generate_local_html_filename
File.open(local_html_filename, "w") do |f|
f.puts doc.serialize
local_html = doc.serialize
if RUBY_PLATFORM.match?(/darwin/i)
local_html.gsub!(finding_aid_data_path, "/opt/app-data")
end
f.puts local_html
end
end

Expand Down Expand Up @@ -142,6 +146,22 @@ def generate_pdf
local_html_filename,
output_filename
]

# Check if the host OS is macOS (Darwin)
if RUBY_PLATFORM.match?(/darwin/i)
cmd.unshift(
"docker",
"compose",
"run",
"-e", "FINDING_AID_DATA=/opt/app-data",
"--rm",
"--no-deps",
"app"
)
cmd[-2].gsub!(finding_aid_data_path, "/opt/app-data")
cmd[-1].gsub!(finding_aid_data_path, "/opt/app-data")
end

stdout_and_stderr, process_status = Open3.capture2e(*cmd)

if process_status.success?
Expand Down Expand Up @@ -173,6 +193,7 @@ def working_path_name
def finding_aid_data_path
ENV.fetch("FINDING_AID_DATA", Rails.root.join("data").to_s)
end

# TODO: this is a hack to get the repository_id from the collection.
def collection_repository_id
return collection.repository_id if collection.respond_to?(:repository_id)
Expand All @@ -197,7 +218,7 @@ def get(url)

def fetch_doc(id)
params = {
fl: "*", # COMPONENT_FIELDS.join(','),
fl: "*",
q: [ "id:#{id}" ],
start: 0,
rows: 1
Expand Down Expand Up @@ -293,7 +314,7 @@ def render_fragment(variables)
end

def update_navigation_links
doc.css("#about-collection-nav a").each do |link|
doc.css(".al-sidebar-navigation-context a").each do |link|
href = link["href"]
link["href"] = "#" + href.split("#").last
end
Expand All @@ -308,25 +329,37 @@ def update_package_html
asset_links.first.add_previous_sibling '<style id="placeholder"></style>'

asset_links.each do |el|
# @chunks << el
el.unlink
end

# @chunks << doc.xpath('/html/head/script[starts-with(@src, "/assets")]')
doc.xpath('/html/head/script[starts-with(@src, "/assets")]').each do |el|
el.unlink
end

doc.xpath('/html/head/script[starts-with(@type, "importmap")]').each do |el|
el.unlink
end

doc.xpath('/html/head/link[@rel="modulepreload"]').each do |el|
el.unlink
end

doc.xpath('/html/head/script[@type="module"]').each do |el|
el.unlink
end

doc.css('meta[name="csrf-param"]').first&.unlink
doc.css('meta[name="csrf-token"]').first&.unlink

doc.css("#summary dl").first << fragment.css("dl#ead_author_block dt,dl#ead_author_block dd")
if (contents_el = doc.css("div.al-contents").first)
doc.css("html").first["class"] = ""

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was there a class that needed to be removed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OTOB there are no-js classes until javascript loads. Do the updated styles use this for anything? Undocumented, and early PDFs were turning out blank.


if (contents_el = doc.css("div#contents > turbo-frame").first)
contents_el.replace(fragment.css("div.al-contents-ish").first)
end
doc.css(".card-img").first&.remove
doc.css(".title-container button").first&.remove
doc.css("#navigate-collection-toggle").first&.remove
if (tree_el = doc.css("#context-tree-nav .tab-pane.active").first)
if (tree_el = doc.css("#toc").first)
tree_el.inner_html = ""
tree_el << fragment.css("#toc").first
end
Expand All @@ -337,6 +370,7 @@ def update_package_html_pdf
if (header_el = doc.css("m-website-header").first) && (new_header = fragment.css("header").first)
header_el.replace(new_header)
end
doc.css(".al-show-actions-toolbar")&.first&.remove
doc.css("footer").first&.remove
doc.css("div.x-printable").remove
doc.css("body a[href]").each do |link|
Expand All @@ -348,6 +382,7 @@ def update_package_html_pdf
link["href"] = CGI.unescape(link["href"])
end
end
doc.css("aside")&.first.unlink
# ARC-114 Chinese characters were missing (Hack to include font as fallback font)
doc.css("body").first << '<div style="font-family: UnifontExMono; visibility: hidden; font-size: 1px;">x</div>'
end
Expand All @@ -360,15 +395,32 @@ def build_package_html_toc
snippet_el.inner_html = '<div id="toc"><ul class="list-unbulleted"></ul></ul>'
current_ul = doc.css("#toc ul").first
contents_li = nil
doc.css("#about-collection-nav li.nav-item").each do |li|
doc.css("aside nav.al-sidebar-navigation-context li").each do |li|
current_ul << li
contents_li = li if li.css("a").first["href"] == "#contents"
contents_li = li if li.css("a").first["href"].index("#contents")
end
return unless contents_li
if (frame_el = doc.css("#collection-context turbo-frame").first)
response = get(frame_el["src"])
frame_doc = Nokogiri::HTML5(response.body)

if (contents_ul = doc.css("#sidebar #toc > ul").first)
contents_ul["class"] = "list-unbulleted"
contents_li << contents_ul
if (contents_ul = frame_doc.css("ul.documents").first)
contents_ul.css(".al-toggle-view-children").each do |el|
el.remove
end
contents_ul.css(".collapse").each do |el|
el.remove
end
contents_ul.css(".al-online-content-icon").each do |el|
el.remove
end
contents_ul.css("a").each do |link|
href = link["href"]
link["href"] = "#" + href.split("/").last
end

contents_ul["class"] = "list-unbulleted"
contents_li << contents_ul
end
end
end

Expand All @@ -377,6 +429,9 @@ def update_package_styles_pdf
placeholder_el = doc.css("style#placeholder").first

doc.css('link[rel="stylesheet"][href^="https://"]').each do |link|
if link["href"].index("umich-lib")
next
end
link.unlink
end

Expand All @@ -389,14 +444,13 @@ def update_package_styles_pdf
# still works in test and environments that don't ship a print stylesheet.
begin
placeholder_el.add_next_sibling CatalogController.helpers.stylesheet_link_tag("print")
rescue Propshaft::MissingAssetError
rescue Propshaft::MissingAssetError => e
# print.css is optional in test and some packaging environments
end

# cache the assets locally
doc.xpath("/html/head/link").each do |link|
next unless link["rel"] == "stylesheet"
# next unless link['href'].start_with?('/assets/', 'https://')
filename = if link["href"].start_with?("/assets/")
link["href"].split(/[\?#]/).first.gsub("/assets", "")
else
Expand All @@ -419,6 +473,9 @@ def update_package_styles_pdf
# volume) and referenced by absolute path so PDF generation never depends on the
# data volume being seeded. wkhtmltopdf reads it via --enable-local-file-access.
unifont_path = Rails.root.join("public", "fonts", "UnifontExMono.woff")
if RUBY_PLATFORM.match?(/darwin/i)
unifont_path = unifont_path.to_s.gsub(Rails.root.to_s, "/rails")
end
placeholder_el.add_next_sibling <<~STYLE
<style>
@font-face {
Expand Down
Loading