Skip to content

Commit db3b006

Browse files
authored
Merge pull request #952 from ArmDeveloperEcosystem/copy-link-url
remove github issue add copy url
2 parents 4991e9e + cfd6eb9 commit db3b006

6 files changed

Lines changed: 131 additions & 31 deletions

File tree

assets/css/eco-dashboard.css

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,18 +112,45 @@
112112

113113
}
114114

115-
p.github-link {
115+
.github-link {
116116
margin-top: 0px;
117117
margin-bottom: 0px;
118118

119119
color: var(--arm-web-safe-blue);
120120
text-decoration: none;
121121
}
122122

123-
html[theme='dark'] p.github-link {
123+
a.package-url-copy-link {
124+
color: inherit;
125+
text-decoration: none;
126+
cursor: pointer;
127+
}
128+
129+
a.package-url-copy-link .github-link span {
130+
display: inline-flex;
131+
align-items: center;
132+
gap: 0.25rem;
133+
}
134+
135+
a.package-url-copy-link:focus,
136+
a.package-url-copy-link:focus-visible {
137+
outline: none;
138+
box-shadow: none;
139+
}
140+
141+
html[theme='dark'] .github-link {
142+
color: var(--arm-light-blue);
143+
}
144+
html[theme='dark'] .github-link:hover {
145+
color: var(--arm-green);
146+
}
147+
148+
html[theme='dark'] a.package-url-copy-link .github-link {
124149
color: var(--arm-light-blue);
125150
}
126-
html[theme='dark'] p.github-link:hover {
151+
152+
html[theme='dark'] a.package-url-copy-link:hover .github-link,
153+
a.package-url-copy-link:hover .github-link {
127154
color: var(--arm-green);
128155
}
129156

@@ -627,7 +654,3 @@ ads-card.stack-card:hover .stack-title {
627654

628655

629656

630-
631-
632-
633-
Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
<!-- GitHub links calculated from GitHub repo, defined in config.toml -->
2-
{{ $gh_repo := site.Params.github_repo -}}
3-
{{ $gh_branch := (default "main" site.Params.github_branch) -}}
4-
{{ $pathFormatted := replace .File.Path "\\" "/" -}}
5-
{{ $gh_repo_path := printf "%s/content/%s" $gh_branch $pathFormatted -}}
1+
{{ $package_slug := partial "eco-dashboard/urlize_custom.html" (.metadata.Params.name | lower) -}}
62

7-
{{ $editURL := printf "%s/edit/%s" $gh_repo $gh_repo_path -}}
8-
9-
<!-- Display github elements -->
10-
11-
<a class="github-issue-update-link" href="{{ $editURL }}" target="_blank" style="text-decoration: none;" title="Edit on GitHub">
3+
<a
4+
class="package-url-copy-link"
5+
href="#"
6+
title="Copy package URL"
7+
aria-label="Copy package URL"
8+
data-package-slug="{{ $package_slug }}"
9+
data-dashboard-path="{{ .dashboard_page_path }}"
10+
onclick="copyPackageUrl(this); return false;"
11+
style="text-decoration: none;">
1212
<p class="github-link">
1313
<span>
14-
<i class="left-hand-icon fa-brands fa-github"></i>
15-
Issues? Update here.
14+
<i class="left-hand-icon fa-solid fa-link"></i>
15+
<span class="package-url-copy-label">Copy package URL</span>
1616
</span>
1717
</p>
1818
</a>

themes/arm-design-system-hugo-theme/layouts/partials/package-display/row-sub.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
{{ end }}
1616
</div>
1717
<div class="c-col u-hide sm:u-display-block sm:c-col-5 md:c-col-4" style="margin: 0px; padding: 0px; text-align: right;">
18-
{{partial "eco-dashboard/github-links.html" .metadata }}
18+
{{partial "eco-dashboard/github-links.html" .}}
1919
</div>
2020
<div class="c-col u-display-block sm:u-hide c-col-12" style="margin: 0px; margin-top: 8px; padding: 0px;">
21-
{{partial "eco-dashboard/github-links.html" .metadata }}
21+
{{partial "eco-dashboard/github-links.html" .}}
2222
</div>
2323
</div>
2424

@@ -156,4 +156,4 @@
156156
{{ end }}
157157
</div>
158158
</td>
159-
</tr>
159+
</tr>

themes/arm-design-system-hugo-theme/layouts/partials/package-display/table.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,20 @@
1313
<tbody id="sw-tablebody">
1414
{{ $id_index := 0}}
1515
{{ $os := .context.Params.os }}
16+
{{ $dashboard_page_path := .context.RelPermalink | strings.TrimRight "/" }}
1617
{{ range .packages }}
1718

1819
{{ $id_index = add $id_index 1 }}
1920

2021

2122

2223
{{ partial "package-display/row-main.html" (dict "metadata" . "id_index" $id_index "os" $os "category" .Params.category "search_enable" $.search_enable) }}
23-
{{ partial "package-display/row-sub.html" (dict "metadata" . "id_index" $id_index "os" $os "category" .Params.category)}}
24+
{{ partial "package-display/row-sub.html" (dict "metadata" . "id_index" $id_index "os" $os "category" .Params.category "dashboard_page_path" $dashboard_page_path)}}
2425

2526
{{end}}
2627

2728

2829

2930
</tbody>
3031
</table>
31-
</div>
32+
</div>

themes/arm-design-system-hugo-theme/static/js/anonymous-analytics.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,12 @@ document.addEventListener("DOMContentLoaded", function() {
154154
}
155155

156156

157-
// GitHub issue tracking
158-
let github_issue_links = document.querySelectorAll('a.github-issue-update-link');
159-
for (let gh_link of github_issue_links) {
160-
gh_link.addEventListener("click", () => {
161-
let package_name = gh_link.closest('table').closest('tr').previousElementSibling.getAttribute('data-title');
162-
trackGeneralContentInteraction('github_edit_package_click',package_name);
157+
// Copy package URL tracking
158+
let package_url_copy_links = document.querySelectorAll('a.package-url-copy-link');
159+
for (let copy_button of package_url_copy_links) {
160+
copy_button.addEventListener("click", () => {
161+
let package_name = copy_button.closest('tr').previousElementSibling.getAttribute('data-title');
162+
trackGeneralContentInteraction('copy_package_url_click',package_name);
163163
});
164164
}
165165

themes/arm-design-system-hugo-theme/static/js/eco-dashboard/search.js

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,76 @@ function normalizePackageName(input) {
5858
.toLowerCase(); // Convert to lowercase
5959
}
6060

61+
function getDashboardPath(dashboardPath) {
62+
if (dashboardPath) {
63+
return dashboardPath.replace(/\/$/, '') || '/';
64+
}
65+
66+
return window.location.pathname.replace(/\/$/, '') || '/';
67+
}
68+
69+
function buildPackageDashboardUrl(packageSlug, dashboardPath) {
70+
const packageUrl = new URL(window.location.href);
71+
72+
packageUrl.pathname = getDashboardPath(dashboardPath);
73+
packageUrl.search = '';
74+
packageUrl.hash = '';
75+
packageUrl.searchParams.set('package', packageSlug);
76+
77+
return packageUrl.toString();
78+
}
79+
80+
async function copyTextToClipboard(textToCopy) {
81+
if (navigator.clipboard && window.isSecureContext) {
82+
await navigator.clipboard.writeText(textToCopy);
83+
return;
84+
}
85+
86+
const temporaryTextArea = document.createElement('textarea');
87+
temporaryTextArea.value = textToCopy;
88+
temporaryTextArea.setAttribute('readonly', '');
89+
temporaryTextArea.style.position = 'absolute';
90+
temporaryTextArea.style.left = '-9999px';
91+
92+
document.body.appendChild(temporaryTextArea);
93+
temporaryTextArea.select();
94+
95+
const copySucceeded = document.execCommand('copy');
96+
document.body.removeChild(temporaryTextArea);
97+
98+
if (!copySucceeded) {
99+
throw new Error('Copy command failed.');
100+
}
101+
}
102+
103+
async function copyPackageUrl(button) {
104+
const packageSlug = button.getAttribute('data-package-slug');
105+
const dashboardPath = button.getAttribute('data-dashboard-path');
106+
const label = button.querySelector('.package-url-copy-label');
107+
const defaultLabel = 'Copy package URL';
108+
109+
if (!packageSlug || !label) {
110+
return;
111+
}
112+
113+
try {
114+
const packageUrl = buildPackageDashboardUrl(packageSlug, dashboardPath);
115+
await copyTextToClipboard(packageUrl);
116+
label.textContent = 'Copied URL';
117+
button.setAttribute('aria-label', 'Package URL copied');
118+
} catch (error) {
119+
console.error('Unable to copy package URL.', error);
120+
label.textContent = 'Copy failed';
121+
button.setAttribute('aria-label', 'Copy package URL failed');
122+
}
123+
124+
window.clearTimeout(button.copyResetTimeout);
125+
button.copyResetTimeout = window.setTimeout(() => {
126+
label.textContent = defaultLabel;
127+
button.setAttribute('aria-label', defaultLabel);
128+
}, 2000);
129+
}
130+
61131

62132

63133
function updatePageMetadata(package_dom) {
@@ -75,7 +145,8 @@ function updatePageMetadata(package_dom) {
75145
if (!does_it_woa) {
76146
social_description = "View "+pkg_name+" in the Software Ecosystem Dashboard for Arm and discover if it runs on Arm Linux servers (Aarch64) and alternative packages.";
77147
}
78-
let new_cannonical = 'https://developer.arm.com/ecosystem-dashboard?package='+normalizePackageName(pkg_name).replaceAll('(','').replaceAll(')','').replaceAll('__','/');
148+
let package_slug = package_dom.getAttribute('data-title-urlized');
149+
let new_cannonical = buildPackageDashboardUrl(package_slug);
79150

80151

81152

@@ -101,6 +172,11 @@ function updatePageMetadata(package_dom) {
101172
canonical_link.setAttribute('href',new_cannonical);
102173
}
103174

175+
const ogUrl = document.querySelector('meta[property="og:url"]');
176+
if (ogUrl) {
177+
ogUrl.setAttribute('content', new_cannonical);
178+
}
179+
104180
// Update descriptions
105181
const ogDescription = document.querySelector('meta[property="og:description"]');
106182
if (ogDescription) {

0 commit comments

Comments
 (0)