|
1 | 1 | ---
|
2 | 2 | layout: default
|
3 | 3 | ---
|
| 4 | + |
4 | 5 | {% assign date = page.updated | default: page.date %}
|
5 | 6 | <main class="container post" id="main" role="main">
|
6 | 7 | <header class="post-header" role="header">
|
@@ -31,12 +32,38 @@ <h6 class="post-meta">
|
31 | 32 | document
|
32 | 33 | .querySelector('.post-content')
|
33 | 34 | .querySelectorAll('h1,h2,h3,h4,h5,h6')
|
34 |
| - .forEach(function(heading) { |
| 35 | + .forEach(function (heading) { |
35 | 36 | if (heading.id)
|
36 | 37 | heading.innerHTML =
|
37 | 38 | '<a href="#' + heading.id + '">' +
|
38 | 39 | heading.innerText +
|
39 | 40 | '<\/a>' +
|
40 | 41 | '<span class="anchor-icon">§<\/span>';
|
41 |
| - }); |
| 42 | + }); |
| 43 | +</script> |
| 44 | +{% comment %} |
| 45 | + |
| 46 | +<!-- Copy code to clipboard --> |
| 47 | +{% endcomment %} |
| 48 | +<script> |
| 49 | + document |
| 50 | + .querySelector('.post-content') |
| 51 | + .querySelectorAll('pre.highlight') |
| 52 | + .forEach(function (pre) { |
| 53 | + var button = document.createElement('button'); |
| 54 | + var copyText = 'Copy'; |
| 55 | + button.className = 'copy'; |
| 56 | + button.type = 'button'; |
| 57 | + button.ariaLabel = 'Copy code to clipboard'; |
| 58 | + button.innerText = copyText; |
| 59 | + button.addEventListener('click', function () { |
| 60 | + var code = pre.querySelector('code').innerText.trim(); |
| 61 | + navigator.clipboard.writeText(code); |
| 62 | + button.innerText = 'Copied'; |
| 63 | + setTimeout(function () { |
| 64 | + button.innerText = copyText; |
| 65 | + }, 4000); |
| 66 | + }); |
| 67 | + pre.appendChild(button); |
| 68 | + }); |
42 | 69 | </script>
|
0 commit comments