Fix empty description box showing for the Invidious API (#2614)
* Fix empty description box showing for the Invidious API * Add comment about HTML parsing
This commit is contained in:
		
							parent
							
								
									9de1a5e4dc
								
							
						
					
					
						commit
						6d1b0a63b6
					
				|  | @ -2,7 +2,6 @@ import Vue from 'vue' | ||||||
| import FtCard from '../ft-card/ft-card.vue' | import FtCard from '../ft-card/ft-card.vue' | ||||||
| import FtTimestampCatcher from '../ft-timestamp-catcher/ft-timestamp-catcher.vue' | import FtTimestampCatcher from '../ft-timestamp-catcher/ft-timestamp-catcher.vue' | ||||||
| import autolinker from 'autolinker' | import autolinker from 'autolinker' | ||||||
| import $ from 'jquery' |  | ||||||
| 
 | 
 | ||||||
| export default Vue.extend({ | export default Vue.extend({ | ||||||
|   name: 'WatchVideoDescription', |   name: 'WatchVideoDescription', | ||||||
|  | @ -31,13 +30,22 @@ export default Vue.extend({ | ||||||
|   }, |   }, | ||||||
|   mounted: function () { |   mounted: function () { | ||||||
|     if (this.descriptionHtml !== '') { |     if (this.descriptionHtml !== '') { | ||||||
|       this.shownDescription = this.parseDescriptionHtml(this.descriptionHtml) |       const parsed = this.parseDescriptionHtml(this.descriptionHtml) | ||||||
|     } else { |  | ||||||
|       this.shownDescription = autolinker.link(this.description) |  | ||||||
|     } |  | ||||||
| 
 | 
 | ||||||
|     if (/^\s*$/.test(this.shownDescription)) { |       // the invidious API returns emtpy html elements when the description is empty
 | ||||||
|       $('.videoDescription')[0].style.display = 'none' |       // so we need to parse it to see if there is any meaningful text in the html
 | ||||||
|  |       // or if it's just empty html elements e.g. `<p></p>`
 | ||||||
|  | 
 | ||||||
|  |       const testDiv = document.createElement('div') | ||||||
|  |       testDiv.innerHTML = parsed | ||||||
|  | 
 | ||||||
|  |       if (!/^\s*$/.test(testDiv.innerText)) { | ||||||
|  |         this.shownDescription = parsed | ||||||
|  |       } | ||||||
|  |     } else { | ||||||
|  |       if (!/^\s*$/.test(this.description)) { | ||||||
|  |         this.shownDescription = autolinker.link(this.description) | ||||||
|  |       } | ||||||
|     } |     } | ||||||
|   }, |   }, | ||||||
|   methods: { |   methods: { | ||||||
|  |  | ||||||
|  | @ -1,5 +1,8 @@ | ||||||
| <template> | <template> | ||||||
|   <ft-card class="videoDescription"> |   <ft-card | ||||||
|  |     v-if="shownDescription.length > 0" | ||||||
|  |     class="videoDescription" | ||||||
|  |   > | ||||||
|     <ft-timestamp-catcher |     <ft-timestamp-catcher | ||||||
|       class="description" |       class="description" | ||||||
|       :input-html="shownDescription" |       :input-html="shownDescription" | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue