pre refactor

This commit is contained in:
2025-11-24 15:48:46 -05:00
parent 84b4487d92
commit e2d31aa734
7 changed files with 71 additions and 6 deletions

1
TODO
View File

@@ -2,3 +2,4 @@ Make this static ( cannot find core.std everywhere )
Add hotreloading Add hotreloading
Add an interval element Add an interval element
Compare bin version to Fes.toml Compare bin version to Fes.toml
Add ways to interact with left and right

View File

@@ -3,7 +3,7 @@ local std = require("core.std")
local M = {} local M = {}
M.__index = M M.__index = M
function M.site_builder(header, footer) function M.fes(header, footer)
local config = {} local config = {}
local site_config = {} local site_config = {}
@@ -119,6 +119,7 @@ a:hover{text-decoration:underline}
.muted{color:#9aa6b1} .muted{color:#9aa6b1}
.lead{font-size:15px;margin-top:8px} .lead{font-size:15px;margin-top:8px}
.callout{display:block;margin:10px 0}
.small{font-size:13px;color:#9aa6b1;margin-top:6px} .small{font-size:13px;color:#9aa6b1;margin-top:6px}
.highlight{font-weight:700;color:#cde7ff} .highlight{font-weight:700;color:#cde7ff}

19
core/console.lua Normal file
View File

@@ -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

View File

@@ -32,6 +32,10 @@ function M.muted(str)
return '<div class="muted">' .. str .. '</div>' return '<div class="muted">' .. str .. '</div>'
end end
function M.callout(str)
return '<div class="callout">' .. str .. '</div>'
end
function M.h1(str) function M.h1(str)
return "<h1>" .. (str or "") .. "</h1>" return "<h1>" .. (str or "") .. "</h1>"
end end
@@ -210,4 +214,8 @@ function M.copyright()
return "&#169;" return "&#169;"
end end
function M.highlight(str)
return '<span class="highlight">' .. str .. "</span>"
end
return M return M

16
main.go
View File

@@ -11,6 +11,7 @@ import (
"path/filepath" "path/filepath"
"regexp" "regexp"
"strings" "strings"
"time"
"github.com/gomarkdown/markdown" "github.com/gomarkdown/markdown"
"github.com/gomarkdown/markdown/html" "github.com/gomarkdown/markdown/html"
@@ -21,11 +22,16 @@ import (
//go:embed core/builtin.lua //go:embed core/builtin.lua
var builtinLua string var builtinLua string
//go:embed core/markdown.lua //go:embed core/markdown.lua
var markdownLua string var markdownLua string
//go:embed core/std.lua //go:embed core/std.lua
var stdLua string var stdLua string
//go:embed core/console.lua
var consoleLua string
const version = "1.0.0" const version = "1.0.0"
type MyConfig struct { type MyConfig struct {
@@ -58,6 +64,14 @@ func loadLua(luaDir string, entry string, cfg *MyConfig) (string, error) {
L := lua.NewState() L := lua.NewState()
defer L.Close() 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 { L.PreloadModule("fes", func(L *lua.LState) int {
mod := L.NewTable() mod := L.NewTable()
@@ -65,6 +79,7 @@ func loadLua(luaDir string, entry string, cfg *MyConfig) (string, error) {
"builtin": builtinLua, "builtin": builtinLua,
"markdown": markdownLua, "markdown": markdownLua,
"std": stdLua, "std": stdLua,
"console": consoleLua,
} }
for modName, luaCode := range coreModules { for modName, luaCode := range coreModules {
@@ -244,6 +259,7 @@ func startServer(dir string) error {
for route, luaPath := range routes { for route, luaPath := range routes {
func(rt string, lp string) { func(rt string, lp string) {
http.HandleFunc(rt, func(w http.ResponseWriter, r *http.Request) { 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) data, err := loadLua(dir, lp, &cfg)
if err != nil { if err != nil {
http.Error(w, fmt.Sprintf("Error loading page: %v", err), http.StatusInternalServerError) http.Error(w, fmt.Sprintf("Error loading page: %v", err), http.StatusInternalServerError)

9
test/Fes.toml Normal file
View File

@@ -0,0 +1,9 @@
[site]
name = "test"
version = "0.0.1"
authors = ["vx-clutch"]
[fes]
version = "1.0.0"
CUSTOM_CSS =

11
test/www/index.lua Normal file
View File

@@ -0,0 +1,11 @@
local fes = require("fes")
local site = fes()
site:h1("<h1>")
site:h2("<h2>")
site:h3("<h3>")
site:h4("<h4>")
site:h5("<h5>")
site:h6("<h6>")
return site