Skip to content

Commit

Permalink
kunai/ui/badge: C++バージョンバッジのbase_urlを遅延で再設定
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Sep 30, 2022
1 parent b9ba551 commit d033f27
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
1 change: 1 addition & 0 deletions js/kunai.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
3 changes: 2 additions & 1 deletion js/kunai/ui.js
Original file line number Diff line number Diff line change
@@ -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}
25 changes: 19 additions & 6 deletions js/kunai/ui/badge.js
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -43,15 +53,18 @@ const sanitize = (badges) => {
const lang_path = cppv ? `/lang/cpp${cppv}` :
named_version ? `/lang/${named_version}` :
`/lang`
const a_elem = $('<a>', {href: `${lang_path}.html`})
.append($('<i>'))
// .append($('<span>').text(clean_txt))
.appendTo(b.empty())

b.empty().append(
$('<a>', {href: `${lang_path}.html`})
.append($('<i>'))
// .append($('<span>').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}

0 comments on commit d033f27

Please sign in to comment.