Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 36 additions & 8 deletions assets/sass/global.scss
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you revert the changes to this file?

Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@
body {
color: var(--text-color);
background: var(--background-color);
font-family:
"Helvetica Neue",
"Segoe UI",
"Noto Sans",
Helvetica,
Arial,
font-family: "Helvetica Neue", "Segoe UI", "Noto Sans", Helvetica, Arial,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a number of formatting changes in this PR. Why did this change?

sans-serif;
font-size: 20px;
line-height: 2em;
Expand All @@ -22,18 +17,30 @@ a {
color: var(--accent-color);
}

a:hover, a:active {
a:hover,
a:active {
text-decoration: underline;
}

pre, code {
pre,
code {
font-family: Monaco, "Ubuntu Mono", Inconsolata, Consolas, monospace;
}

pre {
line-height: 1.4em;

margin: 20px 0 !important; // remove ALL outside spacing
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you make this work without '!important` anywhere in the CSS?

padding: 0 !important; // remove ALL inside spacing
}

pre > code {
margin: 0 !important; // remove internal margin
padding: 16px !important; // remove internal padding
display: block !important;
}


strong {
font-weight: bold;
}
Expand All @@ -58,3 +65,24 @@ em {
transform: translateY(0%);
}
}


.copy-code-button {
position: absolute;
top: 6px;
right: 6px;
padding: 0;
font-size: 12px;

background: transparent !important;
border: none !important;
box-shadow: none !important;
outline: none !important;

cursor: pointer;
}

.copy-code-button span {
font-size: 16px;
background: transparent !important;
}
9 changes: 9 additions & 0 deletions layouts/_default/baseof.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
<meta name="twitter:card" content="summary" />

<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<link
href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than load everything from Google Fonts, could you only include the icons that are actually used?

Also, could you make sure that the icons are free license?

rel="stylesheet"
/>

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: could you remove this newline?

</head>
<body>
<a class="skip-to-content-link" href="#main">
Expand All @@ -45,6 +50,10 @@ <h1><a href="/">Helmet.js</a></h1>
<main id="main" class="container">
{{ block "main" . }}{{ end }}
</div>
<link rel="stylesheet" href="/css/copy-code.css">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this just be part of the main CSS instead of a new file?

<script src="/js/copy-code.js" defer></script>


</body>
</html>

45 changes: 45 additions & 0 deletions static/css/copy-code.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
pre {
position: relative !important;
padding-top: 2em;
overflow-x: auto;
}

.copy-code-button {
position: absolute !important;
top: 12px;
right: 12px;
width: 16px;
height: 16px;
padding: 0;
display: flex;
align-items: center;
justify-content: center;
font-size: 10px;
line-height: 1;
background: rgba(255, 255, 255, 0.06);
border: 1px solid rgba(255, 255, 255, 0.15);
border-radius: 4px;
color: #fff;
cursor: pointer;
z-index: 300;
transition: all 0.15s ease;
}

.copy-code-button:hover {
background: rgba(255, 255, 255, 0.18);
transform: scale(1.05);
}

.copy-code-button:active {
transform: scale(0.85);
}

pre code {
display: block;
padding: 1em;
padding-top: 0;
margin: 0;
background: none;
position: static !important;
overflow-x: auto;
}
38 changes: 38 additions & 0 deletions static/js/copy-code.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
(function () {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This IIFE wrapper is unnecessary.

document.addEventListener("DOMContentLoaded", () => {
const blocks = document.querySelectorAll(
"pre > code.language-js, pre > code.language-javascript"
);

blocks.forEach((code) => {
const pre = code.parentElement;
pre.style.position = "relative";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can't this be done in the CSS?


const btn = document.createElement("button");
btn.className = "copy-code-button";
btn.innerHTML =
'<span class="material-symbols-outlined">content_copy</span>';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I worry that this text is not accessible to screen readers. Could you make sure that it is? Same comment applies elsewhere in this file.


pre.appendChild(btn);

btn.addEventListener("click", async () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If someone double clicks, timeouts might overlap and cause UI jank. Could you address that?

try {
await navigator.clipboard.writeText(code.innerText.trim());
btn.innerHTML =
'<span class="material-symbols-outlined">check</span>';
setTimeout(() => {
btn.innerHTML =
'<span class="material-symbols-outlined">content_copy</span>';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you avoid repeating this in 3 places?

}, 800);
} catch (err) {
btn.innerHTML =
'<span class="material-symbols-outlined">error</span>';
setTimeout(() => {
btn.innerHTML =
'<span class="material-symbols-outlined">content_copy</span>';
}, 800);
}
});
});
});
})();