Skip to content
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

Turn reference URLs into hyperlinks #2234

Merged
merged 7 commits into from
May 13, 2024
Merged

Turn reference URLs into hyperlinks #2234

merged 7 commits into from
May 13, 2024

Conversation

bemoody
Copy link
Collaborator

@bemoody bemoody commented May 13, 2024

References in the References section should include a link, if a URL is provided. Fixes issue #658.

I changed my mind many times about how this should be implemented. At first, I thought that we should separately provide "description" and "URL" fields for authors to edit.

But now I think, actually, the URL is part of the formal reference, and should be displayed as text for transparency's sake. So I think it's better for the URL to be extracted automatically from the description.

On the other hand, I don't want to have ad-hoc parsing rules applied at runtime to published content. (It's possible those rules might change in the future, which I think is okay for active but not for published projects.) So I ended up with this approach:

  • For active projects, the URL is extracted by a regular expression whenever it's needed.
  • When a project is published, the automatically-extracted URL is saved as a model field.
  • For published projects, it's possible to edit the description and url separately via Django admin, but it will only appear as a link if the url appears verbatim within the description.

Benjamin Moody added 7 commits May 13, 2024 15:35
Move the common functionality of the Reference and PublishedReference
classes into a common abstract base class.
This field should hold the URL of the cited work, if any.

In most cases, this should be easy to determine by searching for a
regular expression.  However, if that pattern is changed in the
future, we may not want the new rules to apply retroactively.

Therefore, for published projects, store the URL in a model field, and
perform a one-time migration to compute this field for existing
published projects.
Like the url field of PublishedReference, this should contain the URL
of the cited work, if any.

Unlike published references, this can be automatically derived from
the description, since the results can be checked in the project
preview before publishing.
When a project is published, the URL field of each reference should be
copied from the active Reference object to the new PublishedReference
object.
If a reference has a URL, this should be transformed into a clickable
link.  This is done using either the saved url field
(PublishedReference) or the automatically-derived url property
(Reference).
If a reference has a URL, this should be transformed into a clickable
link; this is done automatically by the BaseReference html_description
property.
@tompollard
Copy link
Member

looks great, thanks!

@tompollard tompollard merged commit c9beed2 into dev May 13, 2024
8 checks passed
@tompollard tompollard deleted the bm/refs-link branch May 13, 2024 23:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants