-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate_funcs.go
48 lines (37 loc) · 1.22 KB
/
template_funcs.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
45
46
47
48
package pipedream
import "fmt"
// JSPath returns the path for a given js asset.
func (p Pipedream) JSPath(file string) string {
return p.lookupPath(typeJS, file)
}
// CSSPath returns the path for a given css asset.
func (p Pipedream) CSSPath(file string) string {
return p.lookupPath(typeCSS, file)
}
// ImgPath returns the path for a given img asset.
func (p Pipedream) ImgPath(file string) string {
return p.lookupPath(typeImg, file)
}
// VideoPath returns the path for a given video asset.
func (p Pipedream) VideoPath(file string) string {
return p.lookupPath(typeVideos, file)
}
// AudioPath returns the path for a given audio asset.
func (p Pipedream) AudioPath(file string) string {
return p.lookupPath(typeAudio, file)
}
// FontPath returns the path for a given font asset.
func (p Pipedream) FontPath(file string) string {
return p.lookupPath(typeFonts, file)
}
func (p Pipedream) lookupPath(typ, file string) string {
if p.NoHash {
return fmt.Sprintf("%s/assets/%s/%s", p.CDNURL, typ, file)
}
key := fmt.Sprintf("%s/%s", typ, file)
asset, ok := p.Manifest.Assets[key]
if !ok {
panic(fmt.Sprintf("asset %s requested but was not in manifest, did you rememeber to precompile assets?", key))
}
return p.CDNURL + asset
}