1import { Controller } from "@hotwired/stimulus" 2import { isEmbeddableLink, mediaSites } from "media_sites" 3 4export default class extends Controller { 5 connect() { 6 this.mediaSites = mediaSites() 7 this.replaceMediaLinks() 8 } 9 10 async replaceMediaLinks() { 11 const articles = Array.from(this.element.querySelectorAll('article')) 12 const links = articles.flatMap(a => Array.from(a.querySelectorAll('a')).filter(l => isEmbeddableLink(l, this.mediaSites))) 13 await Promise.all(links.map(link => this.processLink(link))) 14 } 15 16 async processLink(link) { 17 const url = link.href 18 19 for (const site of this.mediaSites) { 20 if (site.regex.test(url)) { 21 const iframe = await site.transform(url) 22 if (iframe) { 23 link.replaceWith(iframe) 24 break // Stop after first successful match 25 } 26 } 27 } 28 } 29}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.