summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Manuel <nilslice@gmail.com>2017-01-02 13:54:28 -0800
committerSteve Manuel <nilslice@gmail.com>2017-01-02 13:54:28 -0800
commitaf3f7ada295115808c2407e1576ec703091c6c0a (patch)
treefc8dcb556d4a61bc44665895f0a01ff8f8d1460e
parentae201cf1af12132ed5aed3c180bcb785dee85621 (diff)
more code cleanup and adding content dir empty on build before copy
-rw-r--r--cmd/ponzu/options.go37
-rw-r--r--system/admin/handlers.go8
2 files changed, 34 insertions, 11 deletions
diff --git a/cmd/ponzu/options.go b/cmd/ponzu/options.go
index 1316a67..4d102c5 100644
--- a/cmd/ponzu/options.go
+++ b/cmd/ponzu/options.go
@@ -150,13 +150,6 @@ func vendorCorePackages(path string) error {
return err
}
- // // create a user content directory to be vendored
- // contentPath := filepath.Join(path, "content")
- // err = os.Mkdir(contentPath, os.ModeDir|os.ModePerm)
- // if err != nil {
- // return err
- // }
-
dirs := []string{"content", "management", "system"}
for _, dir := range dirs {
err = os.Rename(filepath.Join(path, dir), filepath.Join(vendorPath, dir))
@@ -247,6 +240,27 @@ func copyFilesWarnConflicts(srcDir, dstDir string, conflicts []string) error {
return nil
}
+func emptyDir(path string) error {
+ d, err := os.Open(path)
+ if err != nil {
+ return err
+ }
+ defer d.Close()
+
+ names, err := d.Readdirnames(-1)
+ if err != nil {
+ return err
+ }
+ for _, name := range names {
+ err = os.RemoveAll(filepath.Join(path, name))
+ if err != nil {
+ return err
+ }
+ }
+
+ return nil
+}
+
func buildPonzuServer(args []string) error {
pwd, err := os.Getwd()
if err != nil {
@@ -256,7 +270,10 @@ func buildPonzuServer(args []string) error {
// copy all ./content files to internal vendor directory
src := "content"
dst := filepath.Join("cmd", "ponzu", "vendor", "github.com", "ponzu-cms", "ponzu", "content")
-
+ err = emptyDir(dst)
+ if err != nil {
+ return err
+ }
err = copyFilesWarnConflicts(src, dst, []string{"doc.go"})
if err != nil {
return err
@@ -278,9 +295,7 @@ func buildPonzuServer(args []string) error {
p := filepath.Join(pwd, "cmd", "ponzu", file)
cmdBuildFilePaths = append(cmdBuildFilePaths, p)
}
- // mainPath := filepath.Join(pwd, "cmd", "ponzu", "main.go")
- // optsPath := filepath.Join(pwd, "cmd", "ponzu", "options.go")
- // genPath := filepath.Join(pwd, "cmd", "ponzu", "generate.go")
+
build := exec.Command(gocmd, append(buildOptions, cmdBuildFilePaths...)...)
build.Stderr = os.Stderr
build.Stdout = os.Stdout
diff --git a/system/admin/handlers.go b/system/admin/handlers.go
index efcb449..3d0cf16 100644
--- a/system/admin/handlers.go
+++ b/system/admin/handlers.go
@@ -1249,6 +1249,14 @@ func approveContentHandler(res http.ResponseWriter, req *http.Request) {
return
}
+ pendID := req.FormValue("id")
+ if pendID != "" {
+ err = db.DeleteContent(req.FormValue("type")+":"+pendID, req.Form)
+ if err != nil {
+ log.Println("Failed to remove content after approval:", err)
+ }
+ }
+
// redirect to the new approved content's editor
redir := req.URL.Scheme + req.URL.Host + strings.TrimSuffix(req.URL.Path, "/approve")
redir += fmt.Sprintf("?type=%s&id=%d", t, id)