Ready to release 0.6.0
Signed-off-by: Izuru Yakumo <yakumo.izuru@chaotic.ninja> git-svn-id: file:///srv/svn/repo/aya/trunk@69 cec141ff-132a-4243-88a5-ce187bd62f94
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
// $TheSupernovaDuo: cmd/aya/main.go,v 0.5.x 2023/5/8 18:6:18 yakumo_izuru Exp $
|
||||
// $TheSupernovaDuo: cmd/aya/main.go,v 0.6.0 2023/9/13 07:50:00 yakumo_izuru Exp $
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -13,16 +13,16 @@ import (
|
||||
"text/template"
|
||||
"time"
|
||||
|
||||
"github.com/eknkc/amber"
|
||||
"github.com/russross/blackfriday/v2"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/yosssi/gcss"
|
||||
"gopkg.in/yaml.v2"
|
||||
"marisa.chaotic.ninja/aya"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/eknkc/amber"
|
||||
"github.com/yosssi/gcss"
|
||||
)
|
||||
|
||||
const (
|
||||
AYADIR = ".aya"
|
||||
AYADIR = ".aya"
|
||||
PUBDIR = ".pub"
|
||||
)
|
||||
|
||||
@@ -172,7 +172,7 @@ func render(s string, vars Vars) (string, error) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
// Renders markdown with the given layout into html expanding all the macros
|
||||
@@ -186,7 +186,7 @@ func buildMarkdown(path string, w io.Writer, vars Vars) error {
|
||||
return err
|
||||
}
|
||||
v["content"] = string(blackfriday.Run([]byte(content),
|
||||
blackfriday.WithExtensions(blackfriday.CommonExtensions|blackfriday.AutoHeadingIDs),
|
||||
blackfriday.WithExtensions(blackfriday.CommonExtensions|blackfriday.AutoHeadingIDs|blackfriday.Strikethrough|blackfriday.Footnotes),
|
||||
))
|
||||
if w == nil {
|
||||
out, err := os.Create(filepath.Join(PUBDIR, renameExt(path, "", ".html")))
|
||||
@@ -260,6 +260,7 @@ func buildAmber(path string, w io.Writer, vars Vars) error {
|
||||
_, err = io.WriteString(w, body)
|
||||
return err
|
||||
}
|
||||
|
||||
// Compiles .gcss into .css
|
||||
func buildGCSS(path string, w io.Writer) error {
|
||||
f, err := os.Open(path)
|
||||
@@ -299,6 +300,7 @@ func buildRaw(path string, w io.Writer) error {
|
||||
_, err = io.Copy(w, in)
|
||||
return err
|
||||
}
|
||||
|
||||
// This function passes the files to build to their corresponding functions
|
||||
func build(path string, w io.Writer, vars Vars) error {
|
||||
ext := filepath.Ext(path)
|
||||
@@ -359,13 +361,13 @@ func buildAll(watch bool) {
|
||||
time.Sleep(1 * time.Second)
|
||||
}
|
||||
}
|
||||
// Serve the public directory over HTTP
|
||||
func servePubDir() {
|
||||
rootdir := http.Dir(PUBDIR)
|
||||
http.Handle("/", http.FileServer(rootdir))
|
||||
log.Printf("Serving %v at port 8000, see http://localhost:8000", rootdir)
|
||||
|
||||
// Serve the public directory over HTTP and watch for changes
|
||||
func serve() {
|
||||
http.Handle("/", http.FileServer(http.Dir(PUBDIR)))
|
||||
log.Fatal(http.ListenAndServe(":8000", nil))
|
||||
}
|
||||
|
||||
// Initialize the environment
|
||||
func init() {
|
||||
// prepend .aya to $PATH, so plugins will be found before OS commands
|
||||
@@ -373,6 +375,7 @@ func init() {
|
||||
p = os.Getenv("PWD") + "/" + AYADIR + ":" + p
|
||||
os.Setenv("PATH", p)
|
||||
}
|
||||
|
||||
// Print usage notes
|
||||
func printUsage() {
|
||||
fmt.Printf("%v <command> [args]\n", os.Args[0])
|
||||
@@ -380,10 +383,9 @@ func printUsage() {
|
||||
fmt.Printf("Where <command> is:\n")
|
||||
fmt.Printf("\tbuild\tGenerate site\n")
|
||||
fmt.Printf("\tclean\tRemoves the generated site directory\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 (it also serves on HTTP)\n")
|
||||
fmt.Printf("\n")
|
||||
fmt.Printf("Other commands may be dynamically added by plugins found in %v\n", AYADIR)
|
||||
os.Exit(0)
|
||||
@@ -409,8 +411,8 @@ func main() {
|
||||
case "clean":
|
||||
log.Println("Removing generated site directory")
|
||||
os.RemoveAll(PUBDIR)
|
||||
case "serve":
|
||||
servePubDir()
|
||||
case "help":
|
||||
printUsage()
|
||||
case "var":
|
||||
if len(args) == 0 {
|
||||
log.Fatal("var: filename expected")
|
||||
@@ -436,6 +438,7 @@ func main() {
|
||||
os.Exit(0)
|
||||
case "watch":
|
||||
buildAll(true)
|
||||
serve()
|
||||
default:
|
||||
if s, err := run(globals(), cmd, args...); err != nil {
|
||||
log.Println(err)
|
||||
|
||||
Reference in New Issue
Block a user