diff options
| -rw-r--r-- | cmd/server/app.go | 42 | ||||
| -rw-r--r-- | cmd/server/handlers.go | 3 | ||||
| -rw-r--r-- | cmd/server/main.go | 13 | ||||
| -rw-r--r-- | example-site/index.md | 2 | ||||
| -rw-r--r-- | example-site/tpl/dashboard.md | 62 | ||||
| -rw-r--r-- | example-site/tpl/edit.md | 27 | ||||
| -rw-r--r-- | example-site/tpl/new-template.md | 55 |
7 files changed, 28 insertions, 176 deletions
diff --git a/cmd/server/app.go b/cmd/server/app.go index c694753..a8d1ce8 100644 --- a/cmd/server/app.go +++ b/cmd/server/app.go @@ -39,25 +39,7 @@ type App struct { FeedPrefix string } -func newApp() *App { - return &App{} -} - -func loadConf(fn string) (*App, error) { - fh, err := os.Open(fn) - if err != nil { - return nil, fmt.Errorf("loading config: %w", err) - } - - dec := yaml.NewDecoder(fh) - - app := newApp() - - err = dec.Decode(app) - if err != nil { - return nil, fmt.Errorf("decoding yaml: %w", err) - } - +func (app *App) setDefaults() { if app.StaticDirectory == "" { app.StaticDirectory = "static" } @@ -85,8 +67,28 @@ func loadConf(fn string) (*App, error) { page.Global = map[string]interface{}{ "App": app, } +} + +func loadConf(fn string) (*App, error) { + var dec *yaml.Decoder + app := &App{} + + fh, err := os.Open(fn) + if err != nil { + err = fmt.Errorf("loading config: %w", err) + goto loadConfRet + } + + dec = yaml.NewDecoder(fh) + + err = dec.Decode(app) + if err != nil { + err = fmt.Errorf("decoding yaml: %w", err) + } - return app, nil +loadConfRet: + app.setDefaults() + return app, err } func (a *App) ClearCache() error { diff --git a/cmd/server/handlers.go b/cmd/server/handlers.go index e6d2203..49f2039 100644 --- a/cmd/server/handlers.go +++ b/cmd/server/handlers.go @@ -4,6 +4,7 @@ import ( "net/http" "path/filepath" "strings" + "fmt" "riedstra.dev/mitch/go-website/mapcache" "riedstra.dev/mitch/go-website/page" @@ -55,6 +56,8 @@ func (a *App) Handler() http.Handler { } for _, r := range cacheableRoutes { + fmt.Printf("Calling mux.Handle(r.path(%s), cacheHandler(r.handler(%v)))\n", + r.path, r.handler) mux.Handle(r.path, cacheHandler(r.handler)) } diff --git a/cmd/server/main.go b/cmd/server/main.go index a776980..1b59bbe 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -36,7 +36,6 @@ func main() { //nolint:funlen directory = "." version = false confFn = "conf.yml" - authConfFn = "auth.json" verbose = false defaultIndexPath = "/reIndex" indexPath = "/reIndex" @@ -56,8 +55,6 @@ func main() { //nolint:funlen "print version and exit")) envflag.String(fl, &confFn, "c", "CONFIG_FILE", "Location for configuration file") - envflag.String(fl, &authConfFn, "ac", "AUTH_CONFIG", - "location for the authorization config") logIfErr(envflag.Bool(fl, &verbose, "V", "VERBOSE", "Be more verbose, dump config and such")) envflag.String(fl, &page.TimeFormat, "T", "TIME_FORMAT", @@ -94,20 +91,14 @@ func main() { //nolint:funlen app, err := loadConf(confFn) if err != nil { - logger.Println(err) - - app = &App{} + logger.Print(err) + logger.Fatal("A configuration file must be supplied. No valid config read") } if mapcache { app.mapCache = true } - err = app.ReadAuth(authConfFn) - if err != nil { - logger.Println(err) - } - if app.ReIndexPath == "" || indexPath != defaultIndexPath { app.ReIndexPath = indexPath } diff --git a/example-site/index.md b/example-site/index.md index 7d51067..451f36e 100644 --- a/example-site/index.md +++ b/example-site/index.md @@ -24,7 +24,7 @@ it. {{range $val := .Index.Blog.SortDate}} * [{{$val.Date.Time.Format "2006-01-02"}} {{$val.Title}}]({{$val.Path}}){{end}} -## Published Blog Entries: +## Only Published Blog Entries: {{range $val := .Index.Blog.SortDate}}{{if $val.Published}} * [{{$val.Date.Time.Format "2006-01-02"}} {{$val.Title}}]({{$val.Path}}){{end}}{{end}} diff --git a/example-site/tpl/dashboard.md b/example-site/tpl/dashboard.md deleted file mode 100644 index 4b18b98..0000000 --- a/example-site/tpl/dashboard.md +++ /dev/null @@ -1,62 +0,0 @@ ---- -title: Website Dashboard -description: Website dashboard -|--- - -# Dashboard page ( File: `tpl/dashboard.md` ) - -Almost every page on the website can be edited by simply adding `edit/` before -the path, for instance if we want to edit our `/reIndex` page, we simply go to -`/edit/reIndex` - -There are a few pages where this is not possible, such as with the dashboard and -other templated pages like 404's and 5xx's. That being said, you can still edit -them by referencing their path on disk. - -You can create new pages that way too, the new page template is -`tpl/new-template.md` if you wish to change what the defaults are. - -You'll also notice there's an `edit` button in the navbar, that's a little bit -of Javascript trickery that you'll have to edit if you wish to change the -template directory from `tpl` to anything else. - -Some useful edit links: - - * 4xx page [visit](/some/path/that/does/not/exist) [edit](/edit/tpl/4xx) - * 5xx page [visit](/tpl/5xx) [edit](/edit/tpl/5xx) - * New page template [visit](/tpl/new-template) [edit](/edit/tpl/new-template) - * Edit page [visit](/tpl/edit) [edit](/edit/tpl/edit) - * Login page [visit](/login) [edit](/edit/login) - * Base template [edit](/edit/tpl/base) - -A note about the base template page, editing works, but viewing does not. - -Pages by tags: - -{{range $key, $val := .Index}} -### {{$key}}: - -{{range $v2 := $val}} - * {{$v2.Path}} [visit](/{{$v2.Path}}) [edit](/edit/{{$v2.Path}}){{end}} - - - -{{end}} - - -It can also be a good idea to clear the cache on the dashboard page: - -``` -{{.Global.App.ClearCache}} -``` - -The element can be hidden, if you'd like. - -<script> -/* -window.addEventListener('load', (event) => { - document.querySelector("#edit").remove(); -}); -*/ -</script> - diff --git a/example-site/tpl/edit.md b/example-site/tpl/edit.md deleted file mode 100644 index 4e55f82..0000000 --- a/example-site/tpl/edit.md +++ /dev/null @@ -1,27 +0,0 @@ ---- -title: Editing Page -description: Editor -|--- - -<form action="/edit/{{.Vars.Page}}" method="POST"> -<br /> -<label for="content">Page content:</label><br /> -<br /> - - -<textarea id="content" name="content" rows="24" cols="80"> -{{.Vars.Content}} -</textarea> - -<br /> -<input type="submit" value="save"> -</form> - - -<!-- test --> - -<script> -window.addEventListener('load', (event) => { - document.querySelector("#edit").remove(); -}); -</script> diff --git a/example-site/tpl/new-template.md b/example-site/tpl/new-template.md deleted file mode 100644 index c4fdd95..0000000 --- a/example-site/tpl/new-template.md +++ /dev/null @@ -1,55 +0,0 @@ ---- -# This is the contents of the `tpl/new-template.md` file. You're likely seeing -# This because you've created a new page, or are trying to edit a page that -# does not exist. To save yourself some confusion in the future, if you save -# This page it may be helpful to delete this first paragraph, as it will no -# longer be true. - -# This top section is YAML, this sets up a few of the variables for rendering -# a web page. Below is also some markdown that's executed as a go template -# for the page's content - -# You can edit this page by editing `tpl/new-template` If you changed the -# template directory, take that into account. - -# Controls whether or not the page is published, this includes the -# Atom/RSS feed -published: false -# What tags should be applied to this page? -# The default index/home page shows a list of published blog pages -tags: - Blog: -# This is the meta description, i.e. what you're going to seeing the little blurb -# if you post the link to in say a discord chat. It's also what shows up in -# Google and other search engines -description: >- - This is an example description. Note that the line starts with spaces, and - not tabs. -title: New page from `new-template` -# Used for the RSS/Atom feed, you can also use it in the template below -date: 09.11.2022 09:59:00 EDT - -# This line tells our server to stop parsing yaml and start processing -# the rest of the text file as a markdown template -|--- - -{{/* This is a comment inside of the template */}} - -{{/* - Print out the date, format information can be found here: - https://pkg.go.dev/time#pkg-constants -*/}} -`{{.Date.Time.Format "Monday January 2 2006"}}` - -# {{.Title}} - -Some documentation on the templating language can be found [here]( -https://pkg.go.dev/text/template) - - -A nice markdown reference can be found -[here](https://www.markdownguide.org/basic-syntax/) - - -Additionally <span style="color: red;">html tags</span> can be used in here as well. - |
