feat: add admin publishing workflow and yar theme
Add Go/Postgres admin APIs, Angular admin UI, manual build flow, asset uploads, markdown import/export, configurable slug generation, and the Yar reading theme. Exclude local docs and generated development artifacts from version control.
This commit is contained in:
parent
b78f4b39c9
commit
f0b50d13ea
121 changed files with 27139 additions and 550 deletions
51
backend/internal/admin/static.go
Normal file
51
backend/internal/admin/static.go
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
package admin
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
//go:embed web/*
|
||||
var adminWeb embed.FS
|
||||
|
||||
func adminIndex(adminDir string) ([]byte, error) {
|
||||
if strings.TrimSpace(adminDir) != "" {
|
||||
path := filepath.Join(adminDir, "index.html")
|
||||
if page, err := os.ReadFile(path); err == nil {
|
||||
return rewriteAdminBase(page), nil
|
||||
}
|
||||
}
|
||||
return adminWeb.ReadFile("web/index.html")
|
||||
}
|
||||
|
||||
func serveAdminFile(c *gin.Context, adminDir string) bool {
|
||||
if strings.TrimSpace(adminDir) == "" {
|
||||
return false
|
||||
}
|
||||
|
||||
requested := strings.TrimPrefix(c.Param("filepath"), "/")
|
||||
if requested == "" {
|
||||
return false
|
||||
}
|
||||
cleaned := filepath.Clean(requested)
|
||||
if cleaned == "." || strings.HasPrefix(cleaned, "..") {
|
||||
return false
|
||||
}
|
||||
|
||||
path := filepath.Join(adminDir, cleaned)
|
||||
info, err := os.Stat(path)
|
||||
if err != nil || info.IsDir() {
|
||||
return false
|
||||
}
|
||||
http.ServeFile(c.Writer, c.Request, path)
|
||||
return true
|
||||
}
|
||||
|
||||
func rewriteAdminBase(page []byte) []byte {
|
||||
return []byte(strings.Replace(string(page), `<base href="/">`, `<base href="/admin/">`, 1))
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue