File tree Expand file tree Collapse file tree 3 files changed +32
-7
lines changed
Expand file tree Collapse file tree 3 files changed +32
-7
lines changed Original file line number Diff line number Diff line change @@ -5,8 +5,9 @@ const RECORDS_PAGE = 'https://haloruns.com/records?recent';
55const resolveLink = ( $link ) => {
66 return new URL ( $link . getAttribute ( 'href' ) , RECORDS_PAGE ) . href ;
77} ;
8+
9+ const $a = document . createElement ( 'a' ) ;
810const embedLink = ( $link ) => {
9- const $a = document . createElement ( 'a' ) ;
1011 $a . href = resolveLink ( $link ) ;
1112 $a . target = '_blank' ;
1213 $a . textContent = $link . textContent ;
Original file line number Diff line number Diff line change @@ -45,20 +45,26 @@ const sources = {
4545 let videos ;
4646 try {
4747 videos = await fn ( ) ;
48+ for ( let video of videos ) {
49+ // Add links to video description.
50+ if ( video . desc ) {
51+ video . desc = util . embedLinks ( video . desc ) ;
52+ }
53+ }
54+ if ( ! isHost ) {
55+ videos = await util . parallelFilter ( videos , sources . addMetaToVideo ) ;
56+ }
4857 cachedResults [ type ] [ source ] = videos ;
58+
4959 } catch ( err ) {
5060 console . warn ( `Failed to get videos for ${ source } : ${ err . message } ` ) ;
5161 console . error ( err ) ;
5262
5363 // Fallback to cached videos from this source if getting videos fails.
5464 videos = cachedResults [ type ] [ source ] || [ ] ;
5565 }
56- if ( isHost ) {
57- return { source, videos } ;
58- } else {
59- videos = await util . parallelFilter ( videos , sources . addMetaToVideo ) ;
60- return { source, videos } ;
61- }
66+
67+ return { source, videos } ;
6268 } ) ) ;
6369 } ;
6470
@@ -165,6 +171,7 @@ const sources = {
165171 video [ field ] = meta [ field ] ;
166172 }
167173 } ) ;
174+
168175 return true ;
169176 } ,
170177
Original file line number Diff line number Diff line change @@ -261,3 +261,20 @@ export const uniq = (arr) => {
261261export const sleep = ( ms ) => {
262262 return new Promise ( resolve => setTimeout ( resolve , ms ) ) ;
263263} ;
264+
265+ /**
266+ * Converts urls in a string, that are not already html links, to html links.
267+ *
268+ * @param {string } str
269+ * @return {string }
270+ */
271+ const $a = document . createElement ( 'a' ) ;
272+ export const embedLinks = ( str ) => {
273+ return str . replace ( / ( h r e f = " ) ? ( h t t p s ? : \/ \/ [ ^ " ' ( ) [ \] { } ] + ) / g, ( m , p1 , url ) => {
274+ if ( p1 ) return m ;
275+ $a . href = url ;
276+ $a . target = '_blank' ;
277+ $a . textContent = url ;
278+ return $a . outerHTML ;
279+ } ) ;
280+ } ;
You can’t perform that action at this time.
0 commit comments