Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom new tab page #83

Merged
merged 9 commits into from
Sep 1, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
)

var amforaAppData string // Where amfora files are stored on Windows - cached here
var configDir string
var ConfigDir string
var configPath string

var TofuStore = viper.New()
Expand Down Expand Up @@ -48,18 +48,18 @@ func Init() error {

// Store config directory and file paths
if runtime.GOOS == "windows" {
configDir = amforaAppData
ConfigDir = amforaAppData
} else {
// Unix / POSIX system
xdg_config, ok := os.LookupEnv("XDG_CONFIG_HOME")
if ok && strings.TrimSpace(xdg_config) != "" {
configDir = filepath.Join(xdg_config, "amfora")
ConfigDir = filepath.Join(xdg_config, "amfora")
} else {
// Default to ~/.config/amfora
configDir = filepath.Join(home, ".config", "amfora")
ConfigDir = filepath.Join(home, ".config", "amfora")
}
}
configPath = filepath.Join(configDir, "config.toml")
configPath = filepath.Join(ConfigDir, "config.toml")

// Store TOFU db directory and file paths
if runtime.GOOS == "windows" {
Expand Down Expand Up @@ -96,7 +96,7 @@ func Init() error {
// Create necessary files and folders

// Config
err = os.MkdirAll(configDir, 0755)
err = os.MkdirAll(ConfigDir, 0755)
if err != nil {
return err
}
Expand Down
1 change: 1 addition & 0 deletions display/display.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ func Init() {
})

// Render the default new tab content ONCE and store it for later
newTabContent := getNewTabContent()
renderedNewTabContent, newTabLinks = renderer.RenderGemini(newTabContent, textWidth(), leftMargin())
newTabPage = structs.Page{
Raw: newTabContent,
Expand Down
26 changes: 25 additions & 1 deletion display/newtab.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,40 @@
//nolint
package display

var newTabContent = `# New Tab
import (
"io/ioutil"
"path/filepath"

"github.com/makeworld-the-better-one/amfora/config"
)

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 the Gemtext file

` + "```" + `
$XDG_CONFIG_HOME/amfora/new_tab.gmi
` + "```" + `

sotpapathe marked this conversation as resolved.
Show resolved Hide resolved
Happy browsing!

=> about:bookmarks Bookmarks

=> //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 {
newTabFile := filepath.Join(config.ConfigDir, "new_tab.gmi")
data, err := ioutil.ReadFile(newTabFile)
if err == nil {
return string(data)
} else {
return defaultNewTabContent
}
sotpapathe marked this conversation as resolved.
Show resolved Hide resolved
}