Skip to content

Commit bc8d26a

Browse files
committed
Testing Edit this page along with select and report feature
1 parent 34b73c7 commit bc8d26a

File tree

4 files changed

+130
-1
lines changed

4 files changed

+130
-1
lines changed

.hintrc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"extends": [
3+
"development"
4+
],
5+
"hints": {
6+
"meta-viewport": "off",
7+
"axe/text-alternatives": [
8+
"default",
9+
{
10+
"document-title": "off"
11+
}
12+
],
13+
"axe/language": [
14+
"default",
15+
{
16+
"html-has-lang": "off"
17+
}
18+
]
19+
}
20+
}

layouts/_default/baseof.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
<!DOCTYPE html>
22
<html>
33
{{- partial "head.html" . -}}
4-
<body>
4+
<body{{ with .File }} data-github-file="{{ .Path }}"{{ end }}>
55
<div class="pf-c-page">
66
{{- partial "header.html" . -}}
77
{{- block "main" . }}
88
<!-- get all the things from the content files -->
99
{{- end }}
1010
</div>
1111
<script src="{{ "js/codeblock.js" | relURL }}"></script>
12+
<script src="{{ "js/select-report-issue.js" | relURL }}"></script>
1213
</body>
1314
<!-- Uncomment when you have sorted out the feedback partials option
1415
<body>
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// static/js/bug-reporter.js (or wherever you prefer to store static assets)
2+
3+
document.addEventListener('mouseup', function() {
4+
const selectedText = window.getSelection().toString().trim();
5+
6+
if (selectedText.length > 0) {
7+
// You might want to add a small button or popup here instead of direct confirmation
8+
// For simplicity, we'll keep the confirmation for now.
9+
10+
const currentPageUrl = window.location.href;
11+
const githubFilePath = getGitHubFilePath(); // This will now be more accurate for Hugo
12+
13+
const issueTitle = `Bug Report: Issue on "${selectedText.substring(0, 50).replace(/\n/g, ' ')}..."`;
14+
let issueBody = `
15+
**Description of the issue:**
16+
\`\`\`
17+
${selectedText}
18+
\`\`\`
19+
20+
---
21+
**Context:**
22+
- **Page URL:** ${currentPageUrl}
23+
- **GitHub Source File:** ${githubFilePath}
24+
`;
25+
26+
const encodedTitle = encodeURIComponent(issueTitle);
27+
const encodedBody = encodeURIComponent(issueBody);
28+
29+
const githubRepo = 'validatedpatterns/docs'; // Your GitHub repository
30+
const githubIssueUrl = `https://github.com/${githubRepo}/issues/new?title=${encodedTitle}&body=${encodedBody}`;
31+
32+
const confirmation = confirm("Do you want to report this as a bug on GitHub for the selected text?");
33+
if (confirmation) {
34+
window.open(githubIssueUrl, '_blank');
35+
}
36+
}
37+
});
38+
39+
40+
// Hugo-specific function to get the GitHub file path
41+
function getGitHubFilePath() {
42+
// This assumes you've added a data-github-file attribute to your body or a container.
43+
const bodyElement = document.querySelector('body');
44+
if (bodyElement && bodyElement.dataset.githubFile) {
45+
// Construct the full GitHub blob URL
46+
// Assuming your source files are in the 'content' directory of your repo
47+
// And you're using the 'main' branch
48+
const repoBaseUrl = 'https://github.com/validatedpatterns/docs/blob/main/';
49+
return repoBaseUrl + bodyElement.dataset.githubFile;
50+
}
51+
52+
// Fallback if the data attribute isn't found (shouldn't happen with Hugo setup)
53+
return "Could not determine source file automatically. Please specify if known.";
54+
}

static/js/select-report-issue.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// static/js/bug-reporter.js (or wherever you prefer to store static assets)
2+
3+
document.addEventListener('mouseup', function() {
4+
const selectedText = window.getSelection().toString().trim();
5+
6+
if (selectedText.length > 0) {
7+
// You might want to add a small button or popup here instead of direct confirmation
8+
// For simplicity, we'll keep the confirmation for now.
9+
10+
const currentPageUrl = window.location.href;
11+
const githubFilePath = getGitHubFilePath(); // This will now be more accurate for Hugo
12+
13+
const issueTitle = `Bug Report: Issue on "${selectedText.substring(0, 50).replace(/\n/g, ' ')}..."`;
14+
let issueBody = `
15+
**Description of the issue:**
16+
\`\`\`
17+
${selectedText}
18+
\`\`\`
19+
20+
---
21+
**Context:**
22+
- **Page URL:** ${currentPageUrl}
23+
- **GitHub Source File:** ${githubFilePath}
24+
`;
25+
26+
const encodedTitle = encodeURIComponent(issueTitle);
27+
const encodedBody = encodeURIComponent(issueBody);
28+
29+
const githubRepo = 'validatedpatterns/docs'; // Your GitHub repository
30+
const githubIssueUrl = `https://github.com/${githubRepo}/issues/new?title=${encodedTitle}&body=${encodedBody}`;
31+
32+
const confirmation = confirm("Do you want to report this as a bug on GitHub for the selected text?");
33+
if (confirmation) {
34+
window.open(githubIssueUrl, '_blank');
35+
}
36+
}
37+
});
38+
39+
40+
// Hugo-specific function to get the GitHub file path
41+
function getGitHubFilePath() {
42+
// This assumes you've added a data-github-file attribute to your body or a container.
43+
const bodyElement = document.querySelector('body');
44+
if (bodyElement && bodyElement.dataset.githubFile) {
45+
// Construct the full GitHub blob URL
46+
// Assuming your source files are in the 'content' directory of your repo
47+
// And you're using the 'main' branch
48+
const repoBaseUrl = 'https://github.com/validatedpatterns/docs/blob/main/';
49+
return repoBaseUrl + bodyElement.dataset.githubFile;
50+
}
51+
52+
// Fallback if the data attribute isn't found (shouldn't happen with Hugo setup)
53+
return "Could not determine source file automatically. Please specify if known.";
54+
}

0 commit comments

Comments
 (0)