-
Notifications
You must be signed in to change notification settings - Fork 12
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
DEV: refactor and add support for new tab previews #2
Conversation
no changes in this commit beyond formatting
forEach and Filter already do a quick return
@pmusaraj Can you please take a look at this when you get a chance? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks quite nice @hnb-ku, a few minor notes:
I wouldn't add the feature to skip inline previews using the space before the filename. It feels fragile and hacky. What is the use case for that, to be able to selectively exclude some PDFs from having a preview?
And an unrelated question: what does a preview in another tab look like? It's an image of the PDF, loaded in a separate tab?
Thanks for your time @pmusaraj
I fully agree with your sentiment about the space before the file name. It's been requested a few times. https://meta.discourse.org/t/inline-pdf-previews/157649/15?u=johani However, Discourse doesn't differentiate between attachments on their own line and inline attachments - as it does for inline oneboxes. So, I had to resort to this. It's a power-user feature, and it's a lot simpler than messing around with the rest of the input in the composer to check for inline attachments in a theme component. This component ignores the composer altogether. Also, please note that the space added only affects the "description" of the file that gets rendered in the post stream. The component also removes that space in the decorator. So, while it is indeed hacky, it won't have any impact on the upload process, the downloaded file, or how Discourse stores it.
It's actually the full file loaded as a blob URL that shows in a new tab. The PDF is opened via the native browser PDF reader. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the explanations @hnb-ku, you've got me convinced.
LGTM!
Cheers @pmusaraj 🙏 Any chance you can merge this so I can update the topic on Meta? |
This PR does 4 things.
Changes the inline preview iFrame src from blob to base64, hopefully resolving some CSP / Safari bugs that are not very easy to repro.
adds an option to skip inline previews for a specific PDF. This can be done by adding a space to the file name in the composer. So, if you change
to
Note the space before "file.pdf" No inline preview will be generated. This does not affect how the filename is rendered when the post is cooked or when the file is downloaded.
Add support for new tab PDF previews - toggled via a setting. The default is still inline rendering, but this gives admins the option to load the PDF file previews in a new tab.
If new tab previews are selected, it changes the icon next to PDF attachments from "download" to "external-link" to indicate that it will open in a new tab.