Skip to content

Commit efffa55

Browse files
feat: correction of navbar links in docs.jenkins.io
1 parent d380b45 commit efffa55

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed

src/jio-navbar.ts

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,83 @@ export class Navbar extends LitElement {
8383
handleDocumentClick() {
8484
this.visibleMenu = -1;
8585
}
86+
private isDocsSite = window.location.hostname === 'docs.jenkins.io';
87+
private docsVersion = '2.504.x';
88+
89+
private getDocsUrl(originalPath: string): string {
90+
91+
const cleanPath = originalPath.replace(/^https?:\/\/[^\/]+/, '').split(/[#?]/)[0];
92+
const docMappings: Record<string, {path: string, versioned: boolean}> = {
93+
// User Guide sections (versioned)
94+
'/doc/book': {path: '/user-docs', versioned: true},
95+
'/doc/book/installing': {path: '/user-docs/installing-jenkins', versioned: true},
96+
'/doc/book/pipeline': {path: '/user-docs/pipeline', versioned: true},
97+
'/doc/book/managing': {path: '/user-docs/managing', versioned: true},
98+
'/doc/book/security': {path: '/user-docs/security', versioned: true},
99+
'/doc/book/system-administration': {path: '/user-docs/system-administration', versioned: true},
100+
'/doc/book/troubleshooting': {path: '/user-docs/troubleshooting', versioned: true},
101+
'/doc/book/glossary': {path: '/user-docs/glossary', versioned: true},
102+
103+
// Solutions (versioned)
104+
'/solutions': {path: '/solutions', versioned: true},
105+
106+
// Tutorials (versioned)
107+
'/doc/tutorials': {path: '/tutorials', versioned: true},
108+
109+
// Developer Guide (not versioned)
110+
'/doc/developer': {path: '/dev-docs', versioned: false},
111+
112+
// Community sections
113+
'/participate': {path: '/community', versioned: false},
114+
'/chat': {path: '/community/chat', versioned: false},
115+
'/projects/jam': {path: '/community/meet', versioned: false},
116+
'/events': {path: '/events', versioned: false},
117+
'/mailing-lists': {path: '/community/mailing-lists', versioned: false},
118+
119+
// Subprojects
120+
'/sigs/docs/gsod/2020/projects/document-jenkins-on-kubernetes': {
121+
path: '/sigs/docs/gsod/2020/projects/document-jenkins-on-kubernetes',
122+
versioned: false
123+
},
124+
125+
// Security
126+
'/security/reporting': {path: '/security/reporting', versioned: false},
127+
128+
// About sections
129+
'/project/roadmap': {path: '/about', versioned: false},
130+
'/project/conduct': {path: '/project/conduct', versioned: false},
131+
'/artwork': {path: '/images', versioned: false}
132+
};
133+
134+
const mappingEntry = Object.entries(docMappings).find(([original]) =>
135+
cleanPath.startsWith(original)
136+
);
137+
138+
if (mappingEntry && this.isDocsSite) {
139+
const [original, {path: replacement, versioned}] = mappingEntry;
140+
let newPath = cleanPath.replace(original, replacement);
141+
142+
if (versioned) {
143+
const pathParts = newPath.split('/').filter(part => part !== '');
144+
if (pathParts.length >= 1) {
145+
pathParts.splice(1, 0, this.docsVersion);
146+
newPath = '/' + pathParts.join('/');
147+
} else {
148+
newPath = `/${this.docsVersion}`;
149+
}
150+
}
151+
152+
if (!newPath.endsWith('index.html')) {
153+
newPath = newPath.replace(/(\/)?$/, '/') + 'index.html';
154+
}
155+
156+
return `https://docs.jenkins.io${newPath}`;
157+
}
158+
159+
return this.isDocsSite
160+
? `https://docs.jenkins.io${cleanPath}`
161+
: `https://www.jenkins.io${cleanPath}`;
162+
}
86163

87164
override render() {
88165
const cdfMenuItems = [

0 commit comments

Comments
 (0)