commit 9188941
0uppy
·
2026-05-10 18:15:06 +0000 UTC
parent 401496b
ssg: we can use local images instead of links to call images on the markdown file now
1 files changed,
+36,
-0
+36,
-0
1@@ -0,0 +1,36 @@
2+package ssg
3+
4+import (
5+ "io"
6+ "io/fs"
7+ "log/slog"
8+ "os"
9+ "path/filepath"
10+)
11+
12+// i couldn't come up with a better name for the function without it being too verbose but bwaaa who cares ig ;w;
13+func FromMedia(mediaDir string, outputDir string) error {
14+ err := filepath.WalkDir(mediaDir, func(path string, d fs.DirEntry, err error) error {
15+ if err != nil {
16+ slog.Error("got err while reading path", "path", path, "err", err) // those who error :skull:
17+ return filepath.SkipDir
18+ }
19+ if d.IsDir() {
20+ return nil
21+ }
22+ destPath := filepath.Join(outputDir, filepath.Base(path))
23+ src, err := os.Open(path)
24+ if err != nil {
25+ return err
26+ }
27+ defer src.Close()
28+ dst, err := os.Create(destPath)
29+ if err != nil {
30+ return err
31+ }
32+ defer dst.Close()
33+ _, err = io.Copy(dst, src)
34+ return err
35+ })
36+ return err
37+}