mirror of
https://codeberg.org/video-prize-ranch/rimgo.git
synced 2026-01-28 09:31:13 +00:00
refactor api package comments
* use encoding/json for comment parsing * refactor by moving loop code to an UnmarshalJSON * use a preallocated array and indices to maintain order while using goroutines again, this was removed a while ago * use new struct in comment.hbs and contextComment.hbs * rewriteUrl partial to reduce rimgo-specific code in api * move RenderError into pages package to avoid import cycle between render and utils
This commit is contained in:
25
utils/rewriteUrl.go
Normal file
25
utils/rewriteUrl.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func RewriteUrl(link string) (string, error) {
|
||||
url, err := url.Parse(link)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
path := url.Path
|
||||
if !strings.HasPrefix(path, "/") {
|
||||
path = "/" + path
|
||||
}
|
||||
switch url.Host {
|
||||
case "", "imgur.com", "www.imgur.com", "i.imgur.com":
|
||||
return path, nil
|
||||
case "i.stack.imgur.com":
|
||||
return "/stack" + path, nil
|
||||
}
|
||||
return "", fmt.Errorf("unknown host %s", url.Host)
|
||||
}
|
||||
Reference in New Issue
Block a user