Skip to content

Commit

Permalink
Merge pull request #222 from nyudlts/meta-tag
Browse files Browse the repository at this point in the history
Add changes for meta-tag updates
  • Loading branch information
ekate authored Dec 19, 2024
2 parents 9ec5946 + 268ebdf commit f2fe388
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: ci:test
on:
push:
branches:
- add-meta-tags
- meta-tag
paths-ignore:
- "docs/**"
- "**.md"
Expand Down
11 changes: 10 additions & 1 deletion templates/semantic-ui/invenio_app_rdm/records/details/meta.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,23 @@

{%- from "invenio_formatter/macros/meta.html" import meta_twittercard, meta_opengraph, meta_highwire -%}


{%- set meta_title = record.metadata.title|striptags -%}
{%- set meta_description = record.metadata.description|striptags -%}
{%- set meta_authors = record.metadata.creators|map(attribute='name') -%}
{%- set meta_authors = record.metadata.creators|map(attribute='person_or_org.name') -%}
{%- set contributors = record.metadata.contributors| rejectattr('role.id', 'equalto', 'editor') | map(attribute='person_or_org.name') -%}


{%- set meta_publisher = record.metadata.publisher %}
{%- set files = record.files %}

<!-- skip the tag for pdf_url -->
{{- meta_highwire(meta_title,meta_description,authors=meta_authors,publisher=meta_publisher,publication_date=record.metadata.publication_date|from_isodate,doi=record.pids.get("doi", {}).get("identifier"),keywords=record.metadata.subjects | map(attribute="subject"),url=record.links.self_html) }}

{%- for c in contributors %}
<meta name="citation_contributor" content="{{c}}" />
{%- endfor %}

{{- meta_opengraph(meta_title, meta_description, url=record.links.self_html) }}
{{- meta_twittercard(meta_title, meta_description) }}

Expand Down
21 changes: 11 additions & 10 deletions tests/ui/test_meta_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@
#
# ultraviolet is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.
"""View tests of the front page."""
"""Tests for meta.html."""


from invenio_rdm_records.proxies import current_rdm_records_service
from invenio_access.permissions import system_identity
from io import BytesIO
from flask import url_for

from invenio_accounts.testutils import login_user_via_session
Expand All @@ -38,11 +37,13 @@ def test_meta_tags(full_record, services, client, app, db, admin_user):
response = client.get(record_url)
html_content = response.data.decode()

assert '<meta name="citation_title"' in html_content, "Missing citation_title tag"
assert '<meta name="description"' in html_content, "Missing description tag"
assert '<meta name="citation_author"' in html_content, "Missing author tag"
assert '<meta name="citation_publication_date"' in html_content, "Missing citation_publication_date tag"
assert '<meta name="citation_publisher"' in html_content, "Missing citation_publisher tag"
assert '<meta name="citation_doi"' in html_content, "Missing citation_doi tag"
assert '<meta name="citation_keywords"' in html_content, "Missing citation_keywords tag"
assert '<meta name="citation_abstract_html_url"' in html_content, "Missing citation_abstract_html_url tag"
assert '<meta name="citation_title" content="InvenioRDM" />' in html_content, "Missing citation_title tag"
assert '<meta name="description" content="A description with HTML tags" />' in html_content, "Missing description tag"
assert '<meta name="citation_author" content="Nielsen, Lars Holm" />' in html_content, "Missing author tag"
assert '<meta name="citation_publication_date" content="2020/09/01" />' in html_content, "Missing citation_publication_date tag"
assert '<meta name="citation_publisher" content="InvenioRDM" />' in html_content, "Missing citation_publisher tag"
assert '<meta name="citation_doi" content="10.1234/inveniordm.1234" />' in html_content, "Missing citation_doi tag"
assert '<meta name="citation_keywords" content="custom" />' in html_content, "Missing citation_keywords tag"
assert '<meta name="citation_abstract_html_url" content="https://127.0.0.1:5000/records/' in html_content, "Missing citation_abstract_html_url tag"
assert '<meta name="citation_contributor" content="Nielsen, Lars Holm" />' in html_content, "Missing contirbutor tag"

0 comments on commit f2fe388

Please sign in to comment.