Skip to content

Commit

Permalink
Update doc-versions.js
Browse files Browse the repository at this point in the history
  • Loading branch information
gadenbuie committed Nov 3, 2023
1 parent c28d641 commit 93087ad
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 60 deletions.
22 changes: 10 additions & 12 deletions dev/doc-versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
}

function pathDir (url) {
return url.replace(/\/[^\/]+$/, '/')
return url.replace(/\/[^/]+$/, '/')
}

function ensureTrailingSlash (url) {
Expand All @@ -39,7 +39,7 @@
const currentScript = scripts[scripts.length - 1]

let src = pathDir(currentScript.getAttribute('src'))
if (!src.includes('/') || src === "/") {
if (!src.includes('/') || src === '/') {
src = ''
}

Expand Down Expand Up @@ -121,15 +121,15 @@
return
}

const version = item.version ? item.version : label
const version = item.version ? item.version : item.text.replace(/^v/, '')
const isCurrent = current.innerText === version
ul.appendChild(createVersionDropdownItem(item, isCurrent))
})

return dropdown
}

function createVersionDropdownItem ({text, url}, isCurrent = false) {
function createVersionDropdownItem ({ text, url }, isCurrent = false) {
const li = document.createElement('li')
const a = document.createElement('a')
a.classList.add('dropdown-item')
Expand Down Expand Up @@ -167,7 +167,7 @@
function insertBanner (banner) {
if (!banner) return
const main = document.querySelector('main')
if (!navbar) return
if (!main) return

let { html, class: classes } = banner
if (typeof classes === 'string') {
Expand All @@ -181,13 +181,11 @@
const div = document.createElement('div')
div.classList.add('alert', 'px-3', 'py-2', 'text-center', ...classes)
div.innerHTML = html
div
.querySelectorAll('a')
.forEach(a => {
if (a.getAttribute('href') === '#') {
a.href = makeNewPkgdownLink(findPkgdownGlobalRoot())
}
})
div.querySelectorAll('a').forEach(a => {
if (a.getAttribute('href') === '#') {
a.href = makeNewPkgdownLink(findPkgdownGlobalRoot())
}
})

main.insertAdjacentElement('afterbegin', div)
return div
Expand Down
22 changes: 10 additions & 12 deletions doc-versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
}

function pathDir (url) {
return url.replace(/\/[^\/]+$/, '/')
return url.replace(/\/[^/]+$/, '/')
}

function ensureTrailingSlash (url) {
Expand All @@ -39,7 +39,7 @@
const currentScript = scripts[scripts.length - 1]

let src = pathDir(currentScript.getAttribute('src'))
if (!src.includes('/') || src === "/") {
if (!src.includes('/') || src === '/') {
src = ''
}

Expand Down Expand Up @@ -121,15 +121,15 @@
return
}

const version = item.version ? item.version : label
const version = item.version ? item.version : item.text.replace(/^v/, '')
const isCurrent = current.innerText === version
ul.appendChild(createVersionDropdownItem(item, isCurrent))
})

return dropdown
}

function createVersionDropdownItem ({text, url}, isCurrent = false) {
function createVersionDropdownItem ({ text, url }, isCurrent = false) {
const li = document.createElement('li')
const a = document.createElement('a')
a.classList.add('dropdown-item')
Expand Down Expand Up @@ -167,7 +167,7 @@
function insertBanner (banner) {
if (!banner) return
const main = document.querySelector('main')
if (!navbar) return
if (!main) return

let { html, class: classes } = banner
if (typeof classes === 'string') {
Expand All @@ -181,13 +181,11 @@
const div = document.createElement('div')
div.classList.add('alert', 'px-3', 'py-2', 'text-center', ...classes)
div.innerHTML = html
div
.querySelectorAll('a')
.forEach(a => {
if (a.getAttribute('href') === '#') {
a.href = makeNewPkgdownLink(findPkgdownGlobalRoot())
}
})
div.querySelectorAll('a').forEach(a => {
if (a.getAttribute('href') === '#') {
a.href = makeNewPkgdownLink(findPkgdownGlobalRoot())
}
})

main.insertAdjacentElement('afterbegin', div)
return div
Expand Down
22 changes: 10 additions & 12 deletions v0.1.0/doc-versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
}

function pathDir (url) {
return url.replace(/\/[^\/]+$/, '/')
return url.replace(/\/[^/]+$/, '/')
}

function ensureTrailingSlash (url) {
Expand All @@ -39,7 +39,7 @@
const currentScript = scripts[scripts.length - 1]

let src = pathDir(currentScript.getAttribute('src'))
if (!src.includes('/') || src === "/") {
if (!src.includes('/') || src === '/') {
src = ''
}

Expand Down Expand Up @@ -121,15 +121,15 @@
return
}

const version = item.version ? item.version : label
const version = item.version ? item.version : item.text.replace(/^v/, '')
const isCurrent = current.innerText === version
ul.appendChild(createVersionDropdownItem(item, isCurrent))
})

return dropdown
}

function createVersionDropdownItem ({text, url}, isCurrent = false) {
function createVersionDropdownItem ({ text, url }, isCurrent = false) {
const li = document.createElement('li')
const a = document.createElement('a')
a.classList.add('dropdown-item')
Expand Down Expand Up @@ -167,7 +167,7 @@
function insertBanner (banner) {
if (!banner) return
const main = document.querySelector('main')
if (!navbar) return
if (!main) return

let { html, class: classes } = banner
if (typeof classes === 'string') {
Expand All @@ -181,13 +181,11 @@
const div = document.createElement('div')
div.classList.add('alert', 'px-3', 'py-2', 'text-center', ...classes)
div.innerHTML = html
div
.querySelectorAll('a')
.forEach(a => {
if (a.getAttribute('href') === '#') {
a.href = makeNewPkgdownLink(findPkgdownGlobalRoot())
}
})
div.querySelectorAll('a').forEach(a => {
if (a.getAttribute('href') === '#') {
a.href = makeNewPkgdownLink(findPkgdownGlobalRoot())
}
})

main.insertAdjacentElement('afterbegin', div)
return div
Expand Down
22 changes: 10 additions & 12 deletions v0.1.1/doc-versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
}

function pathDir (url) {
return url.replace(/\/[^\/]+$/, '/')
return url.replace(/\/[^/]+$/, '/')
}

function ensureTrailingSlash (url) {
Expand All @@ -39,7 +39,7 @@
const currentScript = scripts[scripts.length - 1]

let src = pathDir(currentScript.getAttribute('src'))
if (!src.includes('/') || src === "/") {
if (!src.includes('/') || src === '/') {
src = ''
}

Expand Down Expand Up @@ -121,15 +121,15 @@
return
}

const version = item.version ? item.version : label
const version = item.version ? item.version : item.text.replace(/^v/, '')
const isCurrent = current.innerText === version
ul.appendChild(createVersionDropdownItem(item, isCurrent))
})

return dropdown
}

function createVersionDropdownItem ({text, url}, isCurrent = false) {
function createVersionDropdownItem ({ text, url }, isCurrent = false) {
const li = document.createElement('li')
const a = document.createElement('a')
a.classList.add('dropdown-item')
Expand Down Expand Up @@ -167,7 +167,7 @@
function insertBanner (banner) {
if (!banner) return
const main = document.querySelector('main')
if (!navbar) return
if (!main) return

let { html, class: classes } = banner
if (typeof classes === 'string') {
Expand All @@ -181,13 +181,11 @@
const div = document.createElement('div')
div.classList.add('alert', 'px-3', 'py-2', 'text-center', ...classes)
div.innerHTML = html
div
.querySelectorAll('a')
.forEach(a => {
if (a.getAttribute('href') === '#') {
a.href = makeNewPkgdownLink(findPkgdownGlobalRoot())
}
})
div.querySelectorAll('a').forEach(a => {
if (a.getAttribute('href') === '#') {
a.href = makeNewPkgdownLink(findPkgdownGlobalRoot())
}
})

main.insertAdjacentElement('afterbegin', div)
return div
Expand Down
22 changes: 10 additions & 12 deletions v1.0.0/doc-versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
}

function pathDir (url) {
return url.replace(/\/[^\/]+$/, '/')
return url.replace(/\/[^/]+$/, '/')
}

function ensureTrailingSlash (url) {
Expand All @@ -39,7 +39,7 @@
const currentScript = scripts[scripts.length - 1]

let src = pathDir(currentScript.getAttribute('src'))
if (!src.includes('/') || src === "/") {
if (!src.includes('/') || src === '/') {
src = ''
}

Expand Down Expand Up @@ -121,15 +121,15 @@
return
}

const version = item.version ? item.version : label
const version = item.version ? item.version : item.text.replace(/^v/, '')
const isCurrent = current.innerText === version
ul.appendChild(createVersionDropdownItem(item, isCurrent))
})

return dropdown
}

function createVersionDropdownItem ({text, url}, isCurrent = false) {
function createVersionDropdownItem ({ text, url }, isCurrent = false) {
const li = document.createElement('li')
const a = document.createElement('a')
a.classList.add('dropdown-item')
Expand Down Expand Up @@ -167,7 +167,7 @@
function insertBanner (banner) {
if (!banner) return
const main = document.querySelector('main')
if (!navbar) return
if (!main) return

let { html, class: classes } = banner
if (typeof classes === 'string') {
Expand All @@ -181,13 +181,11 @@
const div = document.createElement('div')
div.classList.add('alert', 'px-3', 'py-2', 'text-center', ...classes)
div.innerHTML = html
div
.querySelectorAll('a')
.forEach(a => {
if (a.getAttribute('href') === '#') {
a.href = makeNewPkgdownLink(findPkgdownGlobalRoot())
}
})
div.querySelectorAll('a').forEach(a => {
if (a.getAttribute('href') === '#') {
a.href = makeNewPkgdownLink(findPkgdownGlobalRoot())
}
})

main.insertAdjacentElement('afterbegin', div)
return div
Expand Down

0 comments on commit 93087ad

Please sign in to comment.