diff --git a/archetype/adapter.go b/archetype/adapter.go index c9aff16..7b43da8 100644 --- a/archetype/adapter.go +++ b/archetype/adapter.go @@ -21,11 +21,13 @@ type ConfigOption struct { Type string } +type BuildOption ConfigOption + type Adapter interface { Init(cfg *Config) Name() string EditableSlugs() bool - BuildOptions() []string + BuildOptions() []BuildOption GetConfig() map[ConfigOption]string SetConfig(map[ConfigOption]string) error ListPages() map[string]string @@ -35,5 +37,5 @@ type Adapter interface { CreatePage(slug, title, content string) error SavePage(oldSlug, newSlug, title, content string) error DeletePage(slug string) error - Build(buildOptions map[string][]string) BuildStatus + Build(buildOptions map[BuildOption]string) BuildStatus } diff --git a/archetype/eureka.go b/archetype/eureka.go index e6b1491..a3db885 100644 --- a/archetype/eureka.go +++ b/archetype/eureka.go @@ -40,8 +40,21 @@ func (self *EurekaAdapter) EditableSlugs() bool { return false } -func (self *EurekaAdapter) BuildOptions() []string { - return []string{"twtxt"} +func (self *EurekaAdapter) BuildOptions() []BuildOption { + return []BuildOption{ + BuildOption{ + Name: "twtxt", + Type: "string", + }, + BuildOption{ + Name: "remove newest twtxt", + Type: "bool", + }, + BuildOption{ + Name: "clear thumbnail cache", + Type: "bool", + }, + } } func (self *EurekaAdapter) GetConfig() map[ConfigOption]string { @@ -249,8 +262,11 @@ func (self *EurekaAdapter) DeletePage(slug string) error { return os.Remove(filepath.Join(self.Root, "inc", slug)) } -func (self *EurekaAdapter) Build(buildOptions map[string][]string) BuildStatus { - twtxt := strings.Join(buildOptions["twtxt"], " ") +func (self *EurekaAdapter) Build(buildOptions map[BuildOption]string) BuildStatus { + twtxt := buildOptions[BuildOption{ + Name: "twtxt", + Type: "string", + }] cmdArgs := []string{} if twtxt != "" { cmdArgs = append(cmdArgs, "-t") diff --git a/lfo/middleware.go b/lfo/middleware.go index b96fa8a..f7fd93b 100644 --- a/lfo/middleware.go +++ b/lfo/middleware.go @@ -55,7 +55,7 @@ func SanitizeFormMap(next http.Handler) http.Handler { return http.HandlerFunc(handlerFunc) } -func FormMapToAdapterConfig(next http.Handler, adapter core.Adapter) http.Handler { +func FormMapToAdapterConfig(next http.Handler) http.Handler { handlerFunc := func(w http.ResponseWriter, req *http.Request) { cfg := make(map[core.ConfigOption]string) for k, arr := range req.PostForm { @@ -75,6 +75,26 @@ func FormMapToAdapterConfig(next http.Handler, adapter core.Adapter) http.Handle return http.HandlerFunc(handlerFunc) } +func FormMapToBuildOptions(next http.Handler) http.Handler { + handlerFunc := func(w http.ResponseWriter, req *http.Request) { + options := make(map[core.BuildOption]string) + for k, arr := range req.PostForm { + v := strings.Join(arr, "") + optNameAndType := strings.Split(k, ":") + optName := optNameAndType[0] + optType := optNameAndType[1] + options[core.BuildOption{ + Name: optName, + Type: optType, + }] = v + } + *req = *req.WithContext(context.WithValue(req.Context(), "build-options", options)) + next.ServeHTTP(w, req) + } + + return http.HandlerFunc(handlerFunc) +} + func PrepareForUpload(next http.Handler, fileManager core.FileManager) http.Handler { handlerFunc := func(w http.ResponseWriter, req *http.Request) { req.ParseMultipartForm(fileManager.MaxUploadMB() << 20) diff --git a/nirvash.go b/nirvash.go index f7c90ea..f173411 100644 --- a/nirvash.go +++ b/nirvash.go @@ -148,12 +148,13 @@ func main() { Defend( Protected( SanitizeFormMap( - WithAdapter( - renderer.Template( - pathConcat(templateRoot, "build_run.html"), - pathConcat(templateRoot, "header.html"), - pathConcat(templateRoot, "footer.html")), - cfg.Adapter)), + FormMapToBuildOptions( + WithAdapter( + renderer.Template( + pathConcat(templateRoot, "build_run.html"), + pathConcat(templateRoot, "header.html"), + pathConcat(templateRoot, "footer.html")), + cfg.Adapter))), http.MethodGet, udb, "/login"), @@ -201,8 +202,7 @@ func main() { pathConcat(templateRoot, "config_set.html"), pathConcat(templateRoot, "header.html"), pathConcat(templateRoot, "footer.html")), - cfg.Adapter), - cfg.Adapter)), + cfg.Adapter))), http.MethodGet, udb, "/login"), diff --git a/templates/build.html b/templates/build.html index 364b68c..6523d65 100644 --- a/templates/build.html +++ b/templates/build.html @@ -7,16 +7,35 @@
-
Build Options {{ if $buildOpts }} - {{ range $optName := $buildOpts }} - +
Build Options + {{ range $opt := $buildOpts }} + {{ if eq ($opt).Type "bool" }} +
+ {{ end }} + {{ end }} + {{ range $opt := $buildOpts }} + {{ if eq ($opt).Type "int" }} +
+ {{ end }} + {{ end }} + {{ range $opt := $buildOpts }} + {{ if eq ($opt).Type "float" }} +
+ {{ end }} + {{ end }} + {{ range $opt := $buildOpts }} + {{ if eq ($opt).Type "string" }} +
+ {{ end }} + {{ end }} + {{ range $opt := $buildOpts }} + {{ if eq ($opt).Type "multilinestring" }} +
+ {{ end }} {{ end }} -{{ else }} -There are no build options for this adapter. -{{ end }}
- +{{ end }} diff --git a/templates/build_run.html b/templates/build_run.html index e0c7e61..a94a85d 100644 --- a/templates/build_run.html +++ b/templates/build_run.html @@ -1,14 +1,18 @@ -{{ $buildOpts := .PostForm }} +{{ $buildOpts := (.Context).Value "build-options" }} {{ $status := ((.Context).Value "adapter").Build $buildOpts }} {{ template "header" . }} {{ if ne ($status).Success true }} +

Build Error

{{($status).Message}}
+ {{ else }} +

Build Successful

{{($status).Message}}
+ {{ end }} {{ template "footer" . }} \ No newline at end of file diff --git a/templates/cms_create.html b/templates/cms_create.html index bcb668c..8b8ea7c 100644 --- a/templates/cms_create.html +++ b/templates/cms_create.html @@ -6,11 +6,15 @@ {{ template "header" . }} {{ if $createErr }} +

Page Creation Error

- There was an error creating the page: {{ ($createErr).Error }} + {{ ($createErr).Error }} + {{ else }} +

Page Created

Page '{{ $title }}' created successfully + {{ end }} {{ template "footer" . }} \ No newline at end of file diff --git a/templates/cms_edit.html b/templates/cms_edit.html index 10c6de3..8eb4a07 100644 --- a/templates/cms_edit.html +++ b/templates/cms_edit.html @@ -7,9 +7,10 @@ {{ template "header" . }} {{ if ($page).Error }} -

Page Error

- + +

Page Error

{{($page).Error}} + {{ else }}

Edit Page

diff --git a/templates/cms_save.html b/templates/cms_save.html index fc2e68a..682ea10 100644 --- a/templates/cms_save.html +++ b/templates/cms_save.html @@ -7,11 +7,15 @@ {{ template "header" . }} {{ if $saveErr }} +

Page Save Error

- There was an error saving the page: {{ ($saveErr).Error }} + {{ ($saveErr).Error }} + {{ else }} +

Page Saved

Page '{{ $title }}' saved successfully + {{ end }} {{ template "footer" . }} \ No newline at end of file diff --git a/templates/config.html b/templates/config.html index e87ae4a..eac7d6b 100644 --- a/templates/config.html +++ b/templates/config.html @@ -7,6 +7,11 @@
+ {{ range $opt, $val := $config }} + {{ if eq ($opt).Type "bool" }} +
+ {{ end }} + {{ end }} {{ range $opt, $val := $config }} {{ if eq ($opt).Type "int" }}
diff --git a/templates/config_set.html b/templates/config_set.html index 5652f04..24a624a 100644 --- a/templates/config_set.html +++ b/templates/config_set.html @@ -4,11 +4,15 @@ {{ template "header" . }} {{ if $cfgError }} +

Configuration Error

{{($cfgError).Error}} + {{ else }} +

Configuration Saved

The adapter configuration has been saved + {{ end }} {{ template "footer" . }} \ No newline at end of file diff --git a/templates/delete.html b/templates/delete.html index e5aad23..7300730 100644 --- a/templates/delete.html +++ b/templates/delete.html @@ -4,11 +4,15 @@ {{ template "header" . }} {{ if $deleteErr }} +

Deletion Error

- There was an error deleting the page: {{ ($deleteErr).Error }} + {{ ($deleteErr).Error }} + {{ else }} +

Page Deleted

Page at '{{ $slug }}' was deleted + {{ end }} {{ template "footer" . }} \ No newline at end of file diff --git a/templates/file_delete.html b/templates/file_delete.html index a14d999..aeb5fdf 100644 --- a/templates/file_delete.html +++ b/templates/file_delete.html @@ -4,11 +4,15 @@ {{ template "header" . }} {{ if $deleteErr }} +

File Deletion Error

- There was an error deleting the file: {{ ($deleteErr).Error }} + {{ ($deleteErr).Error }} + {{ else }} +

File Deleted

- Static file '{{ $slug }}' was deleted + '{{ $slug }}' was deleted successfully + {{ end }} {{ template "footer" . }} \ No newline at end of file diff --git a/templates/file_list.html b/templates/file_list.html index b70f034..b29d4cf 100644 --- a/templates/file_list.html +++ b/templates/file_list.html @@ -5,9 +5,10 @@ {{ if ($fileList).Error }} -

File Listing Error

+

File Listing Error

{{($fileList).Error}} + {{ else }}

Files: {{($fileList).Root}}

diff --git a/templates/file_mkdir.html b/templates/file_mkdir.html index e3758e4..cc28d57 100644 --- a/templates/file_mkdir.html +++ b/templates/file_mkdir.html @@ -1,8 +1,16 @@ {{ $slug := ((.Context).Value "params").Slug }} +{{ $fileData := ((.Context).Value "file-manager").GetFileData $slug }} {{ $csrfToken := (.Context).Value "csrfToken" }} {{ template "header" . }} +{{ if ($fileData).Error }} + +

Error

+{{($fileData).Error}} + +{{ else }} +

Directory Creation

@@ -15,4 +23,6 @@
+{{ end }} + {{ template "footer" . }} diff --git a/templates/file_mkdir_process.html b/templates/file_mkdir_process.html index c891cca..dbd9283 100644 --- a/templates/file_mkdir_process.html +++ b/templates/file_mkdir_process.html @@ -5,11 +5,15 @@ {{ template "header" . }} {{ if $mkdirError }} -

Directory Creation Error

- {{($mkdirError).Error}} + +

Directory Creation Error

+{{($mkdirError).Error}} + {{ else }} -

Directory Created

- The directory has been created successfully + +

Directory Created

+The directory has been created successfully + {{ end }} {{ template "footer" . }} \ No newline at end of file diff --git a/templates/file_move.html b/templates/file_move.html index 1e8b747..7fc39b2 100644 --- a/templates/file_move.html +++ b/templates/file_move.html @@ -15,10 +15,10 @@ {{ else if ($fileData).Error }}

File Listing Error

- {{($fileData).Error}} {{ else }} +

Moving {{($fileData).Name}}: {{($fileList).Root}}

diff --git a/templates/file_move_process.html b/templates/file_move_process.html index 6b6ccba..e8725a7 100644 --- a/templates/file_move_process.html +++ b/templates/file_move_process.html @@ -8,13 +8,11 @@ {{ if $moveError }}

File Move/Rename Error

- {{$moveError}} {{ else }}

File Move/Rename Success

- File moved from /{{$slug}} to {{$dest}}{{$name}} {{ end }} diff --git a/templates/file_upload.html b/templates/file_upload.html index ec800ce..090fc39 100644 --- a/templates/file_upload.html +++ b/templates/file_upload.html @@ -5,12 +5,11 @@ {{ template "header" . }} {{ if ($fileData).Error }} -

Error

+

Filesystem Error

{{($fileData).Error}} {{ else }} -

File Upload

diff --git a/templates/file_upload_process.html b/templates/file_upload_process.html index 7f4ec24..3b7a649 100644 --- a/templates/file_upload_process.html +++ b/templates/file_upload_process.html @@ -4,11 +4,15 @@ {{ template "header" . }} {{ if $uploadError }} -

Upload Error

- {{($uploadError).Error}} + +

Upload Error

+{{($uploadError).Error}} + {{ else }} -

Upload Successful

- The file has been uploaded successfuly + +

Upload Successful

+The file has been uploaded successfuly + {{ end }} {{ template "footer" . }} \ No newline at end of file