1import { Controller } from "@hotwired/stimulus" 2 3export default class extends Controller { 4 static values = { 5 pikaDomain: String, 6 subdomain: String, 7 domain: String 8 } 9 10 connect() { 11 this.retargetOutboundLinks(this.element.querySelectorAll("a")) 12 } 13 14 retargetOutboundLinks(links) { 15 links.forEach((link) => { 16 if (this.isOutboundLink(link)) { 17 link.setAttribute("target", "_blank") 18 } 19 }) 20 } 21 22 isOutboundLink(link) { 23 // This is needed for Pagy, which has some links with no hrefs 24 if (!link.href) { 25 return false 26 } 27 28 const urlHostname = new URL(link.href).hostname.toLowerCase() 29 30 if (urlHostname === `${this.normalizedSubdomainValue}.${this.normalizedPikaDomainValue}`) { 31 return false 32 } 33 34 if (this.normalizedDomainValue && urlHostname === this.normalizedDomainValue) { 35 return false 36 } 37 38 if ( 39 this.normalizedDomainValue && 40 !this.normalizedDomainValue.startsWith("www.") && 41 urlHostname === `www.${this.normalizedDomainValue}` 42 ) { 43 return false 44 } 45 46 return true 47 } 48 49 get normalizedSubdomainValue() { 50 this._normalizedSubdomainValue ??= this.subdomainValue.toLowerCase() 51 return this._normalizedSubdomainValue 52 } 53 54 get normalizedPikaDomainValue() { 55 this._normalizedPikaDomainValue ??= this.pikaDomainValue.toLowerCase() 56 return this._normalizedPikaDomainValue 57 } 58 59 get normalizedDomainValue() { 60 if (this._normalizedDomainValue === undefined || this._normalizedDomainValue === null) { 61 this._normalizedDomainValue = this.domainValue?.toLowerCase() ?? "" 62 } 63 return this._normalizedDomainValue 64 } 65};
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.