The view named by -default-view (timeline, the default, or grid) is published at the site root; the other is served under /timeline/ or /grid/. viewBase and pageURL derive every page path, pager link and the Timeline<->Grid cross-link from the single setting, and Build removes both timeline/ and grid/ on each run so flipping the default never leaves a stale root behind. Reimplemented on trunk (which has albums and the /manage feature) rather than cherry-picked, since the original was written against an earlier base. Credit for the edit/delete and default-view ideas goes to Santhosh Raju, now noted in a README Contributors section. - main.go: -default-view flag, validated (fatal on anything but timeline/grid) - module.nix: services.photogallery.defaultView enum option - templates: timeline/grid/day/album/albums cross-links use TimelineURL/GridURL - tests: timeline-root, grid-root, and switch-cleanup
64 lines
3.0 KiB
Go
64 lines
3.0 KiB
Go
package main
|
|
|
|
import (
|
|
"flag"
|
|
"log"
|
|
"os"
|
|
)
|
|
|
|
func main() {
|
|
contentDir := flag.String("content", "./content", "directory containing images and .toml sidecars")
|
|
outputDir := flag.String("output", "./public", "directory for generated site output")
|
|
baseURL := flag.String("base-url", "http://localhost:8080", "public base URL, no trailing slash")
|
|
port := flag.String("port", "8080", "port to listen on")
|
|
serve := flag.Bool("serve", false, "serve the generated site on the same port (for local development)")
|
|
author := flag.String("author", "Ashik Salahudeen", "author name shown on the profile header, photo pages and in the copyright footer")
|
|
handle := flag.String("handle", "@puttaalu@inflo.ws", "handle line shown under the author name on the profile header")
|
|
bio := flag.String("bio", "Personal photo journal.", "primary bio line shown on the profile header")
|
|
bioAlt := flag.String("bio-alt", "എന്തിനോ വേണ്ടി തിളയ്ക്കുന്ന സാമ്പാർ", "secondary bio line rendered on a new line in the alt-script font")
|
|
fontsURL := flag.String("fonts-url", "https://fonts.googleapis.com/css2?family=Crimson+Pro:ital,wght@0,400;0,600;0,700;1,400&family=Manjari:wght@100;400;700&display=swap", "stylesheet URL loading the two web fonts")
|
|
serifFamily := flag.String("serif-family", "Crimson Pro", "CSS font-family for the primary serif text")
|
|
mlFamily := flag.String("ml-family", "Manjari", "CSS font-family for the alt-script (Malayalam) bio line")
|
|
pageSize := flag.Int("page-size", 60, "photos per page on the timeline and grid views (timeline packs whole days, so pages vary slightly around this)")
|
|
htpasswd := flag.String("htpasswd", "", "path to an htpasswd file (bcrypt, `htpasswd -B`) guarding /upload; empty disables auth")
|
|
defaultView := flag.String("default-view", viewTimeline, "view published at the site root: \"timeline\" or \"grid\"; the other is published under /<name>/")
|
|
flag.Parse()
|
|
|
|
if *defaultView != viewTimeline && *defaultView != viewGrid {
|
|
log.Fatalf("-default-view must be %q or %q, got %q", viewTimeline, viewGrid, *defaultView)
|
|
}
|
|
|
|
for _, d := range []string{*contentDir, *outputDir} {
|
|
if err := os.MkdirAll(d, 0755); err != nil {
|
|
log.Fatalf("mkdir %s: %v", d, err)
|
|
}
|
|
}
|
|
|
|
g := NewGenerator(*contentDir, *outputDir, *baseURL, *author, *handle, *bio, *bioAlt, *fontsURL, *serifFamily, *mlFamily, *pageSize, *defaultView)
|
|
|
|
if err := g.Build(); err != nil {
|
|
log.Printf("initial build: %v", err)
|
|
}
|
|
|
|
w, err := NewWatcher(*contentDir, g)
|
|
if err != nil {
|
|
log.Fatalf("watcher: %v", err)
|
|
}
|
|
defer w.Close()
|
|
go w.Watch()
|
|
|
|
var auth *Authenticator
|
|
if *htpasswd != "" {
|
|
auth, err = LoadHtpasswd(*htpasswd)
|
|
if err != nil {
|
|
log.Fatalf("htpasswd: %v", err)
|
|
}
|
|
log.Printf("upload auth: enabled (%s)", *htpasswd)
|
|
} else {
|
|
log.Print("upload auth: DISABLED (no -htpasswd); /upload is open")
|
|
}
|
|
|
|
s := NewServer(*port, *contentDir, *outputDir, *serve, g, auth)
|
|
log.Fatal(s.Listen())
|
|
}
|