diff --git a/js/kunai.js b/js/kunai.js index 4712b71..a4d59d3 100644 --- a/js/kunai.js +++ b/js/kunai.js @@ -107,6 +107,7 @@ class Kunai { async onDatabase(db) { // this.log.debug(`onDatabase`, db) + UI.Badge.onDatabase(db) await this.ui.sidebar.onDatabase(db) await this.ui.sidebar.treeview.onPageID(this.meta.page_id) } diff --git a/js/kunai/ui.js b/js/kunai/ui.js index 98d0db2..1745f55 100644 --- a/js/kunai/ui.js +++ b/js/kunai/ui.js @@ -1,4 +1,5 @@ export {Content} from './ui/content' export {Sidebar} from './ui/sidebar' export {Navbar} from './ui/navbar' - +import * as Badge from './ui/badge' +export {Badge} diff --git a/js/kunai/ui/badge.js b/js/kunai/ui/badge.js index adc0f14..0abe2e0 100644 --- a/js/kunai/ui/badge.js +++ b/js/kunai/ui/badge.js @@ -1,3 +1,13 @@ +let base_url = null +const unresolved_links = [] + +const onDatabase = (db) => { + base_url = db.base_url.toString() + for (let a_elem of unresolved_links) + a_elem.attr('href', base_url.replace(/\/$/, '') + a_elem.attr('href')) + unresolved_links.length = 0 +} + const sanitize = (badges) => { let i = 0 @@ -46,15 +56,18 @@ const sanitize = (badges) => { const lang_path = cppv ? `/lang/cpp${cppv}` : named_version ? `/lang/${named_version}` : `/lang` + const a_elem = $('', {href: `${lang_path}.html`}) + .append($('')) + // .append($('').text(clean_txt)) + .appendTo(b.empty()) - b.empty().append( - $('', {href: `${lang_path}.html`}) - .append($('')) - // .append($('').text(clean_txt)) - ) + if (base_url) + a_elem.attr('href', base_url.replace(/\/$/, '') + a_elem.attr('href')) + else + unresolved_links.push(a_elem) } return i } -export {sanitize} +export {onDatabase, sanitize}