mirror of
				https://github.com/TeamPiped/Piped.git
				synced 2024-08-14 23:57:27 +00:00 
			
		
		
		
	
							parent
							
								
									a861a8b95d
								
							
						
					
					
						commit
						70277fe077
					
				
					 3 changed files with 22 additions and 14 deletions
				
			
		| 
						 | 
					@ -18,6 +18,8 @@
 | 
				
			||||||
        "dompurify": "3.0.5",
 | 
					        "dompurify": "3.0.5",
 | 
				
			||||||
        "hotkeys-js": "3.12.0",
 | 
					        "hotkeys-js": "3.12.0",
 | 
				
			||||||
        "javascript-time-ago": "2.5.9",
 | 
					        "javascript-time-ago": "2.5.9",
 | 
				
			||||||
 | 
					        "linkify-html": "4.1.1",
 | 
				
			||||||
 | 
					        "linkifyjs": "4.1.1",
 | 
				
			||||||
        "mux.js": "6.3.0",
 | 
					        "mux.js": "6.3.0",
 | 
				
			||||||
        "qrcode": "^1.5.3",
 | 
					        "qrcode": "^1.5.3",
 | 
				
			||||||
        "shaka-player": "4.3.8",
 | 
					        "shaka-player": "4.3.8",
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										18
									
								
								pnpm-lock.yaml
									
										
									
										generated
									
									
									
								
							
							
						
						
									
										18
									
								
								pnpm-lock.yaml
									
										
									
										generated
									
									
									
								
							| 
						 | 
					@ -29,6 +29,12 @@ dependencies:
 | 
				
			||||||
  javascript-time-ago:
 | 
					  javascript-time-ago:
 | 
				
			||||||
    specifier: 2.5.9
 | 
					    specifier: 2.5.9
 | 
				
			||||||
    version: 2.5.9
 | 
					    version: 2.5.9
 | 
				
			||||||
 | 
					  linkify-html:
 | 
				
			||||||
 | 
					    specifier: 4.1.1
 | 
				
			||||||
 | 
					    version: 4.1.1(linkifyjs@4.1.1)
 | 
				
			||||||
 | 
					  linkifyjs:
 | 
				
			||||||
 | 
					    specifier: 4.1.1
 | 
				
			||||||
 | 
					    version: 4.1.1
 | 
				
			||||||
  mux.js:
 | 
					  mux.js:
 | 
				
			||||||
    specifier: 6.3.0
 | 
					    specifier: 6.3.0
 | 
				
			||||||
    version: 6.3.0
 | 
					    version: 6.3.0
 | 
				
			||||||
| 
						 | 
					@ -3801,6 +3807,18 @@ packages:
 | 
				
			||||||
      lightningcss-win32-x64-msvc: 1.21.5
 | 
					      lightningcss-win32-x64-msvc: 1.21.5
 | 
				
			||||||
    dev: true
 | 
					    dev: true
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /linkify-html@4.1.1(linkifyjs@4.1.1):
 | 
				
			||||||
 | 
					    resolution: {integrity: sha512-7RcF7gIhEOGBBvs7orCJ2tevaz7iF0ZLZSRPWNNBOnW/uGjOOQYB+ztSeHF6dchMC2dM9H8zZlt6Z959bjteaw==}
 | 
				
			||||||
 | 
					    peerDependencies:
 | 
				
			||||||
 | 
					      linkifyjs: ^4.0.0
 | 
				
			||||||
 | 
					    dependencies:
 | 
				
			||||||
 | 
					      linkifyjs: 4.1.1
 | 
				
			||||||
 | 
					    dev: false
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /linkifyjs@4.1.1:
 | 
				
			||||||
 | 
					    resolution: {integrity: sha512-zFN/CTVmbcVef+WaDXT63dNzzkfRBKT1j464NJQkV7iSgJU0sLBus9W0HBwnXK13/hf168pbrx/V/bjEHOXNHA==}
 | 
				
			||||||
 | 
					    dev: false
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /local-pkg@0.4.3:
 | 
					  /local-pkg@0.4.3:
 | 
				
			||||||
    resolution: {integrity: sha512-SFppqq5p42fe2qcZQqqEOiVRXl+WCP1MdT6k7BDEW1j++sp5fIY+/fdRQitvKgB5BrBcmrs5m/L0v2FrU5MY1g==}
 | 
					    resolution: {integrity: sha512-SFppqq5p42fe2qcZQqqEOiVRXl+WCP1MdT6k7BDEW1j++sp5fIY+/fdRQitvKgB5BrBcmrs5m/L0v2FrU5MY1g==}
 | 
				
			||||||
    engines: {node: '>=14'}
 | 
					    engines: {node: '>=14'}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -4,22 +4,10 @@ export const purifyHTML = html => {
 | 
				
			||||||
    return DOMPurify.sanitize(html);
 | 
					    return DOMPurify.sanitize(html);
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const urlify = string => {
 | 
					import linkifyHtml from "linkify-html";
 | 
				
			||||||
    if (!string) return "";
 | 
					 | 
				
			||||||
    const urlRegex = /(((https?:\/\/)|(www\.))[^\s]+)/g;
 | 
					 | 
				
			||||||
    const emailRegex = /([\w-\\.]+@(?:[\w-]+\.)+[\w-]{2,4})/g;
 | 
					 | 
				
			||||||
    return string
 | 
					 | 
				
			||||||
        .replace(urlRegex, url => {
 | 
					 | 
				
			||||||
            if (url.endsWith("</a>") || url.endsWith("<a")) return url;
 | 
					 | 
				
			||||||
            return `<a href="${url}" target="_blank">${url}</a>`;
 | 
					 | 
				
			||||||
        })
 | 
					 | 
				
			||||||
        .replace(emailRegex, email => {
 | 
					 | 
				
			||||||
            return `<a href="mailto:${email}">${email}</a>`;
 | 
					 | 
				
			||||||
        });
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const rewriteDescription = text => {
 | 
					export const rewriteDescription = text => {
 | 
				
			||||||
    return urlify(text)
 | 
					    return linkifyHtml(text)
 | 
				
			||||||
        .replaceAll(/(?:http(?:s)?:\/\/)?(?:www\.)?youtube\.com(\/[/a-zA-Z0-9_?=&-]*)/gm, "$1")
 | 
					        .replaceAll(/(?:http(?:s)?:\/\/)?(?:www\.)?youtube\.com(\/[/a-zA-Z0-9_?=&-]*)/gm, "$1")
 | 
				
			||||||
        .replaceAll(/(?:http(?:s)?:\/\/)?(?:www\.)?youtu\.be\/(?:watch\?v=)?([/a-zA-Z0-9_?=&-]*)/gm, "/watch?v=$1")
 | 
					        .replaceAll(/(?:http(?:s)?:\/\/)?(?:www\.)?youtu\.be\/(?:watch\?v=)?([/a-zA-Z0-9_?=&-]*)/gm, "/watch?v=$1")
 | 
				
			||||||
        .replaceAll("\n", "<br>");
 | 
					        .replaceAll("\n", "<br>");
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue