diff options
| -rw-r--r-- | README.md | 2 | ||||
| -rw-r--r-- | main.go | 19 |
2 files changed, 18 insertions, 3 deletions
@@ -22,6 +22,8 @@ Some facts (will be more clear when you read the whole readme): - All files in `static` folder will be moved to the root of `public` folder. - When you provide `url` in your markdown files, this will create these files in the root of `public` folder. No nesting allowed. +- Comes with a small embedded HTTP server you can invoke with `jbmafo --server` + which will server contents from `public` folder. Good for testing stuff. ## Install @@ -5,6 +5,7 @@ import ( "fmt" "html/template" "log" + "net/http" "os" "path" "path/filepath" @@ -91,6 +92,13 @@ func cleanHTMLTags(htmlString string) string { return cleanString } +func simpleServer(projectRoot string) { + fs := http.FileServer(http.Dir(path.Join(projectRoot, "public"))) + http.Handle("/", fs) + log.Println("Server started on http://localhost:6969") + log.Fatal(http.ListenAndServe(":6969", nil)) +} + func initializeProject(projectRoot string) { log.Println("Initializing new project") @@ -353,13 +361,14 @@ func main() { } var args struct { - Init bool `arg:"-i,--init" help:"initialize new project"` - Build bool `arg:"-b,--build" help:"build the website"` + Init bool `arg:"-i,--init" help:"initialize new project"` + Build bool `arg:"-b,--build" help:"build the website"` + Server bool `arg:"-s,--server" help:"simple embedded HTTP server"` } arg.MustParse(&args) - if !args.Init && !args.Build { + if !args.Init && !args.Build && !args.Server { fmt.Println("No arguments provided. Try using `jbmafp --help`") os.Exit(0) } @@ -371,4 +380,8 @@ func main() { if args.Build { buildProject(projectRoot) } + + if args.Server { + simpleServer(projectRoot) + } } |
