Skip to content

Commit fc20716

Browse files
committed
fix broken linkedin and copy link buttons
1 parent bb4ed14 commit fc20716

7 files changed

Lines changed: 319 additions & 20 deletions

File tree

‎.makim.yaml‎

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,25 @@ groups:
2020
# 2) Convert .qmd blog posts to Markdown using Quarto
2121
# Run quarto render from inside each blog folder (Quarto rejects --output path).
2222
if ! command -v quarto >/dev/null 2>&1; then
23-
echo "[EE] Quarto CLI is required but not found on PATH. Install it (e.g. conda install quarto) and retry."
24-
exit 1
25-
fi
26-
mapfile -d "" qmd_files < <(find "$SEARCH_DIR" -name "*.qmd" -print0)
27-
for qmd_path in "${qmd_files[@]}"; do
28-
dir=$(dirname "$qmd_path")
29-
base=$(basename "$qmd_path" .qmd)
30-
(
31-
cd "$dir"
32-
quarto render "$base.qmd" --to gfm -M template=default
33-
)
34-
done
23+
echo "[WW] Quarto CLI not found on PATH. Skipping .qmd rendering and using existing Markdown files."
24+
else
25+
mapfile -d "" qmd_files < <(find "$SEARCH_DIR" -name "*.qmd" -print0)
26+
for qmd_path in "${qmd_files[@]}"; do
27+
dir=$(dirname "$qmd_path")
28+
base=$(basename "$qmd_path" .qmd)
29+
(
30+
cd "$dir"
31+
quarto render "$base.qmd" --to gfm -M template=default
32+
)
33+
done
3534
36-
# 3) Ensure generated index.md have YAML from .qmd (Quarto may drop it)
37-
python scripts/inject-qmd-yaml-into-md.py
35+
# 3) Ensure generated index.md have YAML from .qmd (Quarto may drop it)
36+
python scripts/inject-qmd-yaml-into-md.py
3837
39-
# 4) Remove console colors from generated md files
40-
find "$SEARCH_DIR" -name "index.md" -exec sh -c \
41-
'cat "$(dirname "$0")/index.md" | python scripts/clean-output.py > "$(dirname "$0")/temp_index.md" && mv "$(dirname "$0")/temp_index.md" "$(dirname "$0")/index.md"' {} \;
38+
# 4) Remove console colors from generated md files
39+
find "$SEARCH_DIR" -name "index.md" -exec sh -c \
40+
'cat "$(dirname "$0")/index.md" | python scripts/clean-output.py > "$(dirname "$0")/temp_index.md" && mv "$(dirname "$0")/temp_index.md" "$(dirname "$0")/index.md"' {} \;
41+
fi
4242
4343
build:
4444
help: build the static page

‎scripts/check-broken-links-md.py‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import os
66
import subprocess
7+
import sys
78

89
# List of exception URLs
910
exception_urls = [
@@ -18,7 +19,16 @@ def process_log() -> None:
1819

1920
try:
2021
subprocess.run(
21-
["python", "-m", "linkcheckmd", "-r", "-v", "-m", "get", "pages"],
22+
[
23+
sys.executable,
24+
"-m",
25+
"linkcheckmd",
26+
"-r",
27+
"-v",
28+
"-m",
29+
"get",
30+
"pages",
31+
],
2232
stdout=subprocess.PIPE,
2333
stderr=subprocess.PIPE,
2434
text=True,

‎tests/test_share_and_copy_link.py‎

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
"""Test LinkedIn share and Copy Link markup."""
2+
3+
from __future__ import annotations
4+
5+
import unittest
6+
7+
from pathlib import Path
8+
9+
from bs4 import BeautifulSoup
10+
11+
12+
class TestShareAndCopyLinks(unittest.TestCase):
13+
"""Test LinkedIn share and Copy Link in templates and output."""
14+
15+
def setUp(self) -> None:
16+
"""Set up test paths."""
17+
self.root = Path(__file__).resolve().parents[1]
18+
self.theme_dir = self.root / "theme"
19+
20+
def test_blog_post_template_markup(self) -> None:
21+
"""Verify blog-post.html has correct LinkedIn and Copy Link tags."""
22+
template_file = self.theme_dir / "blog-post.html"
23+
self.assertTrue(template_file.exists())
24+
content = template_file.read_text(encoding="utf-8")
25+
26+
# Check LinkedIn share URL endpoint
27+
expected_endpoint = (
28+
"https://www.linkedin.com/sharing/share-offsite/"
29+
"?url={{ page.canonical_url or url }}"
30+
)
31+
self.assertIn(expected_endpoint, content)
32+
self.assertNotIn('href="#linkedinshare"', content)
33+
34+
# Check target and rel
35+
self.assertIn('target="_blank"', content)
36+
self.assertIn('rel="nofollow noopener"', content)
37+
38+
# Check Copy Link button
39+
self.assertIn('class="link link_yank"', content)
40+
self.assertIn('href="{{ page.canonical_url or url }}"', content)
41+
42+
def test_blog_list_template_markup(self) -> None:
43+
"""Verify blog-list.html has correct LinkedIn and Copy Link tags."""
44+
template_file = self.theme_dir / "blog-list.html"
45+
self.assertTrue(template_file.exists())
46+
content = template_file.read_text(encoding="utf-8")
47+
48+
# Check LinkedIn share URL endpoint
49+
expected_endpoint = (
50+
"https://www.linkedin.com/sharing/share-offsite/?url={{ url }}"
51+
)
52+
self.assertIn(expected_endpoint, content)
53+
self.assertNotIn('href="#linkedinshare"', content)
54+
55+
# Check target and rel
56+
self.assertIn('target="_blank"', content)
57+
self.assertIn('rel="nofollow noopener"', content)
58+
59+
# Check Copy Link button
60+
self.assertIn('class="link link_yank"', content)
61+
self.assertIn('href="{{ url }}"', content)
62+
63+
def test_theme_js_copy_link_handler(self) -> None:
64+
"""Verify theme.js has click handler for .link_yank and feedback."""
65+
js_file = self.theme_dir / "js" / "theme.js"
66+
self.assertTrue(js_file.exists())
67+
content = js_file.read_text(encoding="utf-8")
68+
69+
self.assertIn(".link_yank", content)
70+
self.assertIn("preventDefault", content)
71+
self.assertIn("writeText", content)
72+
self.assertIn("copy-tooltip", content)
73+
self.assertIn("Copied!", content)
74+
self.assertIn("execCommand", content)
75+
76+
def test_blog_css_copy_link_styles(self) -> None:
77+
"""Verify blog.css styles .link_yank, .copied, and .copy-tooltip."""
78+
css_file = self.theme_dir / "css" / "blog.css"
79+
self.assertTrue(css_file.exists())
80+
content = css_file.read_text(encoding="utf-8")
81+
82+
self.assertIn(".link_yank", content)
83+
self.assertIn(".link_yank.copied", content)
84+
self.assertIn(".copy-tooltip", content)
85+
86+
def test_rendered_blog_list_html(self) -> None:
87+
"""Verify rendered blog/index.html elements."""
88+
build_html = self.root / "build" / "blog" / "index.html"
89+
if not build_html.exists():
90+
return
91+
92+
soup = BeautifulSoup(
93+
build_html.read_text(encoding="utf-8"), "html.parser"
94+
)
95+
post_cards = soup.find_all("li", class_="post-card")
96+
self.assertGreater(len(post_cards), 0)
97+
98+
for card in post_cards:
99+
share = card.find("div", class_="post_share")
100+
self.assertIsNotNone(share)
101+
102+
# LinkedIn button
103+
linkedin = share.find("a", class_="linkedin")
104+
self.assertIsNotNone(linkedin)
105+
href = linkedin.get("href", "")
106+
share_prefix = (
107+
"https://www.linkedin.com/sharing/share-offsite/?url="
108+
)
109+
self.assertTrue(
110+
href.startswith(share_prefix),
111+
f"Unexpected LinkedIn href: {href}",
112+
)
113+
self.assertEqual(linkedin.get("target"), "_blank")
114+
self.assertEqual(linkedin.get("rel"), ["nofollow", "noopener"])
115+
self.assertEqual(linkedin.get("title"), "Share on LinkedIn")
116+
svg_use = linkedin.find("use")
117+
self.assertIsNotNone(svg_use)
118+
self.assertEqual(svg_use.get("xlink:href"), "#linkedin")
119+
120+
# Copy link button
121+
copy_btn = share.find("a", class_="link_yank")
122+
self.assertIsNotNone(copy_btn)
123+
self.assertTrue(bool(copy_btn.get("href")))
124+
self.assertIn(copy_btn.get("title"), ["Copy link", "Copy Link"])
125+
copy_svg_use = copy_btn.find("use")
126+
self.assertIsNotNone(copy_svg_use)
127+
self.assertEqual(copy_svg_use.get("xlink:href"), "#copy")
128+
129+
def test_rendered_blog_post_html(self) -> None:
130+
"""Verify rendered blog post pages share panel elements."""
131+
build_dir = self.root / "build" / "blog"
132+
if not build_dir.exists():
133+
return
134+
135+
for post_html in build_dir.glob("*/index.html"):
136+
soup = BeautifulSoup(
137+
post_html.read_text(encoding="utf-8"), "html.parser"
138+
)
139+
panel = soup.find("aside", class_="blog-share-panel")
140+
if not panel:
141+
continue
142+
143+
# LinkedIn button
144+
linkedin = panel.find("a", class_="linkedin")
145+
self.assertIsNotNone(
146+
linkedin, f"Missing LinkedIn button in {post_html}"
147+
)
148+
href = linkedin.get("href", "")
149+
share_prefix = (
150+
"https://www.linkedin.com/sharing/share-offsite/?url="
151+
)
152+
self.assertTrue(
153+
href.startswith(share_prefix),
154+
f"Unexpected LinkedIn href in {post_html}: {href}",
155+
)
156+
self.assertEqual(linkedin.get("target"), "_blank")
157+
self.assertEqual(linkedin.get("rel"), ["nofollow", "noopener"])
158+
self.assertEqual(linkedin.get("title"), "Share on LinkedIn")
159+
svg_use = linkedin.find("use")
160+
self.assertIsNotNone(svg_use)
161+
self.assertEqual(svg_use.get("xlink:href"), "#linkedin")
162+
163+
# Copy link button
164+
copy_btn = panel.find("a", class_="link_yank")
165+
self.assertIsNotNone(
166+
copy_btn, f"Missing Copy link button in {post_html}"
167+
)
168+
self.assertTrue(bool(copy_btn.get("href")))
169+
self.assertEqual(copy_btn.get("title"), "Copy link")
170+
copy_svg_use = copy_btn.find("use")
171+
self.assertIsNotNone(copy_svg_use)
172+
self.assertEqual(copy_svg_use.get("xlink:href"), "#copy")
173+
174+
175+
if __name__ == "__main__":
176+
unittest.main()

‎theme/blog-list.html‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ <h3 class="post_link">
6363
class="facebook" title="Share on Facebook" target="_blank" rel="nofollow noopener">
6464
<svg class="icon"><use xlink:href="#facebook"/></svg>
6565
</a>
66-
<a href="#linkedinshare" class="linkedin" title="Share on LinkedIn" rel="nofollow">
66+
<a href="https://www.linkedin.com/sharing/share-offsite/?url={{ url }}"
67+
class="linkedin" title="Share on LinkedIn" target="_blank" rel="nofollow noopener">
6768
<svg class="icon"><use xlink:href="#linkedin"/></svg>
6869
</a>
6970
<a href="{{ url }}" title="Copy Link" class="link link_yank">

‎theme/blog-post.html‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ <h1>{{ title }}</h1>
5858
class="facebook" title="Share on Facebook" target="_blank" rel="nofollow noopener">
5959
<svg class="icon" aria-hidden="true"><use xlink:href="#facebook"/></svg>
6060
</a>
61-
<a href="#linkedinshare" id="linkedinshare" class="linkedin" title="Share on LinkedIn" rel="nofollow">
61+
<a href="https://www.linkedin.com/sharing/share-offsite/?url={{ page.canonical_url or url }}"
62+
class="linkedin" title="Share on LinkedIn" target="_blank" rel="nofollow noopener">
6263
<svg class="icon" aria-hidden="true"><use xlink:href="#linkedin"/></svg>
6364
</a>
6465
<a href="{{ page.canonical_url or url }}" title="Copy link" class="link link_yank">

‎theme/css/blog.css‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,47 @@ a.post-thumb img,
175175
.post_share a:hover{ background: rgba(255,255,255,.08); }
176176
.post_share .share_label{ margin-right: .25rem; }
177177

178+
/* Copy link feedback */
179+
.link_yank {
180+
position: relative;
181+
cursor: pointer;
182+
}
183+
184+
.link_yank.copied {
185+
color: var(--brand-strong, #087fa8) !important;
186+
}
187+
188+
.link_yank .copy-tooltip {
189+
position: absolute;
190+
bottom: calc(100% + 6px);
191+
left: 50%;
192+
transform: translateX(-50%);
193+
background: var(--surface-solid, #1e293b);
194+
color: var(--fg, #ffffff);
195+
border: 1px solid var(--border, rgba(255, 255, 255, 0.15));
196+
font-size: 0.72rem;
197+
font-weight: 600;
198+
line-height: 1.2;
199+
padding: 0.2rem 0.45rem;
200+
border-radius: 4px;
201+
white-space: nowrap;
202+
pointer-events: none;
203+
z-index: 1000;
204+
box-shadow: var(--shadow, 0 4px 12px rgba(0, 0, 0, 0.2));
205+
animation: copyFadeIn 0.15s ease forwards;
206+
}
207+
208+
@keyframes copyFadeIn {
209+
from {
210+
opacity: 0;
211+
transform: translateX(-50%) translateY(4px);
212+
}
213+
to {
214+
opacity: 1;
215+
transform: translateX(-50%) translateY(0);
216+
}
217+
}
218+
178219
/* ── Responsive ─────────────────────────────────────────────── */
179220
@media (max-width: 1024px){
180221
.post-grid{ --card-min: 280px; }

‎theme/js/theme.js‎

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,76 @@
168168
});
169169
}
170170

171+
// D) Copy link buttons (.link_yank)
172+
document.addEventListener('click', async (e) => {
173+
const btn = e.target.closest('.link_yank');
174+
if (!btn) return;
175+
176+
e.preventDefault();
177+
178+
let textToCopy = btn.getAttribute('data-url') || btn.getAttribute('href') || window.location.href;
179+
try {
180+
textToCopy = new URL(textToCopy, window.location.origin).href;
181+
} catch (_) {}
182+
183+
let success = false;
184+
if (navigator.clipboard && navigator.clipboard.writeText) {
185+
try {
186+
await navigator.clipboard.writeText(textToCopy);
187+
success = true;
188+
} catch (_) {}
189+
}
190+
191+
if (!success) {
192+
try {
193+
const ta = document.createElement('textarea');
194+
ta.value = textToCopy;
195+
ta.style.position = 'fixed';
196+
ta.style.left = '-9999px';
197+
ta.style.top = '-9999px';
198+
ta.setAttribute('readonly', '');
199+
document.body.appendChild(ta);
200+
ta.select();
201+
success = document.execCommand('copy');
202+
document.body.removeChild(ta);
203+
} catch (_) {}
204+
}
205+
206+
if (success) {
207+
if (btn._copyTimeout) {
208+
clearTimeout(btn._copyTimeout);
209+
}
210+
211+
const originalTitle = btn.getAttribute('data-original-title') || btn.getAttribute('title') || 'Copy link';
212+
if (!btn.getAttribute('data-original-title')) {
213+
btn.setAttribute('data-original-title', originalTitle);
214+
}
215+
216+
btn.setAttribute('title', 'Copied!');
217+
btn.setAttribute('aria-label', 'Copied!');
218+
btn.classList.add('copied');
219+
220+
let tooltip = btn.querySelector('.copy-tooltip');
221+
if (!tooltip) {
222+
tooltip = document.createElement('span');
223+
tooltip.className = 'copy-tooltip';
224+
tooltip.setAttribute('role', 'status');
225+
btn.appendChild(tooltip);
226+
}
227+
tooltip.textContent = 'Copied!';
228+
229+
btn._copyTimeout = setTimeout(() => {
230+
btn.classList.remove('copied');
231+
btn.setAttribute('title', originalTitle);
232+
btn.setAttribute('aria-label', originalTitle);
233+
if (tooltip && tooltip.parentNode) {
234+
tooltip.parentNode.removeChild(tooltip);
235+
}
236+
btn._copyTimeout = null;
237+
}, 2000);
238+
}
239+
});
240+
171241
})();
172242

173243

0 commit comments

Comments
 (0)