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

feature: link to files (for download) #205

Merged
merged 7 commits into from
Nov 9, 2024
Merged

Conversation

jbmoelker
Copy link
Member

@jbmoelker jbmoelker commented Nov 6, 2024

Changes

  • Adds a new file model that provides a generic pattern for content editors to add and reference files.
    • Editors can upload an asset and link to the file records in text and other fields.
    • Editors can select the locale of a file for improved accessibility.
  • Adds a LinkToFile component. See its README for details.
  • Adds a /files/[...filename].ts route to proxy files, so they can be used as downloads.

In CMS:
image

In Page (EN and NL):
image
image

Associated issue

Resolves #148
Closes #147 (outdated earlier attempt based on older routing)

How to test

  1. Navigate to the Files demo page (en)
  2. Review the links and verify that they work.
  3. Switch to nl locale.
  4. Review the links (see they now also display the language of the file) and verify that they work.
  5. Navigate to the page in the CMS
  6. Test and verify how adding a file and a link to it works

Checklist

  • I have performed a self-review of my own code
  • I have made sure that my PR is easy to review (not too big, includes comments)
  • I have made updated relevant documentation files (in project README, docs/, etc)
  • I have added a decision log entry if the change affects the architecture or changes a significant technology
  • I have notified a reviewer

resolves Downloadable files #148
Copy link

cloudflare-workers-and-pages bot commented Nov 6, 2024

Deploying head-start with  Cloudflare Pages  Cloudflare Pages

Latest commit: 1dca0c3
Status: ✅  Deploy successful!
Preview URL: https://94f44980.head-start.pages.dev
Branch Preview URL: https://feat-file-downloads.head-start.pages.dev

View logs

@jbmoelker jbmoelker marked this pull request as ready for review November 6, 2024 21:30
@@ -54,7 +54,6 @@ export default defineConfig({
output: isPreview ? 'server' : 'static',
server: { port: localhostPort },
site: siteUrl,
trailingSlash: 'always',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is required for the file proxy to work (or otherwise the file href need a / suffix like dummy.pdf/) which is odd. I'm okay with having the required trailing slash removed as all our routing and canonicals make sure we have consistent page routes ending with a /.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have tests in place to verify that trailing slashes for routes to records other than files do in fact work?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not yet. I see the routing tests only cover redirects: https://github.com/voorhoede/head-start/blob/main/src/lib/routing/index.test.ts#L31
Will add tests

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added tests. See commit 587caf9

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Figured I should actually also include tests for the LinkToFile component itself. WIP: 970401f (didn't have enough time to finish it)

@jbmoelker jbmoelker mentioned this pull request Nov 6, 2024
Copy link
Contributor

@jurgenbelien jurgenbelien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Record should be the right type. I think that's of bigger benefit than having the abstraction of the function

@@ -54,7 +54,6 @@ export default defineConfig({
output: isPreview ? 'server' : 'static',
server: { port: localhostPort },
site: siteUrl,
trailingSlash: 'always',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have tests in place to verify that trailing slashes for routes to records other than files do in fact work?

src/components/LinkToFile/LinkToFile.astro Show resolved Hide resolved
src/components/LinkToRecord/LinkToRecord.astro Outdated Show resolved Hide resolved
@jurgenbelien jurgenbelien self-requested a review November 8, 2024 07:57
Copy link
Contributor

@jurgenbelien jurgenbelien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed changes and ready to merge

@jurgenbelien jurgenbelien merged commit f457365 into main Nov 9, 2024
5 checks passed
@jurgenbelien jurgenbelien deleted the feat/file-downloads branch November 9, 2024 14:49
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.

Downloadable files
2 participants