Skip to content

Commit 6d92742

Browse files
committed
added copy code button
1 parent 7a15e38 commit 6d92742

16 files changed

+35
-32
lines changed

assets/js/copybutton.js

+11-23
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ function addCopyButtonToCodeBlocks() {
2828

2929

3030
// Get all code blocks with a class of "language-*"
31-
3231
const codeBlocks = document.querySelectorAll(
3332
'pre > code[class^="language-"]'
3433
);
@@ -38,35 +37,32 @@ function addCopyButtonToCodeBlocks() {
3837

3938
// For each code block, add a copy button inside a header
4039
codeBlocks.forEach((codeBlock) => {
41-
4240
// Get the background color of the code block
4341
const computedStyle = window.getComputedStyle(codeBlock);
44-
const backgroundColor = computedStyle.backgroundColor;
45-
46-
42+
// const backgroundColor = computedStyle.backgroundColor;
43+
const backgroundColor = "#455F92";
44+
4745
// Adjust the header color to be significantly lighter or darker than the background color
48-
49-
const headerColor = isColorDark(backgroundColor)
50-
? adjustColorBrightness(backgroundColor, 65)
51-
: adjustColorBrightness(backgroundColor, -65);
52-
const textColor = isColorDark(backgroundColor) ? "#d1d1d1" : "#606060";
46+
// const headerColor = isColorDark(backgroundColor)
47+
const headerColor = "#455F92";
48+
// ? adjustColorBrightness(backgroundColor, 65)
49+
// : adjustColorBrightness(backgroundColor, -65);
50+
const textColor = isColorDark(backgroundColor) ? "#e6e6e6" : "#e6e6e6";
5351

5452

5553
// Create the header div
5654

5755
const header = document.createElement("div");
5856

5957
header.style.backgroundColor = headerColor;
60-
6158
header.style.display = "flex";
62-
6359
header.style.justifyContent = "space-between";
64-
6560
header.style.alignItems = "center";
6661
header.style.paddingRight = "0.5rem";
6762
header.style.paddingLeft = "0.5rem";
68-
header.style.borderTopLeftRadius = "5px";
69-
header.style.borderTopRightRadius = "5px";
63+
header.style.borderTopLeftRadius = "18px";
64+
header.style.borderTopRightRadius = "0px";
65+
header.style.marginTop = "5px";
7066

7167
header.style.color = textColor;
7268

@@ -78,21 +74,13 @@ function addCopyButtonToCodeBlocks() {
7874
// Create the copy button
7975

8076
const copyButton = document.createElement("button");
81-
8277
copyButton.classList.add("btn", "copy-code-button");
83-
8478
copyButton.style.background = "none";
85-
8679
copyButton.style.border = "none";
87-
8880
copyButton.style.color = textColor;
89-
9081
copyButton.style.fontSize = "100%"; // Override the font size
91-
9282
copyButton.style.cursor = "pointer";
93-
9483
copyButton.innerHTML = copyIcon;
95-
9684
copyButton.style.marginLeft = "auto";
9785

9886

assets/styles/components/misc.scss

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
}
1818

1919
pre {
20-
margin: 5px;
20+
margin: 2px;
2121
border-bottom-right-radius: 18px;
2222

2323
& > code {
@@ -79,3 +79,4 @@ html[data-theme='dark'] {
7979
}
8080
}
8181
}
82+

public/application.b75fd7db826474d1a95fad8a5aec65f60f4e668ee19f6012e8a4af47b191edd3.css

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/application.css.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
1717
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
1818

19-
<link rel="stylesheet" href="/application.48fbd910ec2bdab3c57b60f2698483acf3bb5786ccfa4b11960e2eb1117c6b89.css" integrity="sha256-SPvZEOwr2rPFe2DyaYSDrPO7V4bM&#43;ksRlg4usRF8a4k=" />
19+
<link rel="stylesheet" href="/application.b75fd7db826474d1a95fad8a5aec65f60f4e668ee19f6012e8a4af47b191edd3.css" integrity="sha256-t1/X24JkdNGpX62KWuxl9g9OZo7hn2AS6KSvR7GR7dM=" />
2020

2121

2222

public/js/copybutton.min.1d27bb725f595a043eea7a624116c855a7e07b513864caaec1dcbe6d38464e1a.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/js/copybutton.min.31334c0f2bc4c91a74f48f2ed3a38f7a165adff984aa26ee332783fde0b50eaf.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/js/copybutton.min.3c9b339cc6cbcc3f8c5a6aecc35be316b58b152030dd6e90428f2728481378ac.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/js/copybutton.min.468974aaccbcf5a233b6ba6a4b83aca99e303d0a65a57f5bcf0e8a2a44e9e6c6.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/js/copybutton.min.608f75dc2cc75e4b968d3472ab640b15b0b986a3bf6405a77c92f8eb207e1c16.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/js/copybutton.min.7ca29f46a01bda9f536481c0615a1a47a18e4090dd9aaca16d9d0cfdccd1cfc7.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/js/copybutton.min.d7d606d3788580985641cb9333f5789cf7c5c5af2259b26f411f0c1a3f24ede3.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/posts/index.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
77
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
88

9-
<link rel="stylesheet" href="/application.48fbd910ec2bdab3c57b60f2698483acf3bb5786ccfa4b11960e2eb1117c6b89.css" integrity="sha256-SPvZEOwr2rPFe2DyaYSDrPO7V4bM&#43;ksRlg4usRF8a4k=" />
9+
<link rel="stylesheet" href="/application.b75fd7db826474d1a95fad8a5aec65f60f4e668ee19f6012e8a4af47b191edd3.css" integrity="sha256-t1/X24JkdNGpX62KWuxl9g9OZo7hn2AS6KSvR7GR7dM=" />
1010

1111

1212

@@ -1092,5 +1092,5 @@ <h5 class="card-title"></h5>
10921092

10931093

10941094

1095-
<script src="http://localhost:1313/js/copybutton.min.a48e6828da436de32d10a615cb3004fd3348a7da47c661db91071e2b87a4294a.js" integrity="sha256-pI5oKNpDbeMtEKYVyzAE/TNIp9pHxmHbkQceK4ekKUo=" defer></script>
1095+
<script src="http://localhost:1313/js/copybutton.min.608f75dc2cc75e4b968d3472ab640b15b0b986a3bf6405a77c92f8eb207e1c16.js" integrity="sha256-YI913CzHXkuWjTRyq2QLFbC5hqO/ZAWnfJL46yB&#43;HBY=" defer></script>
10961096

public/posts/machine-learning/deep-learning/nlp/gemma2+rag/index.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
77
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
88

9-
<link rel="stylesheet" href="/application.48fbd910ec2bdab3c57b60f2698483acf3bb5786ccfa4b11960e2eb1117c6b89.css" integrity="sha256-SPvZEOwr2rPFe2DyaYSDrPO7V4bM&#43;ksRlg4usRF8a4k=" />
9+
<link rel="stylesheet" href="/application.b75fd7db826474d1a95fad8a5aec65f60f4e668ee19f6012e8a4af47b191edd3.css" integrity="sha256-t1/X24JkdNGpX62KWuxl9g9OZo7hn2AS6KSvR7GR7dM=" />
1010

1111

1212

@@ -1284,5 +1284,5 @@ <h5 class="text-center ps-3">Table of Contents</h5>
12841284

12851285

12861286

1287-
<script src="http://localhost:1313/js/copybutton.min.a48e6828da436de32d10a615cb3004fd3348a7da47c661db91071e2b87a4294a.js" integrity="sha256-pI5oKNpDbeMtEKYVyzAE/TNIp9pHxmHbkQceK4ekKUo=" defer></script>
1287+
<script src="http://localhost:1313/js/copybutton.min.608f75dc2cc75e4b968d3472ab640b15b0b986a3bf6405a77c92f8eb207e1c16.js" integrity="sha256-YI913CzHXkuWjTRyq2QLFbC5hqO/ZAWnfJL46yB&#43;HBY=" defer></script>
12881288

resources/_gen/assets/styles/application.template.scss_d14e3134243a7799c63301d3787f4708.content

+1-1
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"Target":"application.48fbd910ec2bdab3c57b60f2698483acf3bb5786ccfa4b11960e2eb1117c6b89.css","MediaType":"text/css","Data":{"Integrity":"sha256-SPvZEOwr2rPFe2DyaYSDrPO7V4bM+ksRlg4usRF8a4k="}}
1+
{"Target":"application.b75fd7db826474d1a95fad8a5aec65f60f4e668ee19f6012e8a4af47b191edd3.css","MediaType":"text/css","Data":{"Integrity":"sha256-t1/X24JkdNGpX62KWuxl9g9OZo7hn2AS6KSvR7GR7dM="}}

0 commit comments

Comments
 (0)