Skip to content

Commit 76b1eb7

Browse files
committed
chore(code-window): Enhance copy button and language label
1 parent 2f79405 commit 76b1eb7

File tree

5 files changed

+74
-37
lines changed

5 files changed

+74
-37
lines changed

_plugins/highlight-linedivs.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,19 @@ def render(context)
7373
</g>
7474
</svg>
7575
</div>
76-
<button class=\"window-copy\">
77-
<svg xmlns=\"http://www.w3.org/2000/svg\" height=\"16\" width=\"16\" viewBox=\"0 0 512 512\">
78-
<path d=\"M64 464H288c8.8 0 16-7.2 16-16V384h48v64c0 35.3-28.7 64-64 64H64c-35.3 0-64-28.7-64-64V224c0-35.3 28.7-64 64-64h64v48H64c-8.8 0-16 7.2-16 16V448c0 8.8 7.2 16 16 16zM224 304H448c8.8 0 16-7.2 16-16V64c0-8.8-7.2-16-16-16H224c-8.8 0-16 7.2-16 16V288c0 8.8 7.2 16 16 16zm-64-16V64c0-35.3 28.7-64 64-64H448c35.3 0 64 28.7 64 64V288c0 35.3-28.7 64-64 64H224c-35.3 0-64-28.7-64-64z\"/>
76+
<div class=\"window-copy\">
77+
<svg xmlns=\"http://www.w3.org/2000/svg\" class=\"window-copy-icon\" height=\"24\" width=\"24\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"1.5\">
78+
<path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"></path>
79+
<path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"></path>
7980
</svg>
80-
</button>
81+
</div>
8182
</div>
8283
"
8384
suffix = " " \
8485
"
86+
<div class=\"code-label\">
87+
#{@lang.capitalize}
88+
</div>
8589
</div>
8690
</div>
8791
"

_sass/_highlight.scss

Lines changed: 58 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,23 @@ $background: var(--code-background);
5353
&:hover {
5454
transform: translate(0px, -4px);
5555
box-shadow: 0 10px 50px rgba(var(--shadow-color-flashy), .2);
56-
}
56+
}
57+
}
58+
59+
.code-label {
60+
display: flex;
61+
align-items: flex-end;
62+
padding-bottom: 10px;
63+
padding-right: 20px;
64+
width: 100%;
65+
justify-content: flex-end;
66+
color: #fbfbfb;
67+
//font-size: 14px;
68+
font-family: "Mulish", sans-serif;
69+
font-weight: 800;
70+
opacity: 0.5;
71+
line-height: 1;
72+
position: relative;
5773
}
5874

5975
.window-header {
@@ -70,11 +86,47 @@ $background: var(--code-background);
7086
}
7187

7288
.window-copy {
73-
color: #fbfbfb;
74-
fill: #fbfbfb;
75-
float: right;
76-
margin-right: 14px;
89+
color: #fbfbfb;
90+
float: right;
91+
margin-right: 14px;
92+
cursor: pointer;
93+
94+
.window-copy-icon {
95+
position: absolute;
96+
top: 0;
97+
right: 14px;
98+
left: auto;
99+
border: none;
77100
cursor: pointer;
101+
opacity: 0.5;
102+
transition: opacity 200ms ease-in-out;
103+
background: none;
104+
box-shadow: none;
105+
106+
&:hover {
107+
opacity: 0.8;
108+
}
109+
110+
.without-check {
111+
display: block;
112+
}
113+
114+
.with-check {
115+
display: none;
116+
}
117+
118+
&.copied {
119+
opacity: 1;
120+
121+
.without-check {
122+
display: none;
123+
}
124+
125+
.with-check {
126+
display: block;
127+
}
128+
}
129+
}
78130
}
79131
}
80132

@@ -102,25 +154,6 @@ figure.highlight {
102154
flex: 0 0 auto;
103155
/* Use a counter to generate the line numbers */
104156
counter-reset: code;
105-
106-
/* Display language name */
107-
&[data-lang]::before {
108-
font-family: 'metropolisbold',sans-serif;
109-
color: #f8f8f2;
110-
content: "</>" " " attr(data-lang);
111-
position: absolute;
112-
margin: 0px;
113-
top: -37px;
114-
left: -9px;
115-
width: 100%;
116-
text-align: center;
117-
&[data-lang="zsh"] {
118-
content: "%_ Zsh";
119-
}
120-
&[data-lang="bash"] {
121-
content: "$_ Bash";
122-
}
123-
}
124157

125158
div {
126159
/* Increment the counter for each div */
@@ -129,7 +162,7 @@ figure.highlight {
129162
&:before {
130163
content: counter(code);
131164

132-
/* Hacky, but necessary. Without these lines, single-digit line
165+
/* Hacky, but necessary. Without these lines, single-digit line
133166
/* numbers will not line up with double-digit ones. Change width
134167
/* to suit your font. */
135168
width: 1.8em;

_sass/parts/_post-page.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@
401401
align-items: center;
402402
justify-content: space-between;
403403
margin-top: 50px;
404-
margin-bottom: 50px;
404+
// margin-bottom: 50px;
405405
margin-bottom: 20px;
406406
line-height: 15px;
407407
h4 {

darkmode.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ initDarkMode();
4444

4545
// This assumes that you're using Rouge; if not, update the selector
4646
const codeBlocks = document.querySelectorAll('.highlight');
47-
const copyCodeButtons = document.querySelectorAll('.window-copy');
47+
const copyCodeButtons = document.querySelectorAll('.window-copy-icon');
4848

4949
copyCodeButtons.forEach((copyCodeButton, index) => {
5050
const code = codeBlocks[index].innerText;
@@ -54,16 +54,16 @@ copyCodeButtons.forEach((copyCodeButton, index) => {
5454
window.navigator.clipboard.writeText(code);
5555

5656
// Update the button text visually
57-
const { innerHTML: originalText } = copyCodeButton;
58-
copyCodeButton.innerText = 'Copied!';
57+
////const { innerHTML: originalText } = copyCodeButton;
58+
////copyCodeButton.innerText = 'Copied!';
5959

6060
// (Optional) Toggle a class for styling the button
61-
//copyCodeButton.classList.add('copied');
61+
copyCodeButton.classList.add('copied');
6262

6363
// After 2 seconds, reset the button to its initial UI
6464
setTimeout(() => {
65-
copyCodeButton.innerHTML = originalText;
66-
//copyCodeButton.classList.remove('copied');
65+
////copyCodeButton.innerHTML = originalText;
66+
copyCodeButton.classList.remove('copied');
6767
}, 1000);
6868
});
6969
});

darkmode.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)