Use Once for CachedHostname
This commit is contained in:
parent
e6662e11c3
commit
5b160ea599
@ -96,7 +96,7 @@ func (self *Context) hyperlink_for_path(path string, text string) string {
|
|||||||
if err == nil && fi.IsDir() {
|
if err == nil && fi.IsDir() {
|
||||||
path = strings.TrimSuffix(path, "/") + "/"
|
path = strings.TrimSuffix(path, "/") + "/"
|
||||||
}
|
}
|
||||||
host := utils.CachedHostname()
|
host := utils.Hostname()
|
||||||
url := "file://" + host + path
|
url := "file://" + host + path
|
||||||
return self.hyperlink_for_url(url, text)
|
return self.hyperlink_for_url(url, text)
|
||||||
}
|
}
|
||||||
@ -119,7 +119,7 @@ func (self *Context) link(x string) string {
|
|||||||
|
|
||||||
func (self *Context) ref_hyperlink(x string, prefix string) string {
|
func (self *Context) ref_hyperlink(x string, prefix string) string {
|
||||||
text, target := text_and_target(x)
|
text, target := text_and_target(x)
|
||||||
url := "kitty+doc://" + utils.CachedHostname() + "/#ref=" + prefix + target
|
url := "kitty+doc://" + utils.Hostname() + "/#ref=" + prefix + target
|
||||||
text = replace_all_rst_roles(text, func(group rst_format_match) string {
|
text = replace_all_rst_roles(text, func(group rst_format_match) string {
|
||||||
return group.payload
|
return group.payload
|
||||||
})
|
})
|
||||||
|
|||||||
@ -11,14 +11,10 @@ var _ = fmt.Print
|
|||||||
|
|
||||||
var hostname string = "*"
|
var hostname string = "*"
|
||||||
|
|
||||||
func CachedHostname() string {
|
var Hostname = (&Once[string]{Run: func() string {
|
||||||
if hostname == "*" {
|
|
||||||
h, err := os.Hostname()
|
h, err := os.Hostname()
|
||||||
if err != nil {
|
if err == nil {
|
||||||
hostname = h
|
return h
|
||||||
} else {
|
|
||||||
hostname = ""
|
|
||||||
}
|
}
|
||||||
}
|
return ""
|
||||||
return hostname
|
}}).Get
|
||||||
}
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user