From 3cb7c82cf7c4e050148f69be23590a7fbe587a27 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 31 Mar 2026 10:11:18 +0000 Subject: Add static site builder: SQLite-backed MD→HTML pipeline MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - cmd/nebbet: CLI with build [--watch] and user add/passwd/delete/list - internal/builder: markdown→HTML, component injection via HTML comments, auto importmap from lib/, fsnotify watch with 150ms debounce - internal/db: meta.db (page index, tag queries) + search.db (FTS5) - internal/sqlitedrv: minimal CGO database/sql driver for system libsqlite3 - internal/auth: htpasswd-compatible bcrypt password file management - templates/base.html + admin.html, styles/main.css + admin.css - nginx.conf with auth_basic for /admin, clean URLs, gzip - nebbet.service systemd unit for watch daemon - Example content/index.md and components/site-greeting.js https://claude.ai/code/session_01HTc1BCBCiMTEB54XQP1Wz9 --- internal/builder/importmap.go | 58 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 internal/builder/importmap.go (limited to 'internal/builder/importmap.go') diff --git a/internal/builder/importmap.go b/internal/builder/importmap.go new file mode 100644 index 0000000..8445411 --- /dev/null +++ b/internal/builder/importmap.go @@ -0,0 +1,58 @@ +package builder + +import ( + "encoding/json" + "os" + "path/filepath" + "strings" +) + +// ImportMap represents a browser importmap. +type ImportMap struct { + Imports map[string]string `json:"imports"` +} + +// GenerateImportMap scans libDir for .js files and produces an importmap JSON string. +// +// Naming rules: +// - lib/chart.js → "chart" +// - lib/icons/index.js → "icons" +// - lib/utils/helpers.js → "utils/helpers" +func GenerateImportMap(libDir string) (string, error) { + imports := make(map[string]string) + + if _, err := os.Stat(libDir); os.IsNotExist(err) { + b, _ := json.MarshalIndent(ImportMap{Imports: imports}, "", " ") + return string(b), nil + } + + err := filepath.WalkDir(libDir, func(path string, d os.DirEntry, err error) error { + if err != nil || d.IsDir() || !strings.HasSuffix(path, ".js") { + return err + } + rel, _ := filepath.Rel(libDir, path) + rel = filepath.ToSlash(rel) + + dir := filepath.ToSlash(filepath.Dir(rel)) + base := strings.TrimSuffix(filepath.Base(rel), ".js") + + var importName string + switch { + case dir == ".": + importName = base + case base == "index": + importName = dir + default: + importName = dir + "/" + base + } + + imports[importName] = "/lib/" + rel + return nil + }) + if err != nil { + return "", err + } + + b, err := json.MarshalIndent(ImportMap{Imports: imports}, "", " ") + return string(b), err +} -- cgit v1.3