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

inline images #224

Merged
merged 34 commits into from
Nov 30, 2022
Merged

inline images #224

merged 34 commits into from
Nov 30, 2022

Conversation

alixander
Copy link
Collaborator

@alixander alixander commented Nov 26, 2022

Got the method from @berniexie's PR #178 (closes #176 )

Just adapted to use Go to fetch images instead of JS.

Also, reads local images and inlines them in the SVG, since localhost cannot access local files. This closes #146

Copy link
Contributor

@berniexie berniexie left a comment

Choose a reason for hiding this comment

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

Makes sense to me. Very cool

alixander and others added 5 commits November 29, 2022 11:15
- Correct concurrency
- Return multierr
- Use []byte wherever possible
- Add semaphore to limit number of workers
- Separate timeout for each fetch
@alixander alixander requested a review from nhooyr November 29, 2022 22:20
return svg, err
}
if resp.err != nil {
err = multierr.Combine(err, resp.err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove multierr and log the errors. Otherwise cmdlog.Logger.Nerrors will always return zero.

Copy link
Collaborator Author

@alixander alixander Nov 30, 2022

Choose a reason for hiding this comment

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

i changed the return svg, nil from ur commit to return svg, err above. so all should be good

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh nice catch but I'm saying we get rid of multierr to log all errors as they come in instead of waiting for all images to be fetched before we log errors. Otherwise there's no point in using Nerrors, you could just set a bool in compile() when the imgBundler returns an error and then return an xmain.ExitError with with status 1 if said bool is true at the end of the function.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

hmmm, then this whole thing just doesn't return error at all?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

nvm

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

actually yeah, then there'd be no point in returning an error. which is odd. i think the current way is fine. Nerrors is just checking > 0 anyway, so it's all the same. yes it's the same as setting a bool, but it's cleaner, no extra var

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see why that's odd? It means the CLI is more responsive.

Or actually, yea you ought to return a boolean here then and not even rely on Nerrors, I'm going to remove that. It's not cleaner, it's an unnecessary/nonlocal/magic API.

i.e return an ok bool from this function when the svg is totally good and no images errored and return false when at least one image failed. and then use that bool in compile to return the exit error.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ok sure. but why return a bool? why not just return the error like before?

Copy link
Contributor

Choose a reason for hiding this comment

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

I figure you don't need to, you're going to log that error, you're just going to check if it exists so a simple boolean suffices.

But now that I think about it, just return the xmain.ExitError here and then in compile() return the return error of imgbundler.Inline<whatever> after writing the output. That's perfect.

@alixander alixander requested a review from nhooyr November 30, 2022 01:01
@alixander alixander requested a review from nhooyr November 30, 2022 01:09
@berniexie
Copy link
Contributor

berniexie commented Nov 30, 2022

Can we have the bundle flag also inline all the remote images? Or create a separate flag

@alixander
Copy link
Collaborator Author

merging for now, @nhooyr will followup

@alixander alixander merged commit 0de29f0 into terrastruct:master Nov 30, 2022
@alixander alixander deleted the png-img branch November 30, 2022 01:37
@alixander
Copy link
Collaborator Author

Can we have the bundle flag also inline all the remote images? Or create a separate flag

is this for Obsidian integration? they don't let SVGs load remote images?

@nhooyr
Copy link
Contributor

nhooyr commented Nov 30, 2022

is this for Obsidian integration? they don't let SVGs load remote images?

No I don't know anything about Obsidian. literally nothing. we just talked about it once, creating standalone output svgs with zero linked assets.

@alixander
Copy link
Collaborator Author

bro what, i was asking bernard lol

@nhooyr
Copy link
Contributor

nhooyr commented Nov 30, 2022

I had a comment above before him about literally the exact same thing!

Didn't even realize he also commented lmfao

@nhooyr
Copy link
Contributor

nhooyr commented Nov 30, 2022

Actually idk if I did comment or i was thinking about it and was going to open an issue later lol. yea cause we already have a bundle flag, so we should listen to it for InlineRemote.

@alixander
Copy link
Collaborator Author

yeah for context we're testing obsidian plugins and imgs aren't working rn. we're not sure if obsidian embedded browser has something to prevent remote imgs from loading in svg's or something. in which case, the bundle flag working for svg's will be a blocker for obsidian plugin

@nhooyr
Copy link
Contributor

nhooyr commented Nov 30, 2022

ok i'll throw it in my follow up

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.

exports: PNG exports have to wait for images to load icons: Local images
4 participants