-
Notifications
You must be signed in to change notification settings - Fork 2
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
ImgProxy CDN #66
ImgProxy CDN #66
Conversation
let adjusted_url = if let Some(imgproxy_url) = config.imgproxy_url.as_ref() { | ||
format!( | ||
"{}/unsafe/rs:auto:1000:0:false:false/plain/{}", | ||
imgproxy_url, | ||
urlencoding::encode(&self.url) | ||
) | ||
} else { | ||
self.url | ||
}; |
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.
The issue I'm running into here that needs to be solved is that the self.url
here is likely a relative path to the image, which isn't something I can send to imgproxy
So I need to get the URL of the page we are rendering in here to be able to move forward
URL for imgproxy: https://imgproxy-cja.fly.dev/ |
server/src/http_server/cmd.rs
Outdated
]; | ||
|
||
if std::env::var("CRON_DISABLED").unwrap_or_else(|_| "false".to_string()) != "true" { |
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 code checks an environment variable to determine whether to enable
ordisable cron
jobs.
_config: &AppConfig, | ||
_context: &SyntaxHighlightingContext, | ||
) -> Result<Markup> { | ||
fn into_html(self, config: &AppConfig, context: &SyntaxHighlightingContext) -> Result<Markup> { |
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.
function into_html
take the
Markdown
image syntax into HTML, constructing the image URL
by combining the base URL
, article path
, and image filename
.
.ast | ||
.into_html(&state.app, &state.markdown_to_html_context) | ||
{ | ||
// creating some context for the article_path |
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.
context
vat attempts to clone the existing markdown-to-html
context and updates
it with the current article's path
.gitignore
Outdated
@@ -17,3 +17,5 @@ models | |||
tmp_base_model | |||
|
|||
server/src/local.rs | |||
|
|||
CRON_DISABLED=true |
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.
Hehe wrong file for this 😉
This wants to be in your .envrc
file (any likely is I feel like lol)
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.
I put it there by accident lol
tailwindcss
Outdated
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.
Ahh we don't want this binary file in the repo! It should also be in your ~/bin
dir so I think we can leave it off here!
.split('/') | ||
.next() |
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.
Would be nice to not do any path parsing 'manually' 🤔
This is grabbing the stuff before the first /
right? Whats after the slash lol?
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.
In my local directory, I have a URL like this: http://localhost:3000/posts/BattlesnakeMinimax/Minimax%20in%20Battlesnake/.
I only need the part of the URL before Minimax%20in%20Battlesnake
for the image path. To achieve this, I split the URL and grab everything I need before Minimax%20in%20Battlesnake
"{}/posts/{}/{}", | ||
config.base_url.trim_end_matches('/'), | ||
article_path, | ||
self.url.trim_start_matches("../") |
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.
Would be nice to avoid this path parsing too!
Could we use some Rust Path structs/methods to like join the paths together? I feel like if we told it to join the paths and one has a ../
it will do the 'correct' thing and move up a directory there! 🤞
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.
Looking great!
Left some comments on the structs and then on the manual path parsing logic!
…get the full url here which requires piping context down farther
… related to SyntaxHighlightingContext
2379087
to
75a78fb
Compare
@@ -19,6 +21,7 @@ use crate::AppConfig; | |||
pub struct SyntaxHighlightingContext { | |||
pub(crate) theme: syntect::highlighting::Theme, | |||
pub(crate) syntax_set: syntect::parsing::SyntaxSet, | |||
pub(crate) current_article_path: Option<String>, |
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.
We can remove this now that we have the new MarkdownRenderContext
struct right?
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.
Did this come back in a merge maybe?
We have the MarkdownRenderContext
so I think we can/want to remove this path from this struct!
.unwrap_or("unknown"); | ||
|
||
let base_url = PathBuf::from(config.base_url.trim_end_matches('/')); | ||
let image_path = PathBuf::from(self.url.trim_start_matches("./")); |
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.
./
means that we stay in the current path so this is actually fine to keep in!
The PathBuf::join
method know hows to handle this and strips it our for us!
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.
You can also call join
and pass it a &str so you don't have to convert it to a PathBuf first!
Hey @Seif-Mamdouh! I pulled down the code to check it running and it run great for me without any changes! So don't think you broke it at the end lol I was curious about a refactor and then kinda just did it 😆 Here is a link to the commit where I did most of the refactoring. I wrote a longer commit message so hopefully reading that can kinda show my thought processes since I didn't record doing this refactor. And then also just highlighting these two code level comments I left on your changes before I refactored them: #66 (comment) I think this is looking really good for getting the absolute URL on image now! So what we want to do is when we make the This is a good article on how to use this to serve different sized images to different sized devices! https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Responsive_images The idea is that we want to do that! But we only have the original sized images in our repo. So instead of linking to hard coded resized images, we want to link to Here are the |
…get the full url here which requires piping context down farther
… related to SyntaxHighlightingContext
let small_url = generate_imgproxy_url(base_url, &img_src, 300, 300); | ||
let medium_url = generate_imgproxy_url(base_url, &img_src, 600, 600); | ||
let large_url = generate_imgproxy_url(base_url, &img_src, 1200, 1200); |
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.
For these can we maybe do height 0
so that imgproxy calculates the right height based on the width?
Since we are using the width for picking the right image source (which I like!) I think we might want to just use that and leave off the heights and let imgproxy figure those out!
When set to 0, imgproxy will calculate resulting height using the defined width and source aspect ratio.
From: https://docs.imgproxy.net/usage/processing#resize
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.
Make sense
…guess to format of the fly url but I think thats ok
# Via GitHub * main: Remove Neon Review App branches on PR close (#70) # Conflicts: # .github/workflows/fly_review.yml
I setup an instance of
imgproxy
and a BunnyCDN in front of it to help handle images for meThe idea is that the site can now request images from
imgproxy
and ask for them at specific sizes and dimensions, likely inside apicture
HTML element so the browser can pick the size thats best