Repository navigation
ARC-184 - migrate PDF building #107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
747db75
89d2bc8
35103d7
f447594
ba5c9ea
2cfc64e
982114c
8d21660
8820464
820c7e6
1a27755
c23dfc2
779c761
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 |
| 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; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
||
|
|
@@ -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? | ||
|
|
@@ -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) | ||
|
|
@@ -197,7 +218,7 @@ def get(url) | |
|
|
||
| def fetch_doc(id) | ||
| params = { | ||
| fl: "*", # COMPONENT_FIELDS.join(','), | ||
| fl: "*", | ||
| q: [ "id:#{id}" ], | ||
| start: 0, | ||
| rows: 1 | ||
|
|
@@ -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 | ||
|
|
@@ -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"] = "" | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was there a class that needed to be removed?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OTOB there are |
||
|
|
||
| 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 | ||
|
|
@@ -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| | ||
|
|
@@ -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 | ||
|
|
@@ -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 | ||
|
|
||
|
|
@@ -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 | ||
|
|
||
|
|
@@ -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 | ||
|
|
@@ -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 { | ||
|
|
||
There was a problem hiding this comment.
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?