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

feat: Saving image previews #373

Merged
merged 18 commits into from
Jan 1, 2024
Merged

Conversation

Lyrete
Copy link
Contributor

@Lyrete Lyrete commented Dec 30, 2023

Describe your changes

  • Implemented a function to scrape the og_image from the resource, convert it to a .webp and write it to a file in static/previews.
  • Update ListItem.svelte to use the base url in front of the og_preview so they point correctly.
  • Some other minor nitpick fixes

New dependencies

Related issue number/link

Fixes #219
Will probably help with #201 as well

@Lyrete Lyrete changed the title Saving image previews feat: Saving image previews Dec 30, 2023
@VeckoTheGecko
Copy link
Collaborator

VeckoTheGecko commented Dec 30, 2023

This looks awesome!

Re. your #219 (comment)

What was the idea with the naming schema? For an initial thing I implemented a 8 char hex digest off the resource name...

Using the URL instead of resource name would ensure no name collisions. You can use a hex digest of that, or make the URL filename safe (the former probably a better option to avoid filename length issues).

Otherwise this is fairly done so it's a question of whether you'd prefer two PRs if I do #218 too.

I think two separate PRs would be great and be a bit easier to review (especially since I'm less familiar with async stuff so want better visibility on that). I'm happy to review this ASAP so that your workflow isn't interrupted, feel free to mark as "ready for review" when you're ready :) .

Copy link
Collaborator

@VeckoTheGecko VeckoTheGecko left a comment

Choose a reason for hiding this comment

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

ik its a draft, but here are some preliminary thoughts :) .

scripts/get_og_previews.py Outdated Show resolved Hide resolved
scripts/get_og_previews.py Outdated Show resolved Hide resolved
static/previews/.gitkeep Outdated Show resolved Hide resolved
@Lyrete
Copy link
Contributor Author

Lyrete commented Dec 30, 2023

Using the URL instead of resource name would ensure no name collisions. You can use a hex digest of that, or make the URL filename safe (the former probably a better option to avoid filename length issues).

Was actually already doing that while you posted your comment :D

I'll do a bit of clean up and then should be good to go :) There's a good chance I have to touch this functionality anyway while doing the parallelization, so better not to go too deep with the optimizing.

@VeckoTheGecko
Copy link
Collaborator

VeckoTheGecko commented Dec 30, 2023

so better not to go too deep with the optimizing.

That's fair. I think rather than rescaling then, let's just make sure that we properly do the conversion to webp and jpeg formats. This is quick convo I had with ChatGPT that may help with development. Looks like a quick call to Pillow.

Rescaling can be left to another PR

@Lyrete Lyrete marked this pull request as ready for review December 30, 2023 18:54
@Lyrete
Copy link
Contributor Author

Lyrete commented Dec 30, 2023

Implemented the webp thing so should be fairly good to go now. Fairly big bump (30-40s) to the build time but I guess that should get optimized in the next one.

Oh wait the Pillow dep isn't in there yet, oops.

@Lyrete
Copy link
Contributor Author

Lyrete commented Dec 30, 2023

There's some github actions issue btw, where the build workflow happens if a precommit was made on github on a PR but not if it wasn't. I don't know which is your intention.

Copy link
Collaborator

@VeckoTheGecko VeckoTheGecko left a comment

Choose a reason for hiding this comment

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

I'll implement these, just putting here for transparency

scripts/get_og_previews.py Outdated Show resolved Hide resolved
scripts/get_og_previews.py Outdated Show resolved Hide resolved
scripts/get_og_previews.py Outdated Show resolved Hide resolved
@VeckoTheGecko
Copy link
Collaborator

# TODO: Maybe add additional behaviour to check if the image is large enough

I've removed this TODO comment. I think its a very low priority issue, and would be the 'fault' of the website we're scraping from. If we add image rescaling/optimisation, this can be rolled into that I guess.

@VeckoTheGecko
Copy link
Collaborator

There's some github actions issue btw

I think thats due to the permissions and me having to authorize workflows. I don't think its an issue

@VeckoTheGecko
Copy link
Collaborator

VeckoTheGecko commented Jan 1, 2024

I think 22798d3 was breaking 😅 At least in the VScode Markdown preview. Reverting for wider compatability

Copy link
Collaborator

@VeckoTheGecko VeckoTheGecko left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for this PR @Lyrete 🥳🥳🥳🥳

@VeckoTheGecko VeckoTheGecko merged commit 2a58326 into ClimateTown:main Jan 1, 2024
1 of 2 checks passed
@VeckoTheGecko
Copy link
Collaborator

@all-contributors please add @Lyrete for code

Copy link
Contributor

@VeckoTheGecko

I've put up a pull request to add @Lyrete! 🎉

@Lyrete
Copy link
Contributor Author

Lyrete commented Jan 1, 2024

I think 22798d3 was breaking 😅 At least in the VScode Markdown preview. Reverting for wider compatability

Interestingz for me the emoji was breaking 🤔 the link in the radme doesn't work with it.

@VeckoTheGecko
Copy link
Collaborator

Ah, didn't think to check the README on GitHub 😅. I'll revert the reversion 😁

VeckoTheGecko added a commit that referenced this pull request Jan 1, 2024
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.

[FEATURE] Saving and optimizing resource previews
2 participants