diff --git a/config.go b/config.go index 37cadfa..2759d60 100644 --- a/config.go +++ b/config.go @@ -4,6 +4,8 @@ import ( "gopkg.in/yaml.v3" "log/slog" "os" + "path" + "strings" ) func readConfig(configFilePath string) (resumeConfig *Resume, err error) { @@ -24,3 +26,17 @@ func readConfig(configFilePath string) (resumeConfig *Resume, err error) { } return } + +func photoIsLocal(photoLocation string) bool { + return !strings.HasPrefix(photoLocation, "http") +} + +func getPhotoPaths(cfg *Resume) (dir, relDir string) { + photo := cfg.Profile.Photo + if strings.HasPrefix(photo, ".") { + photo = strings.TrimPrefix(photo, ".") + } + dir, _ = path.Split(photo) + relDir = "." + dir + return +} diff --git a/data/photo/Mickey_Mouse_Steamboat_Willie.jpg b/data/photo/Mickey_Mouse_Steamboat_Willie.jpg new file mode 100644 index 0000000..d484bc9 Binary files /dev/null and b/data/photo/Mickey_Mouse_Steamboat_Willie.jpg differ diff --git a/data/resume.example.yaml b/data/resume.example.yaml index 02a5250..8f789c4 100644 --- a/data/resume.example.yaml +++ b/data/resume.example.yaml @@ -5,7 +5,7 @@ meta: # Set the content for the robots meta tag (noindex to disable search engine indexing) robots: "index, follow" language: "en-EN" - author: "Donald Duck" + author: "Mickey Mouse" # theme-color: "#bd93f9" title: "" description: "Professional job applicant" @@ -13,12 +13,14 @@ meta: github-corner: false theme: "light" profile: - name: "Donald Duck" + name: "Mickey Mouse" title: "Professional job applicant" city: "City, Country" phone: "+358 xx xxx xxxx" email: "your@email.com" - photo: "url-to-photo" + ## Place a local photo in ./data/photo/, the path here is relative to the executable + ## Photo can be a link too, use the full URL (https://example.com/path/to/photo.jpg) + photo: "./data/photo/Mickey_Mouse_Steamboat_Willie.jpg" summary: >- Insert summary here. Multiple lines can be used, but line breaks are determined diff --git a/main.go b/main.go index 644ffde..ec210b3 100644 --- a/main.go +++ b/main.go @@ -22,7 +22,7 @@ func main() { cfgFile := flag.String("config", "./data/resume.yaml", "Path to the configuration YAML") flag.Parse() - _, err := readConfig(*cfgFile) + cfg, err := readConfig(*cfgFile) if err != nil { slog.Error(fmt.Sprintf("error reading configuration: %s", err.Error())) os.Exit(1) @@ -34,7 +34,10 @@ func main() { mux.HandleFunc("/light", home) mux.HandleFunc("/dark", home) mux.Handle("/static/", staticFileServer) - + if photoIsLocal(cfg.Profile.Photo) { + dir, relDir := getPhotoPaths(cfg) + mux.Handle(dir, http.StripPrefix(dir, http.FileServer(http.Dir(relDir)))) + } slog.Info("Starting go-resume server, listening on port 3000") err = http.ListenAndServe("0.0.0.0:3000", mux) slog.Error(err.Error())