- Timestamp:
- Apr 21, 2023, 11:06:28 PM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/cmd/aya/main.go
r60 r61 5 5 "fmt" 6 6 "io" 7 " io/ioutil"7 "net/http" 8 8 "os" 9 9 "os/exec" … … 60 60 func run(vars Vars, cmd string, args ...string) (string, error) { 61 61 // First check if partial exists (.html) 62 if b, err := ioutil.ReadFile(filepath.Join(AYADIR, cmd+".html")); err == nil {62 if b, err := os.ReadFile(filepath.Join(AYADIR, cmd+".html")); err == nil { 63 63 return string(b), nil 64 64 } … … 91 91 // If no empty newline is found - file is treated as content-only. 92 92 func getVars(path string, globals Vars) (Vars, string, error) { 93 b, err := ioutil.ReadFile(path)93 b, err := os.ReadFile(path) 94 94 if err != nil { 95 95 return nil, "", err … … 360 360 } 361 361 } 362 // Serve the public directory over HTTP 363 func servePubDir() { 364 rootdir := http.Dir(PUBDIR) 365 http.Handle("/", http.FileServer(rootdir)) 366 log.Fatal(http.ListenAndServe(":8000", nil)) 367 } 362 368 363 369 func init() { … … 373 379 fmt.Printf("Where <command> is:\n") 374 380 fmt.Printf("\tbuild\tGenerate site\n") 381 fmt.Printf("\tserve\tServe %v over HTTP\n", PUBDIR) 382 fmt.Printf("\tvar\tQuery variable(s) from a markdown file\n") 383 fmt.Printf("\tversion\tPrint program version and exit\n") 375 384 fmt.Printf("\twatch\t(Re)generate site while looking for changes\n") 376 fmt.Printf("\tvar\tQuery a variable from a markdown file\n")377 fmt.Printf("\tversion\tPrint version and exit\n")378 385 fmt.Printf("\n") 379 386 fmt.Printf("Other commands may be dynamically added by plugins found in %v\n", AYADIR) … … 398 405 fmt.Println("ERROR: too many arguments") 399 406 } 400 case " watch":401 buildAll(true)407 case "serve": 408 servePubDir() 402 409 case "var": 403 410 if len(args) == 0 { … … 421 428 } 422 429 case "version": 423 fmt.Printf("%v\n", aya. Version)430 fmt.Printf("%v\n", aya.FullVersion()) 424 431 os.Exit(0) 432 case "watch": 433 buildAll(true) 425 434 default: 426 435 if s, err := run(globals(), cmd, args...); err != nil {
Note:
See TracChangeset
for help on using the changeset viewer.