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:
curben 2019-05-25 19:46:35 +09:30
parent 3dfc57dbbe
commit cf16dd3e43
2 changed files with 14 additions and 11 deletions

View File

@ -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()
})

View File

@ -6,17 +6,6 @@ searchClick.onclick = function() {
'&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.
* Following functions only execute after