diff --git a/TODO b/TODO index 54f6186..a1372fd 100644 --- a/TODO +++ b/TODO @@ -2,3 +2,4 @@ Make this static ( cannot find core.std everywhere ) Add hotreloading Add an interval element Compare bin version to Fes.toml +Add ways to interact with left and right diff --git a/core/builtin.lua b/core/builtin.lua index 0fa4440..38dd63f 100644 --- a/core/builtin.lua +++ b/core/builtin.lua @@ -3,7 +3,7 @@ local std = require("core.std") local M = {} M.__index = M -function M.site_builder(header, footer) +function M.fes(header, footer) local config = {} local site_config = {} @@ -119,6 +119,7 @@ a:hover{text-decoration:underline} .muted{color:#9aa6b1} .lead{font-size:15px;margin-top:8px} +.callout{display:block;margin:10px 0} .small{font-size:13px;color:#9aa6b1;margin-top:6px} .highlight{font-weight:700;color:#cde7ff} diff --git a/core/console.lua b/core/console.lua new file mode 100644 index 0000000..992dceb --- /dev/null +++ b/core/console.lua @@ -0,0 +1,19 @@ +local M = {} + +function M.log(fmt, ...) + print(string.format("[%12f] ", os.clock()) .. string.format(fmt, ...)) +end + +function M.info(fmt, ...) + print("INFO: " .. string.format(fmt, ...)) +end + +function M.warn(fmt, ...) + print("WARN: " .. string.format(fmt, ...)) +end + +function M.error(fmt, ...) + print("ERROR: " .. string.format(fmt, ...)) +end + +return M diff --git a/core/std.lua b/core/std.lua index 36df1f8..3b4ad45 100644 --- a/core/std.lua +++ b/core/std.lua @@ -32,6 +32,10 @@ function M.muted(str) return '
' .. str .. '
' end +function M.callout(str) + return '
' .. str .. '
' +end + function M.h1(str) return "

" .. (str or "") .. "

" end @@ -210,4 +214,8 @@ function M.copyright() return "©" end +function M.highlight(str) + return '' .. str .. "" +end + return M diff --git a/main.go b/main.go index 9a3f13b..11e6dda 100644 --- a/main.go +++ b/main.go @@ -11,6 +11,7 @@ import ( "path/filepath" "regexp" "strings" + "time" "github.com/gomarkdown/markdown" "github.com/gomarkdown/markdown/html" @@ -21,11 +22,16 @@ import ( //go:embed core/builtin.lua var builtinLua string + //go:embed core/markdown.lua var markdownLua string + //go:embed core/std.lua var stdLua string +//go:embed core/console.lua +var consoleLua string + const version = "1.0.0" type MyConfig struct { @@ -58,15 +64,24 @@ func loadLua(luaDir string, entry string, cfg *MyConfig) (string, error) { L := lua.NewState() defer L.Close() + L.PreloadModule("core.std", func(L *lua.LState) int { + if err := L.DoString(stdLua); err != nil { + panic(err) + } + L.Push(L.Get(-1)) + return 1 + }) + L.PreloadModule("fes", func(L *lua.LState) int { mod := L.NewTable() - + coreModules := map[string]string{ "builtin": builtinLua, "markdown": markdownLua, "std": stdLua, + "console": consoleLua, } - + for modName, luaCode := range coreModules { if err := L.DoString(luaCode); err != nil { fmt.Println("error loading", modName, ":", err) @@ -220,7 +235,7 @@ func startServer(dir string) error { } wwwDir := filepath.Join(dir, "www") - + entries, err := os.ReadDir(wwwDir) if err != nil { return fmt.Errorf("failed to read www directory: %w", err) @@ -231,7 +246,7 @@ func startServer(dir string) error { if !entry.IsDir() && strings.HasSuffix(entry.Name(), ".lua") { baseName := strings.TrimSuffix(entry.Name(), ".lua") luaPath := filepath.Join(wwwDir, entry.Name()) - + if baseName == "index" { routes["/"] = luaPath routes["/index"] = luaPath @@ -244,6 +259,7 @@ func startServer(dir string) error { for route, luaPath := range routes { func(rt string, lp string) { http.HandleFunc(rt, func(w http.ResponseWriter, r *http.Request) { + fmt.Printf("[%s] LOAD /%s\n", time.Now().Format(time.RFC1123), lp) data, err := loadLua(dir, lp, &cfg) if err != nil { http.Error(w, fmt.Sprintf("Error loading page: %v", err), http.StatusInternalServerError) @@ -255,7 +271,7 @@ func startServer(dir string) error { } fmt.Printf("Server is running on http://localhost:%d\n", *port) - + return http.ListenAndServe(fmt.Sprintf(":%d", *port), nil) } diff --git a/test/Fes.toml b/test/Fes.toml new file mode 100644 index 0000000..3698755 --- /dev/null +++ b/test/Fes.toml @@ -0,0 +1,9 @@ +[site] + +name = "test" +version = "0.0.1" +authors = ["vx-clutch"] + +[fes] +version = "1.0.0" +CUSTOM_CSS = diff --git a/test/www/index.lua b/test/www/index.lua new file mode 100644 index 0000000..4b8cfb1 --- /dev/null +++ b/test/www/index.lua @@ -0,0 +1,11 @@ +local fes = require("fes") +local site = fes() + +site:h1("

") +site:h2("

") +site:h3("

") +site:h4("

") +site:h5("

") +site:h6("
") + +return site