Skip to content

Commit 70f91f3

Browse files
committed
Fix run link implementation
1 parent 6cd7162 commit 70f91f3

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

website/src/js/hljs-run.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export default class RunButtonPlugin {
2+
ORIGIN = globalThis.location.origin;
23
PATH = globalThis.location.pathname;
3-
BASE_URL = document.querySelector('base')?.getAttribute('href') || globalThis.location.origin;
4+
BASE_URL = document.querySelector('base')?.getAttribute('href');
45
RELATIVE_PATH = this.PATH.replace(this.BASE_URL, '');
56
PLAYGROUND_URL = 'playground';
67

@@ -21,8 +22,9 @@ export default class RunButtonPlugin {
2122
const urlParams = new URLSearchParams();
2223
urlParams.set('code', text);
2324
const hash = urlParams.toString();
24-
const version = this.RELATIVE_PATH.startsWith('docs/') ? '' : `${ this.RELATIVE_PATH.split('/')[0] }/`;
25-
globalThis.location.href = `${ this.BASE_URL }${ version }${ this.PLAYGROUND_URL }#${ hash }`;
25+
const hasVersion = this.RELATIVE_PATH !== '' && !this.RELATIVE_PATH.startsWith('docs/') && !this.RELATIVE_PATH.startsWith('index');
26+
const version = hasVersion ? `${ this.RELATIVE_PATH.split('/')[0] }/` : '';
27+
globalThis.location.href = `${ this.ORIGIN }${ this.BASE_URL }${ version }${ this.PLAYGROUND_URL }#${ hash }`;
2628
});
2729
const wrapper = document.createElement('div');
2830
wrapper.classList.add('hljs-run');

0 commit comments

Comments
 (0)