mirror of
https://github.com/writeas/htmlhouse
synced 2025-07-18 21:08:16 +00:00
Allow disabling publishing
Set ALLOW_PUBLISH=false environment variable to disable it.
This commit is contained in:
parent
54e7055361
commit
905a0f5ea3
@ -51,6 +51,7 @@ DB_USER=dbuser DB_PASSWORD=pass DB_DB=htmlhouse PRIVATE_KEY=keys/dev PUBLIC_KEY=
|
|||||||
| `PUBLIC_KEY` | Generated public key | None. **Required** |
|
| `PUBLIC_KEY` | Generated public key | None. **Required** |
|
||||||
| `PORT` | Port to run app on | `8080` |
|
| `PORT` | Port to run app on | `8080` |
|
||||||
| `STATIC_DIR` | Relative dir where static files are stored | `static` |
|
| `STATIC_DIR` | Relative dir where static files are stored | `static` |
|
||||||
|
| `ALLOW_PUBLISH` | Allow users to publish posts | true |
|
||||||
| `AUTO_APPROVE` | Automatically approves public posts | false |
|
| `AUTO_APPROVE` | Automatically approves public posts | false |
|
||||||
| `PREVIEWS_HOST` | Fully-qualified URL (without trailing slash) of screenshot server | None. |
|
| `PREVIEWS_HOST` | Fully-qualified URL (without trailing slash) of screenshot server | None. |
|
||||||
| `ADMIN_PASS` | Password to perform admin functions via API | `uhoh` |
|
| `ADMIN_PASS` | Password to perform admin functions via API | `uhoh` |
|
||||||
|
18
app.go
18
app.go
@ -54,7 +54,9 @@ func (app *app) initRouter() {
|
|||||||
app.router = mux.NewRouter()
|
app.router = mux.NewRouter()
|
||||||
|
|
||||||
api := app.router.PathPrefix("/⌂/").Subrouter()
|
api := app.router.PathPrefix("/⌂/").Subrouter()
|
||||||
api.HandleFunc("/create", app.handler(createHouse)).Methods("POST").Name("create")
|
if app.cfg.AllowPublish {
|
||||||
|
api.HandleFunc("/create", app.handler(createHouse)).Methods("POST").Name("create")
|
||||||
|
}
|
||||||
api.HandleFunc("/{house:[A-Za-z0-9.-]{8}}", app.handler(renovateHouse)).Methods("POST").Name("update")
|
api.HandleFunc("/{house:[A-Za-z0-9.-]{8}}", app.handler(renovateHouse)).Methods("POST").Name("update")
|
||||||
api.HandleFunc("/public", app.handler(getPublicHousesData)).Methods("GET").Name("browse-api")
|
api.HandleFunc("/public", app.handler(getPublicHousesData)).Methods("GET").Name("browse-api")
|
||||||
|
|
||||||
@ -74,6 +76,8 @@ type EditorPage struct {
|
|||||||
ID string
|
ID string
|
||||||
Content string
|
Content string
|
||||||
Public bool
|
Public bool
|
||||||
|
|
||||||
|
AllowPublish bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func getEditor(app *app, w http.ResponseWriter, r *http.Request) error {
|
func getEditor(app *app, w http.ResponseWriter, r *http.Request) error {
|
||||||
@ -86,7 +90,10 @@ func getEditor(app *app, w http.ResponseWriter, r *http.Request) error {
|
|||||||
fmt.Printf("\n%s\n", err)
|
fmt.Printf("\n%s\n", err)
|
||||||
defaultPage = []byte("<!DOCTYPE html>\n<html>\n</html>")
|
defaultPage = []byte("<!DOCTYPE html>\n<html>\n</html>")
|
||||||
}
|
}
|
||||||
app.templates["editor"].ExecuteTemplate(w, "editor", &EditorPage{"", string(defaultPage), false})
|
app.templates["editor"].ExecuteTemplate(w, "editor", &EditorPage{
|
||||||
|
Content: string(defaultPage),
|
||||||
|
AllowPublish: app.cfg.AllowPublish,
|
||||||
|
})
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -96,7 +103,12 @@ func getEditor(app *app, w http.ResponseWriter, r *http.Request) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
app.templates["editor"].ExecuteTemplate(w, "editor", &EditorPage{house, html, isHousePublic(app, house)})
|
app.templates["editor"].ExecuteTemplate(w, "editor", &EditorPage{
|
||||||
|
ID: house,
|
||||||
|
Content: html,
|
||||||
|
Public: isHousePublic(app, house),
|
||||||
|
AllowPublish: app.cfg.AllowPublish,
|
||||||
|
})
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@ type config struct {
|
|||||||
ServerPort int `env:"key=PORT default=8080"`
|
ServerPort int `env:"key=PORT default=8080"`
|
||||||
|
|
||||||
AutoApprove bool `env:"key=AUTO_APPROVE default=false"`
|
AutoApprove bool `env:"key=AUTO_APPROVE default=false"`
|
||||||
|
AllowPublish bool `env:"key=ALLOW_PUBLISH default=true"`
|
||||||
PreviewsHost string `env:"key=PREVIEWS_HOST`
|
PreviewsHost string `env:"key=PREVIEWS_HOST`
|
||||||
AdminPass string `env:"key=ADMIN_PASS default=uhoh"`
|
AdminPass string `env:"key=ADMIN_PASS default=uhoh"`
|
||||||
BrowseItems int `env:"key=BROWSE_ITEMS default=10"`
|
BrowseItems int `env:"key=BROWSE_ITEMS default=10"`
|
||||||
|
@ -37,8 +37,10 @@
|
|||||||
<a href="/contact.html">contact</a>
|
<a href="/contact.html">contact</a>
|
||||||
</nav>
|
</nav>
|
||||||
{{if .ID}}<a href="/{{.ID}}.html">view</a>{{end}}
|
{{if .ID}}<a href="/{{.ID}}.html">view</a>{{end}}
|
||||||
<a id="publish" href="#">{{if .ID}}update{{else}}publish{{end}}</a>
|
{{if .AllowPublish}}
|
||||||
<input type="checkbox" name="public" id="public"{{if .Public}} checked="checked"{{end}} /><label for="public">public</label>
|
<a id="publish" href="#">{{if .ID}}update{{else}}publish{{end}}</a>
|
||||||
|
<input type="checkbox" name="public" id="public"{{if .Public}} checked="checked"{{end}} /><label for="public">public</label>
|
||||||
|
{{end}}
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<pre id="editor">{{.Content}}</pre>
|
<pre id="editor">{{.Content}}</pre>
|
||||||
|
Loading…
Reference in New Issue
Block a user