-
-
Notifications
You must be signed in to change notification settings - Fork 0
Add debugging logs to SEO post generation #134
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,11 +27,15 @@ const ( | |
| func (g *Generator) preparePostImage(post payload.PostResponse) (preparedImage, error) { | ||
| source := strings.TrimSpace(post.CoverImageURL) | ||
| if source == "" { | ||
| cli.Grayln(fmt.Sprintf("Skipping image preparation for %s: no cover image", post.Slug)) | ||
| return preparedImage{}, errors.New("post has no cover image url") | ||
| } | ||
|
|
||
| cli.Grayln(fmt.Sprintf("Preparing post image for %s from %s", post.Slug, source)) | ||
|
|
||
| spaImagesDir, err := g.spaImagesDir() | ||
| if err != nil { | ||
| cli.Errorln(fmt.Sprintf("Could not determine SPA images directory: %v", err)) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This error log is redundant. The error is returned and logged by the caller in This applies to the other new error logs in this function on lines 65, 71, and 77 as well. |
||
| return preparedImage{}, err | ||
| } | ||
|
|
||
|
|
@@ -48,22 +52,29 @@ func (g *Generator) preparePostImage(post payload.PostResponse) (preparedImage, | |
| return preparedImage{}, err | ||
| } | ||
|
|
||
| bounds := img.Bounds() | ||
| cli.Grayln(fmt.Sprintf("Fetched image %s (%s) with bounds %dx%d", source, format, bounds.Dx(), bounds.Dy())) | ||
|
|
||
| resized := pkgimages.Resize(img, seoImageWidth, seoImageHeight) | ||
| cli.Grayln(fmt.Sprintf("Resized image to %dx%d", seoImageWidth, seoImageHeight)) | ||
|
|
||
| ext := pkgimages.DetermineExtension(source, format) | ||
| fileName := pkgimages.BuildFileName(post.Slug, ext, "post-image") | ||
|
|
||
| if err := os.MkdirAll(spaImagesDir, 0o755); err != nil { | ||
| cli.Errorln(fmt.Sprintf("Unable to create SPA images directory %s: %v", spaImagesDir, err)) | ||
| return preparedImage{}, fmt.Errorf("create destination dir: %w", err) | ||
| } | ||
|
|
||
| destPath := filepath.Join(spaImagesDir, fileName) | ||
| if err := pkgimages.Save(destPath, resized, ext, pkgimages.DefaultJPEGQuality); err != nil { | ||
| cli.Errorln(fmt.Sprintf("Unable to save resized image to %s: %v", destPath, err)) | ||
| return preparedImage{}, fmt.Errorf("write resized image: %w", err) | ||
| } | ||
|
|
||
| relativeDir, err := filepath.Rel(g.Page.OutputDir, spaImagesDir) | ||
| if err != nil { | ||
| cli.Errorln(fmt.Sprintf("Unable to determine relative path for %s: %v", spaImagesDir, err)) | ||
| return preparedImage{}, fmt.Errorf("determine relative image path: %w", err) | ||
| } | ||
|
|
||
|
|
@@ -73,6 +84,8 @@ func (g *Generator) preparePostImage(post payload.PostResponse) (preparedImage, | |
| relative := path.Join(relativeDir, fileName) | ||
| relative = pkgimages.NormalizeRelativeURL(relative) | ||
|
|
||
| cli.Grayln(fmt.Sprintf("Post image relative path: %s", relative)) | ||
|
|
||
| return preparedImage{ | ||
| URL: g.siteURLFor(relative), | ||
| Mime: pkgimages.MIMEFromExtension(ext), | ||
|
|
||
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
truncateForLogfunction could panic ifmaxRunesis set to a value less than 3. While it's a constant set to 80 for now, it's good practice to make utility functions robust against such changes. I'd suggest adding a check to handle small values ofmaxRunesgracefully.