decaporg / decap-cms

A Git-based CMS for Static Site Generators
https://decapcms.org
MIT License
17.92k stars 3.04k forks source link

PDFs Have No Thumbnail Or Icon In Media Gallery #1984

Open Undistraction opened 5 years ago

Undistraction commented 5 years ago

Describe the bug When a .pdf file is uploaded to the Media Gallery, it's preview card is blank. No thumbnail is generated for it. Note that this remains true after a page refresh. Thumbnails are generated for images.

To Reproduce

Expected behavior Either a Thumbnail, or a PDF icon is displayed on the file's preview card.

Observations

Screenshots

screenshot 2018-12-31 at 23 33 02

Applicable Versions:

thebetternewt commented 5 years ago

Agreed! There should be icons for common filetypes, including CSVs in my case.

image

erquhart commented 5 years ago

Closed in #2089.

equivalentideas commented 4 years ago

For my team of authors, there are issues recognising PDFs in the media library. Without a preview to aid recognition, they rely on the file naming, which is often inconsistent, unpredictable, and often out of their control.

For us, a preview image of the first page would make PDF's much more recognisable, by giving some more information about the contents of the file. This is a familiar pattern from Google Drive, Drop Box etc.

I think the current solution was a good first pass, and now we could use this issue to discuss improvements / possible solutions, @erquhart would you be up for re-opening this?

erezrokah commented 4 years ago

Re-opening - this https://github.com/mozilla/pdf.js/ might serve as a solution as long as it doesn't add to much to our bundle size.

equivalentideas commented 4 years ago

Thanks @erezrokah :bread:

tylerbrostrom commented 3 years ago

Spitballing here, but maybe PDF thumbnails could be generated by a third-party image service like Cloudinary.

You could even defer the implementation of that image service to the developer. Say by adding a thumbnail_url option to the file widget. thumbnail_url would accept a string template with access to the site’s URL and the file’s public path:

- name: "pdf"
  widget: "file"
  thumbnail_url: "https://res.cloudinary.com/<cloudinary-id>/image/fetch/<transforms>/{{site_url}}/{{public_path}}.jpg"
  # Appending `.jpg` tells Cloudinary to convert the given PDF file to a JPG. Cool beans!

Yeah, it’s a bit scrappy and definitely hinges on the magic of Cloudinary’s Fetched URL API, which simultaneously uploads an asset from a given URL and responds with a transformed asset. Figured it was still worth sharing!

Folks hosting on Netlify could get super slick with it too, proxying friendlier URLs to Cloudinary:

# netlify.toml

[[redirects]]
    from = "/pdf-to-jpg/*"
    to = """\
        https://res.cloudinary.com/\
        <cloudinary-id>/\
        /image/fetch/\
        q_auto,f_auto,w_720/\
        https://example.netlify.app/:splat.jpg\
        """
    status = 200