ministryofjustice / justice-gov-uk

Justice UK website
https://www.justice.gov.uk/
MIT License
2 stars 0 forks source link

Feature/cdpt 1739 file download #230

Closed EmilyHazlehurst closed 3 months ago

EmilyHazlehurst commented 3 months ago

Based on https://github.com/ministryofjustice/justice-gov-uk/pull/229

EmilyHazlehurst commented 3 months ago

This looks good on it's own but I think it would be helpful to add some context.

This page is an example of where an editor has created a table in the block editor, and created links to zips.

And, I think there are other pages where editors have added these download links inline with paragraphs.

At the moment, the mechanism for adding one of the icons is to create a link in the editor, and set the href to a document. Based on the file extension, a download icon is shown.

To rollout this block should we ask the editor to continue adding documents in the same way? And use some backend code to filter content:

e.g. from

<p>some text <a href="https://www.justice.gov.uk/courts/procedure-rules/family/zips/fpr-update-5-html.zip">HTML</a> </p>

to

<p>some text <div class="file-download">
    <i class="file-download__icon icon-{{ format|lower }}--sm" aria-hidden="true"></i>
    <a class="file-download__link" href={{ link }}>
        <span class="file-download__prefix visually-hidden">Download</span>
        {{ filename }}
    </a>
    <span class="file-download__details">({{ language ? language ~ ", " : "" }}{{ format }}, {{ filesize }})</span>
</div></p>

Thanks @EarthlingDavey, yes I was planning on doing something like that when integrating it into the backend.

I've added the code into this PR for completeness, but essentially I'm using the render_block hook to replace the existing link with the new template.

My main concern is that the editors have accounted for things like the filesize not being calculated automatically, so when we replace the link it appears twice in some places:

Screenshot 2024-07-29 at 11 05 04

Depending on how many instances of this type of link there are we could potentially update them manually.

Ultimately I don't want the editors to have to make any changes to how they add content so it may be that we don't use this in the end, but it's a good template for other block components so probably worth keeping for now.