Compare commits
No commits in common. "9ba5647ddc2339494b0b0421828de908ef0600eb" and "e88fe268f15475d3f28bc76dbf2902a6b5b9c854" have entirely different histories.
9ba5647ddc
...
e88fe268f1
1
go.mod
1
go.mod
@ -4,7 +4,6 @@ go 1.21.4
|
||||
|
||||
require (
|
||||
github.com/joho/godotenv v1.5.1
|
||||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646
|
||||
golang.org/x/oauth2 v0.23.0
|
||||
gopkg.in/yaml.v2 v2.4.0
|
||||
gopkg.in/yaml.v3 v3.0.1
|
||||
|
2
go.sum
2
go.sum
@ -2,8 +2,6 @@ github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
|
||||
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
||||
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
||||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ=
|
||||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8=
|
||||
golang.org/x/oauth2 v0.23.0 h1:PbgcYx2W7i4LvjJWEbf0ngHV6qJYr86PkAV3bXdLEbs=
|
||||
golang.org/x/oauth2 v0.23.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
|
@ -184,12 +184,5 @@ func DownloadImage(url, slug string) error {
|
||||
}
|
||||
|
||||
fmt.Printf(" - Image saved successfully at: %s\n", filePath)
|
||||
|
||||
// Generate thumbnails for the specified resolutions
|
||||
resolutions := []uint{1024, 640, 320} // Define resolutions array for thumbnails
|
||||
if err := utils.GenerateThumbnails(filePath, slug, imageDir, resolutions); err != nil {
|
||||
return fmt.Errorf("error generating thumbnails: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -231,13 +231,5 @@ func DownloadImage(url, slug, suffix string) error {
|
||||
}
|
||||
|
||||
fmt.Printf(" - Image saved successfully at: %s\n", filePath)
|
||||
|
||||
// Generate thumbnails for the specified resolutions
|
||||
thumbnail_slug := fmt.Sprintf("%s%s", slug, suffix)
|
||||
resolutions := []uint{1024, 640, 320} // Define resolutions array for thumbnails
|
||||
if err := utils.GenerateThumbnails(filePath, thumbnail_slug, imageDir, resolutions); err != nil {
|
||||
return fmt.Errorf("error generating thumbnails: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -102,13 +102,5 @@ func DownloadImage(url, slug, imageType string) error {
|
||||
}
|
||||
|
||||
fmt.Printf(" - Image saved successfully at: %s\n", filePath)
|
||||
|
||||
// Generate thumbnails for the specified resolutions
|
||||
thumbnail_slug := fmt.Sprintf("%s-%s", slug, imageType)
|
||||
resolutions := []uint{1024, 640, 320} // Define resolutions array for thumbnails
|
||||
if err := utils.GenerateThumbnails(filePath, thumbnail_slug, imageDir, resolutions); err != nil {
|
||||
return fmt.Errorf("error generating thumbnails: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -151,12 +151,5 @@ func DownloadImage(url, slug string) error {
|
||||
}
|
||||
|
||||
fmt.Printf(" - Image saved successfully at: %s\n", filePath)
|
||||
|
||||
// Generate thumbnails for the specified resolutions
|
||||
resolutions := []uint{1024, 640, 320} // Define resolutions array for thumbnails
|
||||
if err := utils.GenerateThumbnails(filePath, slug, imageDir, resolutions); err != nil {
|
||||
return fmt.Errorf("error generating thumbnails: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -102,13 +102,5 @@ func DownloadImage(url, slug, imageType string) error {
|
||||
}
|
||||
|
||||
fmt.Printf(" - Image saved successfully at: %s\n", filePath)
|
||||
|
||||
// Generate thumbnails for the specified resolutions
|
||||
thumbnail_slug := fmt.Sprintf("%s-%s", slug, imageType)
|
||||
resolutions := []uint{1024, 640, 320} // Define resolutions array for thumbnails
|
||||
if err := utils.GenerateThumbnails(filePath, thumbnail_slug, imageDir, resolutions); err != nil {
|
||||
return fmt.Errorf("error generating thumbnails: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -8,9 +8,6 @@ rate: {{ .Rate }}
|
||||
pages: {{ .Pages }}
|
||||
progress: {{ .Progress }}
|
||||
image: {{ .Image }}
|
||||
image320: {{ imageSize .Image "320" }}
|
||||
image640: {{ imageSize .Image "640" }}
|
||||
image1024: {{ imageSize .Image "1024" }}
|
||||
date: {{ .Date }}
|
||||
draft: false
|
||||
tags: {{ .Tags }}
|
||||
|
@ -6,17 +6,8 @@ year: {{ .Year }}
|
||||
rate: {{ .Rate }}
|
||||
progress: {{ .Progress }}
|
||||
image: {{ .Image }}
|
||||
image320: {{ imageSize .Image "320" }}
|
||||
image640: {{ imageSize .Image "640" }}
|
||||
image1024: {{ imageSize .Image "1024" }}
|
||||
poster-image: {{ .Poster }}
|
||||
poster-image320: {{ imageSize .Poster "320" }}
|
||||
poster-image640: {{ imageSize .Poster "640" }}
|
||||
poster-image1024: {{ imageSize .Poster "1024" }}
|
||||
background-image: {{ .Background }}
|
||||
background-image320: {{ imageSize .Background "320" }}
|
||||
background-image640: {{ imageSize .Background "640" }}
|
||||
background-image1024: {{ imageSize .Background "1024" }}
|
||||
date: {{ .Date }}
|
||||
draft: false
|
||||
tags: {{ .Tags }}
|
||||
|
@ -6,17 +6,8 @@ year: {{ .Year }}
|
||||
rate: {{ .Rate }}
|
||||
progress: {{ .Progress }}
|
||||
image: {{ .Image }}
|
||||
image320: {{ imageSize .Image "320" }}
|
||||
image640: {{ imageSize .Image "640" }}
|
||||
image1024: {{ imageSize .Image "1024" }}
|
||||
poster-image: {{ .Poster }}
|
||||
poster-image320: {{ imageSize .Poster "320" }}
|
||||
poster-image640: {{ imageSize .Poster "640" }}
|
||||
poster-image1024: {{ imageSize .Poster "1024" }}
|
||||
background-image: {{ .Background }}
|
||||
background-image320: {{ imageSize .Background "320" }}
|
||||
background-image640: {{ imageSize .Background "640" }}
|
||||
background-image1024: {{ imageSize .Background "1024" }}
|
||||
date: {{ .Date }}
|
||||
draft: false
|
||||
tags: {{ .Tags }}
|
||||
|
@ -6,9 +6,6 @@ artist: "{{ .Artist }}"
|
||||
year: {{ .Year }}
|
||||
rate: {{ .Rate }}
|
||||
image: {{ .Image }}
|
||||
image320: {{ imageSize .Image "320" }}
|
||||
image640: {{ imageSize .Image "640" }}
|
||||
image1024: {{ imageSize .Image "1024" }}
|
||||
tracks: {{ .Tracks }}
|
||||
date: {{ .Date }}
|
||||
draft: false
|
||||
|
@ -7,17 +7,8 @@ rate: {{ .Rate }}
|
||||
progress: {{ .Progress }}
|
||||
episode: {{ .Episode }}
|
||||
image: {{ .Image }}
|
||||
image320: {{ imageSize .Image "320" }}
|
||||
image640: {{ imageSize .Image "640" }}
|
||||
image1024: {{ imageSize .Image "1024" }}
|
||||
poster-image: {{ .Poster }}
|
||||
poster-image320: {{ imageSize .Poster "320" }}
|
||||
poster-image640: {{ imageSize .Poster "640" }}
|
||||
poster-image1024: {{ imageSize .Poster "1024" }}
|
||||
background-image: {{ .Background }}
|
||||
background-image320: {{ imageSize .Background "320" }}
|
||||
background-image640: {{ imageSize .Background "640" }}
|
||||
background-image1024: {{ imageSize .Background "1024" }}
|
||||
date: {{ .Date }}
|
||||
draft: false
|
||||
tags: {{ .Tags }}
|
||||
|
@ -6,7 +6,6 @@ import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
"text/template"
|
||||
@ -23,15 +22,7 @@ type FrontMatter struct {
|
||||
}
|
||||
|
||||
func GenerateMarkdown(templatePath string, outputPath string, data map[string]interface{}) error {
|
||||
// Define a template funcition that generates image versions
|
||||
funcMap := template.FuncMap{
|
||||
"imageSize": func(imagePath string, size string) string {
|
||||
base := strings.TrimSuffix(imagePath, filepath.Ext(imagePath))
|
||||
return fmt.Sprintf("%s-%s.jpg", base, size)
|
||||
},
|
||||
}
|
||||
|
||||
tmpl, err := template.New(filepath.Base(templatePath)).Funcs(funcMap).ParseFiles(templatePath)
|
||||
tmpl, err := template.ParseFiles(templatePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -106,7 +97,7 @@ func SaveUpdatedMarkdown(filepath string, frontmatter FrontMatter, content strin
|
||||
fileContent := string(fileBytes)
|
||||
|
||||
fieldPatterns := map[string]string{
|
||||
"progress": `(?m)^progress: "(.*)%"$`,
|
||||
"progress": `(?m)^progress: (.*)%$`,
|
||||
"episode": `(?m)^episode: "(.*)"$`,
|
||||
"date": `(?m)^date: (.*)$`,
|
||||
"rate": `(?m)^rate: (\d+\.?\d*)$`,
|
||||
|
@ -1,21 +1,12 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"image"
|
||||
"image/jpeg"
|
||||
_ "image/jpeg"
|
||||
_ "image/png"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
"unicode"
|
||||
|
||||
"github.com/nfnt/resize"
|
||||
)
|
||||
|
||||
func CreateDirIfNotExists(dir string) error {
|
||||
@ -83,49 +74,3 @@ func Sluggify(s string) string {
|
||||
|
||||
return slug
|
||||
}
|
||||
|
||||
func GenerateThumbnails(originalPath, slug, outputDir string, resolutions []uint) error {
|
||||
// Open the original image
|
||||
file, err := os.Open(originalPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error opening original image: %w", err)
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
imgData, err := ioutil.ReadAll(file)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error reading original image data: %w", err)
|
||||
}
|
||||
|
||||
// Decode the original image
|
||||
img, _, err := image.Decode(bytes.NewReader(imgData))
|
||||
if err != nil {
|
||||
return fmt.Errorf("error decoding image: %w", err)
|
||||
}
|
||||
|
||||
// Generate thumbnails for each resolution
|
||||
for _, res := range resolutions {
|
||||
// Resize the image while maintaining the aspect ratio
|
||||
thumbnail := resize.Resize(res, 0, img, resize.Lanczos3)
|
||||
|
||||
// Define the new filename with resolution suffix
|
||||
thumbnailFilename := fmt.Sprintf("%s-%d.jpg", slug, res)
|
||||
thumbnailPath := filepath.Join(outputDir, thumbnailFilename)
|
||||
|
||||
// Save the resized image
|
||||
thumbnailFile, err := os.Create(thumbnailPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error creating thumbnail file: %w", err)
|
||||
}
|
||||
defer thumbnailFile.Close()
|
||||
|
||||
err = jpeg.Encode(thumbnailFile, thumbnail, nil)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error encoding thumbnail: %w", err)
|
||||
}
|
||||
|
||||
fmt.Printf(" - Thumbnail saved successfully at: %s\n", thumbnailPath)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user