Skip to content

Commit 62975f8

Browse files
committed
added copy code button functionality
1 parent bfb7a7f commit 62975f8

20 files changed

Lines changed: 186 additions & 224 deletions

blog.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ <h2 class="section-heading">Filter by Technology</h2>
374374
</div>
375375
<footer class="page-footer">
376376
<div class="container">
377-
<p>© 2025 Mit Patel. All rights reserved.</p>
377+
<p>© 2026 Mit Patel. All rights reserved.</p>
378378
</div>
379379

380380
<script>

contact.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ <h3 class="contact-subheading">Send Me An Email</h3>
168168

169169
<footer class="page-footer">
170170
<div class="container">
171-
<p>© 2025 Mit Patel. All rights reserved.</p>
171+
<p>© 2026 Mit Patel. All rights reserved.</p>
172172
</div>
173173
</footer>
174174

css/post.css

Lines changed: 114 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,92 @@
11
/* Main content area for the article */
22
.post-content-main {
3-
padding: 2rem;
3+
padding: 2rem;
44
}
55

66
/* Headings within the article */
77
.post-content-main h1 {
8-
font-size: 2.5rem; /* Main title of the article if used */
9-
margin: 0 0 1rem 0;
8+
font-size: 2.5rem;
9+
/* Main title of the article if used */
10+
margin: 0 0 1rem 0;
1011
}
12+
1113
.post-content-main h2 {
12-
border-bottom: 1px solid var(--border-color);
13-
/* Other heading styles remain the same */
14-
font-size: 1.8rem;
15-
margin-top: 2rem;
16-
padding-bottom: 0.5rem;
14+
border-bottom: 1px solid var(--border-color);
15+
/* Other heading styles remain the same */
16+
font-size: 1.8rem;
17+
margin-top: 2rem;
18+
padding-bottom: 0.5rem;
1719
}
20+
1821
.post-content-main h3 {
19-
font-size: 1.4rem;
20-
margin-top: 1.5rem;
22+
font-size: 1.4rem;
23+
margin-top: 1.5rem;
2124
}
2225

2326
/* Paragraphs */
2427
.post-content-main p {
25-
line-height: 1.7;
28+
line-height: 1.7;
2629
}
2730

2831
/* For Unordered Lists (bullet points) */
2932
.post-content-main ul {
30-
list-style-type: disc;
31-
padding-left: 40px;
32-
margin-top: 0.5em;
33-
margin-bottom: 1em;
33+
list-style-type: disc;
34+
padding-left: 40px;
35+
margin-top: 0.5em;
36+
margin-bottom: 1em;
3437
}
38+
3539
.post-content-main li {
36-
margin-bottom: 0.5em;
37-
padding-left: 5px;
40+
margin-bottom: 0.5em;
41+
padding-left: 5px;
3842
}
3943

4044
/* For Code Blocks (already uses dark background, let's refine for light theme) */
4145
.post-content-main pre {
42-
background-color: var(--code-bg-color); /* This stays dark for contrast in both themes */
43-
color: var(--code-text-color);
44-
padding: 1.5rem;
45-
border-radius: 8px;
46-
overflow-x: auto;
47-
font-family: 'Courier New', Courier, monospace;
48-
font-size: 0.9em;
49-
line-height: 1.5;
50-
margin: 1.5em 0;
46+
background-color: var(--code-bg-color);
47+
/* This stays dark for contrast in both themes */
48+
color: var(--code-text-color);
49+
padding: 1.5rem;
50+
border-radius: 8px;
51+
overflow-x: auto;
52+
font-family: 'Courier New', Courier, monospace;
53+
font-size: 0.9em;
54+
line-height: 1.5;
55+
margin: 1.5em 0;
56+
position: relative;
5157
}
5258

5359
.post-content-main pre code {
54-
padding: 0;
55-
background: none;
56-
color: inherit;
60+
padding: 0;
61+
background: none;
62+
color: inherit;
5763
}
5864

5965
/* For inline code snippets, now theme-aware */
60-
.post-content-main p > code, .post-content-main li > code {
61-
background-color: var(--tag-bg-color); /* Use the tag background color */
62-
color: var(--tag-text-color); /* Use the tag text color */
63-
padding: 3px 6px;
64-
border-radius: 4px;
65-
font-family: 'Courier New', Courier, monospace;
66+
.post-content-main p>code,
67+
.post-content-main li>code {
68+
background-color: var(--tag-bg-color);
69+
/* Use the tag background color */
70+
color: var(--tag-text-color);
71+
/* Use the tag text color */
72+
padding: 3px 6px;
73+
border-radius: 4px;
74+
font-family: 'Courier New', Courier, monospace;
6675
}
6776

6877
/* For images */
6978
.post-content-main img {
70-
max-width: 100%;
71-
height: auto;
72-
border-radius: 8px;
73-
margin: 2em 0;
79+
max-width: 100%;
80+
height: auto;
81+
border-radius: 8px;
82+
margin: 2em 0;
7483
}
7584

7685
/* Ensure the tags in the sidebar stack nicely */
7786
aside .tech-stack {
78-
display: flex;
79-
flex-wrap: wrap;
80-
gap: 0.5rem;
87+
display: flex;
88+
flex-wrap: wrap;
89+
gap: 0.5rem;
8190
}
8291

8392
/* ===== PREVIOUS / NEXT POST NAVIGATION ===== */
@@ -87,7 +96,8 @@ aside .tech-stack {
8796
margin-top: 2rem;
8897
padding-top: 2rem;
8998
border-top: 1px solid var(--border-color);
90-
grid-column: 1 / -1; /* This makes it span both columns */
99+
grid-column: 1 / -1;
100+
/* This makes it span both columns */
91101
}
92102

93103
.nav-link {
@@ -130,56 +140,70 @@ aside .tech-stack {
130140
justify-content: flex-end;
131141
}
132142

133-
/* ===== PRISMJS COPY-TO-CLIPBOARD BUTTON STYLING ===== */
134-
div.code-toolbar {
135-
position: relative;
136-
}
137-
138-
div.code-toolbar > .toolbar {
143+
/* ===== CUSTOM COPY-TO-CLIPBOARD BUTTON STYLING ===== */
144+
.copy-code-btn {
139145
position: absolute;
140146
top: 0.5rem;
141147
right: 0.5rem;
142-
transition: opacity 0.3s ease-in-out;
143-
opacity: 0;
148+
padding: 0.4rem;
149+
background: transparent;
150+
color: var(--code-text-color);
151+
/* Contrasts with code block background */
152+
border: none;
153+
font-size: 1.1rem;
154+
cursor: pointer;
155+
opacity: 0.7;
156+
/* Always clearly visible */
157+
transition: opacity 0.2s, color 0.2s, background-color 0.2s;
158+
border-radius: 4px;
144159
}
145160

146-
div.code-toolbar:hover > .toolbar {
161+
.post-content-main pre:hover .copy-code-btn {
147162
opacity: 1;
148163
}
149164

150-
.toolbar-item > .copy-to-clipboard-button {
151-
cursor: pointer;
152-
padding: 0.5rem 0.75rem;
153-
background: #555;
154-
color: #f0f0f0;
155-
border: 1px solid var(--border-color);
156-
border-radius: 6px;
157-
font-family: sans-serif;
158-
font-size: 0.8em;
159-
transition: background-color 0.2s;
160-
}
161-
162-
.toolbar-item > .copy-to-clipboard-button:hover {
163-
background-color: #777;
165+
.copy-code-btn:hover {
166+
background-color: rgba(128, 128, 128, 0.3);
164167
}
165168

166-
.toolbar-item > .copy-to-clipboard-button:active {
167-
background-color: var(--link-color);
169+
.copy-code-btn.copied {
170+
color: var(--link-color);
171+
opacity: 1;
168172
}
169173

170-
.toolbar-item > .copy-to-clipboard-button[data-copy-state="copy"]::after {
171-
content: 'Copy';
174+
/* ===== TOAST NOTIFICATION ===== */
175+
.toast-notification {
176+
visibility: hidden;
177+
min-width: 200px;
178+
background-color: var(--text-color);
179+
color: var(--bg-color);
180+
text-align: center;
181+
border-radius: 8px;
182+
padding: 12px 16px;
183+
position: fixed;
184+
z-index: 1000;
185+
left: 30px;
186+
bottom: 30px;
187+
font-size: 0.9rem;
188+
font-weight: 600;
189+
box-shadow: 0px 4px 12px rgba(0, 0, 0, 0.15);
190+
transition: visibility 0.3s, opacity 0.3s, transform 0.3s;
191+
opacity: 0;
192+
transform: translateY(20px);
172193
}
173194

174-
.toolbar-item > .copy-to-clipboard-button[data-copy-state="copied"]::after {
175-
content: 'Copied!';
195+
.toast-notification.show {
196+
visibility: visible;
197+
opacity: 1;
198+
transform: translateY(0);
176199
}
177200

178201
/* ===== GITHUB BUTTON IN POST SIDEBAR ===== */
179202
.sidebar-button {
180203
display: inline-block;
181204
width: 100%;
182-
box-sizing: border-box; /* Ensures padding is included in the width */
205+
box-sizing: border-box;
206+
/* Ensures padding is included in the width */
183207
margin-top: 1rem;
184208
padding: 10px 15px;
185209
background-color: var(--card-bg-color);
@@ -204,26 +228,27 @@ div.code-toolbar:hover > .toolbar {
204228

205229
/* ===== BLOG POST SERIES BOX IN SIDEBAR ===== */
206230
.series-navigation-sidebar {
207-
padding: 1.25rem;
208-
margin-bottom: 2rem;
209-
border: 1px solid var(--border-color);
210-
background-color: var(--card-bg-color);
211-
border-radius: 8px;
212-
text-align: center;
213-
border-left: 4px solid var(--aside-accent-color);
231+
padding: 1.25rem;
232+
margin-bottom: 2rem;
233+
border: 1px solid var(--border-color);
234+
background-color: var(--card-bg-color);
235+
border-radius: 8px;
236+
text-align: center;
237+
border-left: 4px solid var(--aside-accent-color);
214238
}
215239

216240
.series-navigation-sidebar h4 {
217-
margin-top: 0;
218-
margin-bottom: 1rem;
219-
font-size: 1rem;
220-
font-weight: 600;
241+
margin-top: 0;
242+
margin-bottom: 1rem;
243+
font-size: 1rem;
244+
font-weight: 600;
221245
}
222246

223247
.series-navigation-sidebar .series-link {
224-
display: block; /* Stack the links vertically if both are present */
225-
margin: 0.5rem 0;
226-
font-weight: 600;
227-
text-decoration: none;
228-
color: var(--link-color) !important;
248+
display: block;
249+
/* Stack the links vertically if both are present */
250+
margin: 0.5rem 0;
251+
font-weight: 600;
252+
text-decoration: none;
253+
color: var(--link-color) !important;
229254
}

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ <h3 class="competency-title-sidebar">Applied Natural Language Processing (NLP)</
282282

283283
<footer class="page-footer">
284284
<div class="container">
285-
<p>© 2025 Mit Patel. All rights reserved.</p>
285+
<p>© 2026 Mit Patel. All rights reserved.</p>
286286
</div>
287287
</footer>
288288

js/app.js

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,65 @@ document.addEventListener('DOMContentLoaded', function () {
2121
applyTheme(savedTheme);
2222

2323
// Listen for toggle clicks
24-
themeToggle.addEventListener('click', function() {
24+
themeToggle.addEventListener('click', function () {
2525
const currentTheme = localStorage.getItem('theme') || 'light';
2626
const newTheme = (currentTheme === 'dark') ? 'light' : 'dark';
2727
applyTheme(newTheme);
2828
});
29+
30+
// Custom Copy to Clipboard for Code Blocks
31+
const codeBlocks = document.querySelectorAll('pre');
32+
33+
// Create Toast Element for notification
34+
const toast = document.createElement('div');
35+
toast.className = 'toast-notification';
36+
toast.innerText = 'Copied to clipboard';
37+
document.body.appendChild(toast);
38+
39+
codeBlocks.forEach(block => {
40+
// Create the copy button using an icon
41+
const copyButton = document.createElement('button');
42+
copyButton.className = 'copy-code-btn';
43+
copyButton.innerHTML = '<i class="far fa-copy"></i>';
44+
copyButton.setAttribute('aria-label', 'Copy code to clipboard');
45+
46+
// Add the button to the pre block
47+
block.appendChild(copyButton);
48+
49+
// Add the click event listener
50+
copyButton.addEventListener('click', () => {
51+
const code = block.querySelector('code');
52+
let textToCopy = '';
53+
54+
if (code) {
55+
textToCopy = code.innerText;
56+
} else {
57+
// Remove the button from the copied text if no inner code tag is found
58+
const clone = block.cloneNode(true);
59+
const btn = clone.querySelector('.copy-code-btn');
60+
if (btn) clone.removeChild(btn);
61+
textToCopy = clone.innerText;
62+
}
63+
64+
navigator.clipboard.writeText(textToCopy).then(() => {
65+
// Show toast notification
66+
toast.classList.add('show');
67+
68+
// Change icon to a checkmark
69+
copyButton.innerHTML = '<i class="fas fa-check"></i>';
70+
copyButton.classList.add('copied');
71+
72+
setTimeout(() => {
73+
// Hide toast and revert icon
74+
toast.classList.remove('show');
75+
copyButton.innerHTML = '<i class="far fa-copy"></i>';
76+
copyButton.classList.remove('copied');
77+
}, 2500);
78+
}).catch(err => {
79+
console.error('Failed to copy text: ', err);
80+
});
81+
});
82+
});
2983
});
3084

3185

0 commit comments

Comments
 (0)