1
1
package run .halo .feed ;
2
2
3
+ import static run .halo .feed .RssUtils .genRelativeThumbUri ;
4
+
3
5
import com .google .common .base .Throwables ;
6
+ import java .net .URI ;
4
7
import lombok .extern .slf4j .Slf4j ;
5
8
import org .apache .commons .lang3 .StringUtils ;
6
9
import org .jsoup .Jsoup ;
7
10
import org .jsoup .nodes .Element ;
8
11
import org .jsoup .select .Elements ;
9
12
import org .springframework .util .Assert ;
10
13
import org .springframework .web .util .UriComponentsBuilder ;
11
- import org .springframework .web .util .UriUtils ;
12
14
import run .halo .app .core .attachment .ThumbnailSize ;
13
15
import run .halo .app .infra .utils .PathUtils ;
14
16
import run .halo .feed .telemetry .TelemetryEndpoint ;
15
17
16
- import java .net .URI ;
17
- import java .nio .charset .StandardCharsets ;
18
-
19
18
@ Slf4j
20
19
public class RelativeLinkProcessor {
21
20
private final URI externalUri ;
@@ -66,8 +65,6 @@ private String doProcessForHtml(String html) {
66
65
processElementAttr (embeds , "src" , false );
67
66
68
67
return document .body ().html ();
69
- // var outputHtml = document.body().html();
70
- // return StringEscapeUtils.unescapeHtml4(outputHtml);
71
68
}
72
69
73
70
private void processElementAttr (Elements elements , String attrKey , boolean canThumb ) {
@@ -89,10 +86,7 @@ boolean isNotTelemetryLink(String uri) {
89
86
}
90
87
91
88
private String genThumbUrl (String url , ThumbnailSize size ) {
92
- return processLink ("/apis/api.storage.halo.run/v1alpha1/thumbnails/-/via-uri?uri="
93
- + UriUtils .encode (url , StandardCharsets .UTF_8 )
94
- + "&size=" + size .name ().toLowerCase ()
95
- );
89
+ return processLink (genRelativeThumbUri (url , size ));
96
90
}
97
91
98
92
private String processLink (String link ) {
@@ -101,18 +95,18 @@ private String processLink(String link) {
101
95
}
102
96
var contextPath = StringUtils .defaultIfBlank (externalUri .getPath (), "/" );
103
97
var linkUri = UriComponentsBuilder .fromUriString (URI .create (link ).toASCIIString ())
104
- .build (true );
98
+ .build (true );
105
99
var builder = UriComponentsBuilder .fromUriString (externalUri .toString ());
106
100
if (shouldAppendPath (contextPath , link )) {
107
101
builder .pathSegment (linkUri .getPathSegments ().toArray (new String [0 ]));
108
102
} else {
109
103
builder .replacePath (linkUri .getPath ());
110
104
}
111
105
return builder .query (linkUri .getQuery ())
112
- .fragment (linkUri .getFragment ())
113
- .build (true )
114
- .toUri ()
115
- .toString ();
106
+ .fragment (linkUri .getFragment ())
107
+ .build (true )
108
+ .toUri ()
109
+ .toString ();
116
110
}
117
111
118
112
private static boolean shouldAppendPath (String contextPath , String link ) {
0 commit comments