-
Notifications
You must be signed in to change notification settings - Fork 1
/
local.go
44 lines (38 loc) · 957 Bytes
/
local.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package main
import (
"io/ioutil"
"strings"
)
const (
FilesDefaultPath = ".my_scripts/.tldr"
)
func getLocalPath(homeDir string) (path string) {
return homeDir + "/" + FilesDefaultPath
}
func buildLocalPath(cfg *Config, platform string) string {
folder := "pages"
if *cfg.Language != "en" {
folder += "." + *cfg.Language
}
return *cfg.Source + "/" + folder + "/" + platform
}
func checkLocal(cfg *Config, name string) (page []string, err error) {
platforms := []string{PlatformCommon, *cfg.Platform}
// Check file for all platforms
for _, platform := range platforms {
// Build path to the local pages
fileName := buildLocalPath(cfg, platform) + "/" + name + ".md"
// If page not exist, just return
if isFileExists(fileName) {
var data []byte
// Read page data
data, err = ioutil.ReadFile(fileName)
if err != nil {
return
}
// Split text to lines
page = strings.Split(string(data), "\n")
}
}
return
}