# HG changeset patch # User yakumo.izuru # Date 1682118388 0 # Node ID cf7277e42ece60140b69010aa59df130d176dcc4 # Parent ed3aa9aaad0abc4bb48c9660a43be7669b942017 Add serve function, update documentation accordingly Signed-off-by: Izuru Yakumo diff -r ed3aa9aaad0a -r cf7277e42ece README.md --- a/README.md Fri Apr 21 20:25:31 2023 +0000 +++ b/README.md Fri Apr 21 23:06:28 2023 +0000 @@ -17,7 +17,7 @@ Build it manually assuming you have Go installed: - $ go install marisa.chaotic.ninja/aya@latest + $ go install marisa.chaotic.ninja/aya/cmd/aya@latest ## Ideology @@ -66,10 +66,10 @@ echo $timestamp \ "" \ "$title" \ - "http://ayaerge.com/$url" \ + "http://zserge.com/$url" \ "$descr" \ "$(date --date @$timestamp -R)" \ - "http://ayaerge.com/$url" \ + "http://zserge.com/$url" \ "" fi done | sort -r -n | cut -d' ' -f2- @@ -93,12 +93,14 @@ `aya build ` re-builds one file and prints resulting content to stdout. -`aya watch` rebuilds your site every time you modify any file. +`aya serve` serves your site over HTTP. `aya var [var1 var2...]` prints a list of variables defined in the header of a given markdown file, or the values of certain variables (even if it's an empty string). +`aya watch` rebuilds your site every time you modify any file. + ## License The software is distributed under the MIT license. diff -r ed3aa9aaad0a -r cf7277e42ece aya.1 --- a/aya.1 Fri Apr 21 20:25:31 2023 +0000 +++ b/aya.1 Fri Apr 21 23:06:28 2023 +0000 @@ -16,21 +16,22 @@ .It Fast (of course) .El .Sh USAGE -.Ss (Re-)build your site. -.Nm -.Cm build -.Ss (Re-)build one file and prints resulting content to standard output. +.Bl -tag +.It build +(Re-)build a site or a file in particular +.It serve +Serve generated site over HTTP +.It var +Print a list of variables defined in a given markdown file. +.It watch +(Re-)build a site if any file changed +.Sh HISTORY .Nm -.Cm build -.Ar -.Ss (Re-)build your site every time you modify any file. -.Nm -.Cm watch -.Ss Print a list of variables defined in the header of a given markdown file. -.Nm -.Cm var -.Ar -.Ar ... +was originally forked from prologic/zs by Izuru +out of disgust with the latest revision, so he +used a earlier commit as a base, and then +eventually reimplemented older features from +zserge's original project. .Sh AUTHORS .Nm is maintained by Izuru Yakumo diff -r ed3aa9aaad0a -r cf7277e42ece cmd/aya/main.go --- a/cmd/aya/main.go Fri Apr 21 20:25:31 2023 +0000 +++ b/cmd/aya/main.go Fri Apr 21 23:06:28 2023 +0000 @@ -4,7 +4,7 @@ "bytes" "fmt" "io" - "io/ioutil" + "net/http" "os" "os/exec" "path/filepath" @@ -59,7 +59,7 @@ // stderr is printed to aya stderr, command output is returned as a string. func run(vars Vars, cmd string, args ...string) (string, error) { // First check if partial exists (.html) - if b, err := ioutil.ReadFile(filepath.Join(AYADIR, cmd+".html")); err == nil { + if b, err := os.ReadFile(filepath.Join(AYADIR, cmd+".html")); err == nil { return string(b), nil } @@ -90,7 +90,7 @@ // content by an empty line. Header can be either YAML or JSON. // If no empty newline is found - file is treated as content-only. func getVars(path string, globals Vars) (Vars, string, error) { - b, err := ioutil.ReadFile(path) + b, err := os.ReadFile(path) if err != nil { return nil, "", err } @@ -359,6 +359,12 @@ time.Sleep(1 * time.Second) } } +// Serve the public directory over HTTP +func servePubDir() { + rootdir := http.Dir(PUBDIR) + http.Handle("/", http.FileServer(rootdir)) + log.Fatal(http.ListenAndServe(":8000", nil)) +} func init() { // prepend .aya to $PATH, so plugins will be found before OS commands @@ -372,9 +378,10 @@ fmt.Printf("\n") fmt.Printf("Where is:\n") fmt.Printf("\tbuild\tGenerate site\n") + fmt.Printf("\tserve\tServe %v over HTTP\n", PUBDIR) + fmt.Printf("\tvar\tQuery variable(s) from a markdown file\n") + fmt.Printf("\tversion\tPrint program version and exit\n") fmt.Printf("\twatch\t(Re)generate site while looking for changes\n") - fmt.Printf("\tvar\tQuery a variable from a markdown file\n") - fmt.Printf("\tversion\tPrint version and exit\n") fmt.Printf("\n") fmt.Printf("Other commands may be dynamically added by plugins found in %v\n", AYADIR) os.Exit(0) @@ -397,8 +404,8 @@ } else { fmt.Println("ERROR: too many arguments") } - case "watch": - buildAll(true) + case "serve": + servePubDir() case "var": if len(args) == 0 { fmt.Println("var: filename expected") @@ -420,8 +427,10 @@ fmt.Println(strings.TrimSpace(s)) } case "version": - fmt.Printf("%v\n", aya.Version) + fmt.Printf("%v\n", aya.FullVersion()) os.Exit(0) + case "watch": + buildAll(true) default: if s, err := run(globals(), cmd, args...); err != nil { fmt.Println(err)