Update index.js

Improved path conversion to allow any number of subpaths
pull/5095/head
Cláudio Patrício 2023-05-03 04:38:29 +01:00 committed by GitHub
parent c593a455b6
commit b396e718aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 19 deletions

View File

@ -1,27 +1,12 @@
function convertPathToHtml(path) {
let count = 0
let htmlpath = ''
while (path.startsWith('../')) {
count++
path = path.slice(3)
if (htmlpath.length < 2) htmlpath += '.'
else htmlpath += '/..'
}
if (count === 1) {
return '.'
}
if (count === 2) {
return '..'
}
if (count === 3) {
return '../..'
}
if (count === 4) {
return '../../..'
}
return ''
return htmlpath
}
export { convertPathToHtml }