~nromdotcom/gemif

73f32fca6ddc83433128bd62edc6e2dff4e6716d — Norm MacLennan 10 months ago 4537a2f 0.4.0
Make homepage customizable in config.toml
M cmd/gemif/main.go => cmd/gemif/main.go +10 -3
@@ 45,8 45,8 @@ func main() {
		log.Fatalf("Error loading stories! %s", err)
	}

	renderDesc := config.Get("engine.render_descriptions").(bool)
	tokenFormat := config.Get("engine.statetoken_format").(string)
	renderDesc := config.GetDefault("engine.render_descriptions", true).(bool)
	tokenFormat := config.GetDefault("engine.statetoken_format", "proto").(string)

	engineConfig, err := gamemanager.NewEngineConfig(renderDesc, tokenFormat)
	if err != nil {


@@ 64,7 64,14 @@ func main() {
		Port:     gsConfig.Get("port").(int64),
		CertFile: gsConfig.Get("cert_file").(string),
		KeyFile:  gsConfig.Get("key_file").(string),
		Version:  appVersion,
		HomePage: gemserver.IndexConfig{
			DisplayProjectInfo: config.GetDefault("homepage.display_project_info", true).(bool),
			ContactEmail:       config.GetDefault("homepage.contact_email", "").(string),
			Title:              config.GetDefault("homepage.title", "").(string),
			DisplayPoweredBy:   config.GetDefault("homepage.display_powered_by", true).(bool),
			PageBody:           config.GetDefault("homepage.page_body", "").(string),
		},
		Version: appVersion,
	}

	fmt.Printf("Starting %s %s (%s) - built %s\n\n", appName, appVersion, appCommit, buildTime)

M infra/user_data/install_gemif.sh => infra/user_data/install_gemif.sh +5 -0
@@ 41,6 41,11 @@ key_file  = "./acme.key"
stories_dir         = "./stories/compiled"
render_descriptions = true
statetoken_format   = "proto"

[homepage]
display_powered_by = true
display_project_info = true
contact_email = "norm@iwritethe.codes"
EOF

wget https://git.sr.ht/~nromdotcom/gemif/refs/${version}/gemif-linux-arm64-${version}.tar.gz

M pkg/gemserver/router.go => pkg/gemserver/router.go +1 -1
@@ 30,7 30,7 @@ func StartRouter(gm *gamemanager.GameManager, gc ServerConfig) {
		templates: tmpl,
	}

	g.Handle("/", handleHome(gm, gc.Version))
	g.Handle("/", handleHome(gm, gc.Version, gc.HomePage))
	g.Handle("/game/:statetoken", handleGame(gm, sceneRenderer))
	g.Handle("/story/:storyid", handleStory(gm))
	g.Handle("/docs*", handleStatic)

M pkg/gemserver/routes.go => pkg/gemserver/routes.go +2 -6
@@ 39,15 39,10 @@ func handleStatic(c gig.Context) error {
	return c.Gemini(string(sl))
}

func handleHome(gm *gamemanager.GameManager, version string) func(gig.Context) error {
func handleHome(gm *gamemanager.GameManager, version string, pc IndexConfig) func(gig.Context) error {
	return func(c gig.Context) error {
		stories := gm.GetStories()

		// startStates, startErr := gm.ConstructStartingState(stories)
		// if startErr != nil {
		// 	return fmt.Errorf("couldn't load game: %w", startErr)
		// }

		sort.Slice(stories, func(a int, b int) bool {
			return stories[a].Name < stories[b].Name
		})


@@ 56,6 51,7 @@ func handleHome(gm *gamemanager.GameManager, version string) func(gig.Context) e
			"Stories": stories,
			"Banner":  getRandomBanner(),
			"Version": version,
			"Config":  pc,
		})
	}
}

M pkg/gemserver/serverconfig.go => pkg/gemserver/serverconfig.go +10 -0
@@ 7,4 7,14 @@ type ServerConfig struct {
	CertFile string
	KeyFile  string
	Version  string
	HomePage IndexConfig
}

// IndexConfig contains configuration info for the homepage.
type IndexConfig struct {
	DisplayProjectInfo bool
	DisplayPoweredBy   bool
	ContactEmail       string
	Title              string
	PageBody           string
}

M sample.config.toml => sample.config.toml +27 -1
@@ 5,8 5,34 @@ cert_file = "./itsa.crt"
key_file  = "./anda.key"

[engine]
# Path to directory where compiled stories are stored.
stories_dir         = "./stories/compiled"
# Whether to render gotmpl syntax in room descriptions,
# otherwise all room descriptions are printed literally.
# Note: gemtext will render even when this is false.
render_descriptions = true
# Method to use for serializing the state token.
# JSON is easier to debug, but often less efficient.
# proto = protobuf
# json  = json
statetoken_format   = "proto"
\ No newline at end of file
statetoken_format   = "proto"

[homepage]
# Whether or not to display 
# "Powered by GemIF vX.Y.Z" on the homepage
display_powered_by = true
# Whether or not to add a link to the GemIF git repo
# on the homepage
display_project_info = false
# Email address for the capsule owner, renders
# a `mailto` link when present, otherwise no contact
# info is rendered
contact_email = "norm@iwritethe.codes"
# Level one title to render at the top of the page,
# otherwise a GemIF ASCII banner will be rendered
title = "My Gemini Capsule"
# Gemtext to render between the title and stories list.
# If not present, a short intro to GemIF will be rendered.
page_body = '''
Hey, check out my stories!
'''
\ No newline at end of file

M static/templates/index.gmi.tmpl => static/templates/index.gmi.tmpl +18 -6
@@ 1,15 1,23 @@
{{- if ne .Config.Title "" }}
# {{.Config.Title}}
{{- else}}
```
{{.Banner}}
```
v{{.Version}}

{{ end -}}

{{- if .Config.DisplayPoweredBy }}
Powered by GemIF v{{.Version}}
{{ end -}}
{{- if ne .Config.PageBody "" }}
{{.Config.PageBody}}
{{- else }}
GemIF is a simple Interactive Fiction engine for Gemini (think: twine but with fewer features).

Each story below is written in a simple mark-up format similar to Gemini format and compiled into a (relatively-) simple YAML file describing the scenes and transitions.

Stories allow users to make choices, moving from scene to scene. Simple logic can be added in the form of "condition" tags attached to the game state. Making choices can apply those transitions, which allow for conditional text rendering and conditionally allowing use of transitions later in the story.

If you want to run your own instance, check out the repo linked below. There are instructions in the README.
{{ end -}}

## Stories



@@ 20,8 28,12 @@ If you want to run your own instance, check out the repo linked below. There are
{{- end}} (by {{$value.Author}})
{{- end}}

{{- if .Config.DisplayProjectInfo}}
## Learn More
=> https://git.sr.ht/~nromdotcom/gemif [https] source at sr.ht
=> mailto:~nromdotcom/gemif@lists.sr.ht [mailto] Send in your stories for free hosting

For anything else, feel free to email the project mailing list `~nromdotcom/gemif@lists.sr.ht` or me personally at `norm@iwritethe.codes`.
\ No newline at end of file
{{end}}
{{ if ne .Config.ContactEmail ""}}
Contact the operator of this capsule:
=> mailto:{{.Config.ContactEmail}}
{{end}}
\ No newline at end of file