Ticket #43: patch_collide.diff
File patch_collide.diff, 3.1 KB (added by , 10 years ago) |
---|
-
htmlgen.go
19 19 20 20 import ( 21 21 "bytes" 22 "encoding/hex"23 22 "errors" 24 23 "fmt" 25 24 "html" … … 62 61 return fmt.Sprintf(`src="%v"`, url) 63 62 } 64 63 if options.inline { 65 return fmt.Sprintf(`data-imgsrc="res_%v"`, string(hex.EncodeToString([]byte(url))))64 return fmt.Sprintf(`data-imgsrc="res_%v"`, urlToCopiedResourceName(url)) 66 65 } 67 66 return fmt.Sprintf(`src="%v"`, url) 68 67 } … … 157 156 158 157 func (this *HTMLGenerator) imgSrc(href string) string { 159 158 if this.options.inline && CanInline(href) { 160 return fmt.Sprintf(`data-imgsrc="res_%v"`, string(hex.EncodeToString([]byte(filepath.Base(href)))))159 return fmt.Sprintf(`data-imgsrc="res_%v"`, urlToCopiedResourceName(href)) 161 160 } 162 161 if CanInline(href) { // The file will be copied 163 return fmt.Sprintf(`src="%v"`, filepath.Base(href))162 return fmt.Sprintf(`src="%v"`, urlToCopiedResourceNameExt(href)) 164 163 } 165 164 return fmt.Sprintf(`src="%v"`, href) 166 165 } -
resource.go
19 19 20 20 import ( 21 21 "encoding/base64" 22 "encoding/hex"23 22 "fmt" 24 23 "io/ioutil" 25 24 "log" … … 64 63 return &Resource{name, true, resType, funcGetBytes} 65 64 } 66 65 66 67 func urlToCopiedResourceName(url string) string { 68 return func_hash(url) 69 } 70 71 func urlToCopiedResourceNameExt(url string) string { 72 return urlToCopiedResourceName(url)+filepath.Ext(url) 73 } 74 67 75 func NewExternalResource(url string, resType resourceType) *Resource { 68 76 if CanInline(url) { 69 77 f := func() []byte { … … 119 127 120 128 switch this.resType { 121 129 case typeImage: 122 f.WriteString(fmt.Sprintf("window.res_%v = '%v';\n", string(hex.EncodeToString([]byte(filepath.Base(this.url)))), InlineImage(this.url, this.GetBytes())))130 f.WriteString(fmt.Sprintf("window.res_%v = '%v';\n", urlToCopiedResourceName(this.url), InlineImage(this.url, this.GetBytes()))) 123 131 case typeCss, typeScript: 124 132 f.Write(this.GetBytes()) 125 133 case typeFont: … … 141 149 func (this *Resource) ToHtmlLink(f *os.File) { 142 150 url := this.url 143 151 // If the file will be copied and if it is not builtin, remove the path from the URL 144 if ! this.builtin && !strings.HasPrefix(this.url, "http:") && !strings.HasPrefix(this.url, "https:") {145 url = filepath.Base(url)152 if !strings.HasPrefix(this.url, "http:") && !strings.HasPrefix(this.url, "https:") { 153 url = urlToCopiedResourceNameExt(url) 146 154 } 147 155 switch this.resType { 148 156 case typeCss: … … 171 179 } 172 180 173 181 if this.builtin { 174 err := ioutil.WriteFile(filepath.Join(destpath, this.url), this.GetBytes(), 0664)182 err := ioutil.WriteFile(filepath.Join(destpath, urlToCopiedResourceNameExt(this.url)), this.GetBytes(), 0664) 175 183 if err != nil { 176 184 log.Printf("Could not write file %v", this.url) 177 185 } 178 186 } else { 179 CopyFile(filepath.Join(destpath, filepath.Base(this.url)), this.url)187 CopyFile(filepath.Join(destpath, urlToCopiedResourceNameExt(this.url)), this.url) 180 188 } 181 189 182 190 writtenResource[this.url] = true