From b7bf538314181a0ac9df396d90a8f5bc4cadac89 Mon Sep 17 00:00:00 2001
From: claudiawulee <68723604+claudiawulee@users.noreply.github.com>
Date: Wed, 23 Oct 2024 09:58:27 -0400
Subject: [PATCH] Adding Schema.org tags for better discovery (#688)
---
app/helpers/schema_org_helper.rb | 43 +++++++++++++
app/views/layouts/blacklight/base.html.erb | 1 +
app/views/shared/_schema_org.html.erb | 28 ++++++++
spec/helpers/schema_org_helper_spec.rb | 67 ++++++++++++++++++++
spec/system/search_pdc_results_page_spec.rb | 5 ++
spec/system/show_pdc_describe_record_spec.rb | 5 ++
6 files changed, 149 insertions(+)
create mode 100644 app/helpers/schema_org_helper.rb
create mode 100644 app/views/shared/_schema_org.html.erb
create mode 100644 spec/helpers/schema_org_helper_spec.rb
diff --git a/app/helpers/schema_org_helper.rb b/app/helpers/schema_org_helper.rb
new file mode 100644
index 00000000..63798e2c
--- /dev/null
+++ b/app/helpers/schema_org_helper.rb
@@ -0,0 +1,43 @@
+# frozen_string_literal: true
+
+# rubocop:disable Rails/OutputSafety
+module SchemaOrgHelper
+ def keywords_helper(subjects)
+ keywords_json = subjects.map do |subject|
+ '"' + html_escape(subject) + '"'
+ end
+
+ html = "[" + keywords_json.join(",") + "]"
+ html.html_safe
+ end
+
+ def authors_helper(authors)
+ authors_json = authors.each.map do |author|
+ json_str = "\n\t\t\t{\n\t\t\t" + '"name": ' + '"' + author.value + '"'
+ if author.affiliation_name.present?
+ json_str += ",\n\t\t\t" + '"affiliation": ' + '"' + author.affiliation_name + '"'
+ end
+ if author.orcid.present?
+ json_str += ",\n\t\t\t" + '"identifier": ' + '"' + author.orcid + '"'
+ end
+ json_str += "\n\t\t\t}"
+ json_str
+ end
+ html = "[" + authors_json.join(",") + "]"
+ html.html_safe
+ end
+
+ def license_helper(licenses)
+ if licenses.count == 0
+ ""
+ else
+ html = '"license": {'
+ html += "\n\t\t\t" + '"@type": ' + '"Dataset"' + ",\n" \
+ "\t\t\t" + '"text": ' + '"' + licenses[0]['identifier'] + '"' + ",\n" \
+ "\t\t\t" + '"url": ' + '"' + licenses[0]['uri'] + '"'
+ html += "\n\t\t\t},"
+ html.html_safe
+ end
+ end
+end
+# rubocop:enable Rails/OutputSafety
diff --git a/app/views/layouts/blacklight/base.html.erb b/app/views/layouts/blacklight/base.html.erb
index 87c28bb8..a8ca5bce 100644
--- a/app/views/layouts/blacklight/base.html.erb
+++ b/app/views/layouts/blacklight/base.html.erb
@@ -33,6 +33,7 @@
More info: https://getbootstrap.com/docs/4.6/components/popovers/
-->
+ <%= render partial: 'shared/schema_org'%>