Skip to content

Commit

Permalink
Merge pull request #3094 from nathreed/fix_og_urls
Browse files Browse the repository at this point in the history
Fix open graph urls for RECAP pdfs
  • Loading branch information
mlissner authored Sep 7, 2023
2 parents f31256f + 9b97802 commit 6c01de9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cl/assets/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<meta property="og:title" content="{% block og_title %}CourtListener{% endblock %}"/>
<meta property="og:description"
content="{% block og_description %}Create alerts, search for and browse the latest court opinions, PACER documents, judges, and oral arguments. Updated automatically with the latest court documents. An initiative of Free Law Project.{% endblock %}">
<meta property="og:url" content="{% get_full_host %}{{ request.path }}"/>
<meta property="og:url" content="{% block og_url %}{% get_full_host %}{{ request.path }}{% endblock %}"/>
<meta property="og:site_name" content="CourtListener"/>
<meta property="og:image"
content="{% block og_image %}{% static "png/og-image-300x300.png" %}{% endblock %}"/>
Expand Down
1 change: 1 addition & 0 deletions cl/opinion_page/templates/recap_document.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
{% endblock %}
{% block og_description %}{% if rd.docket_entry.description %}{{ rd.docket_entry.description }}{% else %}{{ rd.description }}{% endif %}
{% endblock %}
{% block og_url %}{% if og_file_path %}{% get_full_host %}{{ og_file_path }}{% else %}{{ block.super }}{% endif %}{% endblock %}
{% block twitter_card_type %}{% if rd.thumbnail %}summary_large_image{% else %}{{ block.super }}{% endif %}{% endblock %}
{% block og_image %}{% if rd.thumbnail %}{{ rd.thumbnail.url }}{% else %}{{ block.super }}{% endif %}{% endblock %}
{% block og_image_alt %}{% if rd.thumbnail %}The first page of the document in the linked PDF{% else %}{{ block.super }}{% endif %}{% endblock %}
Expand Down
6 changes: 6 additions & 0 deletions cl/opinion_page/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ def redirect_og_lookup(request: HttpRequest) -> HttpResponse:
docket_id=rd.docket_entry.docket_id,
doc_num=rd.document_number,
att_num=rd.attachment_number,
is_og_bot=True,
)


Expand Down Expand Up @@ -438,6 +439,7 @@ def view_recap_document(
doc_num: int | None = None,
att_num: int | None = None,
slug: str = "",
is_og_bot: bool = False,
) -> HttpResponse:
"""This view can either load an attachment or a regular document,
depending on the URL pattern that is matched.
Expand Down Expand Up @@ -519,12 +521,16 @@ def view_recap_document(
else:
note_form = NoteForm(instance=note)

# Override the og:url if we're serving a request to an OG crawler bot
og_file_path_override = rd.filepath_local if is_og_bot else None

return TemplateResponse(
request,
"recap_document.html",
{
"rd": rd,
"title": title,
"og_file_path": og_file_path_override,
"note_form": note_form,
"private": True, # Always True for RECAP docs.
"timezone": COURT_TIMEZONES.get(
Expand Down

0 comments on commit 6c01de9

Please sign in to comment.