1
+ // static/js/select-report-issue.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