Add serve function, update documentation accordingly
Signed-off-by: Izuru Yakumo <yakumo.izuru@chaotic.ninja> git-svn-id: file:///srv/svn/repo/aya/trunk@61 cec141ff-132a-4243-88a5-ce187bd62f94
This commit is contained in:
10
README.md
10
README.md
@@ -17,7 +17,7 @@ This crow tengu stands for 'the fastest one in Gensokyo' and yes this is also a
|
|||||||
|
|
||||||
Build it manually assuming you have Go installed:
|
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
|
## Ideology
|
||||||
|
|
||||||
@@ -66,10 +66,10 @@ for f in ./blog/*.md ; do
|
|||||||
echo $timestamp \
|
echo $timestamp \
|
||||||
"<item>" \
|
"<item>" \
|
||||||
"<title>$title</title>" \
|
"<title>$title</title>" \
|
||||||
"<link>http://ayaerge.com/$url</link>" \
|
"<link>http://zserge.com/$url</link>" \
|
||||||
"<description>$descr</description>" \
|
"<description>$descr</description>" \
|
||||||
"<pubDate>$(date --date @$timestamp -R)</pubDate>" \
|
"<pubDate>$(date --date @$timestamp -R)</pubDate>" \
|
||||||
"<guid>http://ayaerge.com/$url</guid>" \
|
"<guid>http://zserge.com/$url</guid>" \
|
||||||
"</item>"
|
"</item>"
|
||||||
fi
|
fi
|
||||||
done | sort -r -n | cut -d' ' -f2-
|
done | sort -r -n | cut -d' ' -f2-
|
||||||
@@ -93,12 +93,14 @@ content generation, or additional commands, like LESS to CSS conversion:
|
|||||||
|
|
||||||
`aya build <file>` re-builds one file and prints resulting content to stdout.
|
`aya build <file>` 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 <filename> [var1 var2...]` prints a list of variables defined in the
|
`aya var <filename> [var1 var2...]` prints a list of variables defined in the
|
||||||
header of a given markdown file, or the values of certain variables (even if
|
header of a given markdown file, or the values of certain variables (even if
|
||||||
it's an empty string).
|
it's an empty string).
|
||||||
|
|
||||||
|
`aya watch` rebuilds your site every time you modify any file.
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
The software is distributed under the MIT license.
|
The software is distributed under the MIT license.
|
||||||
|
|||||||
29
aya.1
29
aya.1
@@ -16,21 +16,22 @@ Does it need one?
|
|||||||
.It Fast (of course)
|
.It Fast (of course)
|
||||||
.El
|
.El
|
||||||
.Sh USAGE
|
.Sh USAGE
|
||||||
.Ss (Re-)build your site.
|
.Bl -tag
|
||||||
.Nm
|
.It build
|
||||||
.Cm build
|
(Re-)build a site or a file in particular
|
||||||
.Ss (Re-)build one file and prints resulting content to standard output.
|
.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
|
.Nm
|
||||||
.Cm build
|
was originally forked from prologic/zs by Izuru
|
||||||
.Ar <file>
|
out of disgust with the latest revision, so he
|
||||||
.Ss (Re-)build your site every time you modify any file.
|
used a earlier commit as a base, and then
|
||||||
.Nm
|
eventually reimplemented older features from
|
||||||
.Cm watch
|
zserge's original project.
|
||||||
.Ss Print a list of variables defined in the header of a given markdown file.
|
|
||||||
.Nm
|
|
||||||
.Cm var
|
|
||||||
.Ar <file>
|
|
||||||
.Ar <var1> <var2> ...
|
|
||||||
.Sh AUTHORS
|
.Sh AUTHORS
|
||||||
.Nm
|
.Nm
|
||||||
is maintained by Izuru Yakumo
|
is maintained by Izuru Yakumo
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@@ -59,7 +59,7 @@ func globals() Vars {
|
|||||||
// stderr is printed to aya stderr, command output is returned as a string.
|
// stderr is printed to aya stderr, command output is returned as a string.
|
||||||
func run(vars Vars, cmd string, args ...string) (string, error) {
|
func run(vars Vars, cmd string, args ...string) (string, error) {
|
||||||
// First check if partial exists (.html)
|
// 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
|
return string(b), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,7 +90,7 @@ func run(vars Vars, cmd string, args ...string) (string, error) {
|
|||||||
// content by an empty line. Header can be either YAML or JSON.
|
// content by an empty line. Header can be either YAML or JSON.
|
||||||
// If no empty newline is found - file is treated as content-only.
|
// If no empty newline is found - file is treated as content-only.
|
||||||
func getVars(path string, globals Vars) (Vars, string, error) {
|
func getVars(path string, globals Vars) (Vars, string, error) {
|
||||||
b, err := ioutil.ReadFile(path)
|
b, err := os.ReadFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, "", err
|
return nil, "", err
|
||||||
}
|
}
|
||||||
@@ -359,6 +359,12 @@ func buildAll(watch bool) {
|
|||||||
time.Sleep(1 * time.Second)
|
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() {
|
func init() {
|
||||||
// prepend .aya to $PATH, so plugins will be found before OS commands
|
// prepend .aya to $PATH, so plugins will be found before OS commands
|
||||||
@@ -372,9 +378,10 @@ func printUsage() {
|
|||||||
fmt.Printf("\n")
|
fmt.Printf("\n")
|
||||||
fmt.Printf("Where <command> is:\n")
|
fmt.Printf("Where <command> is:\n")
|
||||||
fmt.Printf("\tbuild\tGenerate site\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("\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("\n")
|
||||||
fmt.Printf("Other commands may be dynamically added by plugins found in %v\n", AYADIR)
|
fmt.Printf("Other commands may be dynamically added by plugins found in %v\n", AYADIR)
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
@@ -397,8 +404,8 @@ func main() {
|
|||||||
} else {
|
} else {
|
||||||
fmt.Println("ERROR: too many arguments")
|
fmt.Println("ERROR: too many arguments")
|
||||||
}
|
}
|
||||||
case "watch":
|
case "serve":
|
||||||
buildAll(true)
|
servePubDir()
|
||||||
case "var":
|
case "var":
|
||||||
if len(args) == 0 {
|
if len(args) == 0 {
|
||||||
fmt.Println("var: filename expected")
|
fmt.Println("var: filename expected")
|
||||||
@@ -420,8 +427,10 @@ func main() {
|
|||||||
fmt.Println(strings.TrimSpace(s))
|
fmt.Println(strings.TrimSpace(s))
|
||||||
}
|
}
|
||||||
case "version":
|
case "version":
|
||||||
fmt.Printf("%v\n", aya.Version)
|
fmt.Printf("%v\n", aya.FullVersion())
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
|
case "watch":
|
||||||
|
buildAll(true)
|
||||||
default:
|
default:
|
||||||
if s, err := run(globals(), cmd, args...); err != nil {
|
if s, err := run(globals(), cmd, args...); err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
|
|||||||
Reference in New Issue
Block a user