mirror of https://gitlab.com/curben/blog
				
				
				
			refactor: move creation of 'Copy' button from client to server
* https://github.com/cheeriojs/cheerio#append-content-content-- * cheerio doesn't have .createElement() function - https://code.tutsplus.com/tutorials/jquery-14-released-the-15-new-features-you-must-know--net-8590
This commit is contained in:
		
							parent
							
								
									3dfc57dbbe
								
							
						
					
					
						commit
						cf16dd3e43
					
				|  | @ -0,0 +1,14 @@ | ||||||
|  | // Add "Copy" button to code snippet
 | ||||||
|  | 
 | ||||||
|  | const cheerio = require('cheerio') | ||||||
|  | 
 | ||||||
|  | hexo.extend.filter.register('after_render:html', (str) => { | ||||||
|  |   const $ = cheerio.load(str) | ||||||
|  | 
 | ||||||
|  |   // Avoid duplicate button
 | ||||||
|  |   if ($('button').parent().hasClass('code')) return | ||||||
|  | 
 | ||||||
|  |   $('.code').append('<button class="copy-button">Copy</button>') | ||||||
|  | 
 | ||||||
|  |   return $.html() | ||||||
|  | }) | ||||||
|  | @ -6,17 +6,6 @@ searchClick.onclick = function() { | ||||||
|   '&group_id=&project_id=8306723&search_code=true&repository_ref=master') |   '&group_id=&project_id=8306723&search_code=true&repository_ref=master') | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // Add "Copy" button to code snippet
 |  | ||||||
| const code = document.getElementsByClassName('code') |  | ||||||
| 
 |  | ||||||
| Array.from(code).forEach((element) => { |  | ||||||
|   const button = document.createElement('button') |  | ||||||
|   button.className = 'copy-button' |  | ||||||
|   button.textContent = 'Copy' |  | ||||||
| 
 |  | ||||||
|   element.appendChild(button) |  | ||||||
| }) |  | ||||||
| 
 |  | ||||||
| /* | /* | ||||||
| * Copy button and Cloudinary functions. | * Copy button and Cloudinary functions. | ||||||
| * Following functions only execute after | * Following functions only execute after | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue