Simplify admin publishing pipeline
This commit is contained in:
parent
13e7e4026d
commit
9186801c7f
37 changed files with 750 additions and 3367 deletions
|
|
@ -46,6 +46,33 @@ func serveAdminFile(c *gin.Context, adminDir string) bool {
|
|||
return true
|
||||
}
|
||||
|
||||
func serveSiteFile(c *gin.Context, staticDir string) bool {
|
||||
if strings.TrimSpace(staticDir) == "" {
|
||||
return false
|
||||
}
|
||||
|
||||
requested := strings.TrimPrefix(c.Request.URL.Path, "/")
|
||||
if requested == "" {
|
||||
requested = "index.html"
|
||||
}
|
||||
cleaned := filepath.Clean(requested)
|
||||
if cleaned == "." || strings.HasPrefix(cleaned, "..") || filepath.IsAbs(cleaned) {
|
||||
return false
|
||||
}
|
||||
|
||||
path := filepath.Join(staticDir, cleaned)
|
||||
info, err := os.Stat(path)
|
||||
if err == nil && info.IsDir() {
|
||||
path = filepath.Join(path, "index.html")
|
||||
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