1
0
mirror of https://github.com/makew0rld/amfora.git synced 2024-12-04 14:46:29 -05:00

Custom new tab page (#83)

This commit is contained in:
Sotiris Papatheodorou 2020-09-01 18:55:09 +01:00 committed by GitHub
parent 3dfbeb5bda
commit 9d7c7370e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 49 additions and 5 deletions

View File

@ -19,6 +19,9 @@ var amforaAppData string // Where amfora files are stored on Windows - cached he
var configDir string var configDir string
var configPath string var configPath string
var NewTabPath string
var CustomNewTab bool
var TofuStore = viper.New() var TofuStore = viper.New()
var tofuDBDir string var tofuDBDir string
var tofuDBPath string var tofuDBPath string
@ -64,6 +67,13 @@ func Init() error {
} }
configPath = filepath.Join(configDir, "config.toml") 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 // Store TOFU db directory and file paths
if runtime.GOOS == "windows" { if runtime.GOOS == "windows" {
// Windows just stores it in APPDATA along with other stuff // Windows just stores it in APPDATA along with other stuff

View File

@ -51,8 +51,6 @@ var tabRow = cview.NewTextView().
var layout = cview.NewFlex(). var layout = cview.NewFlex().
SetDirection(cview.FlexRow) SetDirection(cview.FlexRow)
var renderedNewTabContent string
var newTabLinks []string
var newTabPage structs.Page var newTabPage structs.Page
var App = cview.NewApplication(). var App = cview.NewApplication().
@ -202,7 +200,8 @@ func Init() {
}) })
// Render the default new tab content ONCE and store it for later // 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{ newTabPage = structs.Page{
Raw: newTabContent, Raw: newTabContent,
Content: renderedNewTabContent, Content: renderedNewTabContent,
@ -519,6 +518,24 @@ func SwitchTab(tab int) {
} }
func Reload() { 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() { if !tabs[curTab].hasContent() {
return return
} }

View File

@ -1,12 +1,20 @@
//nolint
package display 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. 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. 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! Happy browsing!
=> about:bookmarks Bookmarks => about:bookmarks Bookmarks
@ -14,3 +22,12 @@ Happy browsing!
=> //gemini.circumlunar.space Project Gemini => //gemini.circumlunar.space Project Gemini
=> https://github.com/makeworld-the-better-one/amfora Amfora homepage [HTTPS] => 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
}