Changeset 61 in code


Ignore:
Timestamp:
Apr 21, 2023, 11:06:28 PM (2 years ago)
Author:
Izuru Yakumo
Message:

Add serve function, update documentation accordingly

Signed-off-by: Izuru Yakumo <yakumo.izuru@…>

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/README.md

    r56 r61  
    1818Build it manually assuming you have Go installed:
    1919
    20         $ go install marisa.chaotic.ninja/aya@latest
     20        $ go install marisa.chaotic.ninja/aya/cmd/aya@latest
    2121
    2222## Ideology
     
    6767                        "<item>" \
    6868                        "<title>$title</title>" \
    69                         "<link>http://ayaerge.com/$url</link>" \
     69                        "<link>http://zserge.com/$url</link>" \
    7070                        "<description>$descr</description>" \
    7171                        "<pubDate>$(date --date @$timestamp -R)</pubDate>" \
    72                         "<guid>http://ayaerge.com/$url</guid>" \
     72                        "<guid>http://zserge.com/$url</guid>" \
    7373                "</item>"
    7474        fi
     
    9494`aya build <file>` re-builds one file and prints resulting content to stdout.
    9595
    96 `aya watch` rebuilds your site every time you modify any file.
     96`aya serve` serves your site over HTTP.
    9797
    9898`aya var <filename> [var1 var2...]` prints a list of variables defined in the
     
    100100it's an empty string).
    101101
     102`aya watch` rebuilds your site every time you modify any file.
     103
    102104## License
    103105
  • trunk/aya.1

    r56 r61  
    1717.El
    1818.Sh USAGE
    19 .Ss (Re-)build your site.
    20 .Nm
    21 .Cm build
    22 .Ss (Re-)build one file and prints resulting content to standard output.
     19.Bl -tag
     20.It build
     21(Re-)build a site or a file in particular
     22.It serve
     23Serve generated site over HTTP
     24.It var
     25Print a list of variables defined in a given markdown file.
     26.It watch
     27(Re-)build a site if any file changed
     28.Sh HISTORY
    2329.Nm
    24 .Cm build
    25 .Ar <file>
    26 .Ss (Re-)build your site every time you modify any file.
    27 .Nm
    28 .Cm watch
    29 .Ss Print a list of variables defined in the header of a given markdown file.
    30 .Nm
    31 .Cm var
    32 .Ar <file>
    33 .Ar <var1> <var2> ...
     30was originally forked from prologic/zs by Izuru
     31out of disgust with the latest revision, so he
     32used a earlier commit as a base, and then
     33eventually reimplemented older features from
     34zserge's original project.
    3435.Sh AUTHORS
    3536.Nm
  • trunk/cmd/aya/main.go

    r60 r61  
    55        "fmt"
    66        "io"
    7         "io/ioutil"
     7        "net/http"
    88        "os"
    99        "os/exec"
     
    6060func run(vars Vars, cmd string, args ...string) (string, error) {
    6161        // 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 {
    6363                return string(b), nil
    6464        }
     
    9191// If no empty newline is found - file is treated as content-only.
    9292func getVars(path string, globals Vars) (Vars, string, error) {
    93         b, err := ioutil.ReadFile(path)
     93        b, err := os.ReadFile(path)
    9494        if err != nil {
    9595                return nil, "", err
     
    360360        }
    361361}
     362// Serve the public directory over HTTP
     363func servePubDir() {
     364        rootdir := http.Dir(PUBDIR)
     365        http.Handle("/", http.FileServer(rootdir))
     366        log.Fatal(http.ListenAndServe(":8000", nil))
     367}
    362368
    363369func init() {
     
    373379        fmt.Printf("Where <command> is:\n")
    374380        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")
    375384        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")
    378385        fmt.Printf("\n")
    379386        fmt.Printf("Other commands may be dynamically added by plugins found in %v\n", AYADIR)
     
    398405                        fmt.Println("ERROR: too many arguments")
    399406                }
    400         case "watch":
    401                 buildAll(true)
     407        case "serve":
     408                servePubDir()
    402409        case "var":
    403410                if len(args) == 0 {
     
    421428                }
    422429        case "version":
    423                 fmt.Printf("%v\n", aya.Version)
     430                fmt.Printf("%v\n", aya.FullVersion())
    424431                os.Exit(0)
     432        case "watch":
     433                buildAll(true)
    425434        default:
    426435                if s, err := run(globals(), cmd, args...); err != nil {
Note: See TracChangeset for help on using the changeset viewer.