Option for a local photo server from ./data/photo/ (relative to executable)

This commit is contained in:
Jarno Rankinen 2024-02-10 11:42:46 +02:00
parent 5a19ed18e7
commit a6a2872eef
4 changed files with 26 additions and 5 deletions

View File

@ -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
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 387 KiB

View File

@ -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

View File

@ -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())