diff --git a/config/config.go b/config/config.go index dc83b5bc..c2ba2706 100644 --- a/config/config.go +++ b/config/config.go @@ -18,6 +18,9 @@ var amforaAppData string // Where amfora files are stored on Windows - cached he var configDir string var configPath string +var NewTabPath string +var CustomNewTab bool + var TofuStore = viper.New() var tofuDBDir string var tofuDBPath string @@ -61,6 +64,13 @@ func Init() error { } configPath = filepath.Join(configDir, "config.toml") + // Search for a custom new tab + NewTabPath = filepath.Join(configDir, "newtab.gmi") + CustomNewTab = false + if _, err := os.Stat(NewTabPath); err == nil { + CustomNewTab = true + } + // Store TOFU db directory and file paths if runtime.GOOS == "windows" { // Windows just stores it in APPDATA along with other stuff diff --git a/display/display.go b/display/display.go index 15cc65e8..870ef0e1 100644 --- a/display/display.go +++ b/display/display.go @@ -51,8 +51,6 @@ var tabRow = cview.NewTextView(). var layout = cview.NewFlex(). SetDirection(cview.FlexRow) -var renderedNewTabContent string -var newTabLinks []string var newTabPage structs.Page var App = cview.NewApplication(). @@ -202,7 +200,8 @@ func Init() { }) // Render the default new tab content ONCE and store it for later - renderedNewTabContent, newTabLinks = renderer.RenderGemini(newTabContent, textWidth(), leftMargin()) + newTabContent := getNewTabContent() + renderedNewTabContent, newTabLinks := renderer.RenderGemini(newTabContent, textWidth(), leftMargin()) newTabPage = structs.Page{ Raw: newTabContent, Content: renderedNewTabContent, @@ -519,6 +518,24 @@ func SwitchTab(tab int) { } func Reload() { + if tabs[curTab].page.URL == "about:newtab" && config.CustomNewTab { + // Re-render new tab, similar to Init() + newTabContent := getNewTabContent() + tmpTermW := termW + renderedNewTabContent, newTabLinks := renderer.RenderGemini(newTabContent, textWidth(), leftMargin()) + newTabPage = structs.Page{ + Raw: newTabContent, + Content: renderedNewTabContent, + Links: newTabLinks, + URL: "about:newtab", + Width: tmpTermW, + Mediatype: structs.TextGemini, + } + temp := newTabPage // Copy + setPage(tabs[curTab], &temp) + return + } + if !tabs[curTab].hasContent() { return } diff --git a/display/newtab.go b/display/newtab.go index 987f0f68..e1755c52 100644 --- a/display/newtab.go +++ b/display/newtab.go @@ -1,12 +1,20 @@ -//nolint package display -var newTabContent = `# New Tab +import ( + "io/ioutil" + + "github.com/makeworld-the-better-one/amfora/config" +) + +//nolint +var defaultNewTabContent = `# New Tab You've opened a new tab. Use the bar at the bottom to browse around. You can start typing in it by pressing the space key. Press the ? key at any time to bring up the help, and see other keybindings. Most are what you expect. +You can customize this page by creating a gemtext file called newtab.gmi, in Amfora's configuration folder. + Happy browsing! => about:bookmarks Bookmarks @@ -14,3 +22,12 @@ Happy browsing! => //gemini.circumlunar.space Project Gemini => https://github.com/makeworld-the-better-one/amfora Amfora homepage [HTTPS] ` + +// Read the new tab content from a file if it exists or fallback to a default page. +func getNewTabContent() string { + data, err := ioutil.ReadFile(config.NewTabPath) + if err == nil { + return string(data) + } + return defaultNewTabContent +}