Skip to content

Commit

Permalink
kunai.js: オンラインURLをデータベースに指定 (Google検索対象サイトに使用)
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed May 27, 2024
1 parent b66c4d7 commit 9c16b08
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions js/kunai.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,18 @@ class Kunai {
return "/"
})()

// Determine the project website URL, which is assumed to be stored in
// <meta name="twietter:url" content="..." /> or in <meta property="og:url"
// content="..." />.
const online_base_url = (() => {
const meta = document.querySelector('meta[name="twitter:url"]') || document.querySelector('meta[property="og:url"]')
if (meta && meta.content) {
const m = meta.content.toString().match(/^https?:\/\/[^/]*\//)
if (m) return m[0]
}
return null
})()

const database_url = (() => {
// Determine the location of the database file "crsearch.json".
const current_script = document.currentScript || document.querySelector('script[src*="kunai/js/kunai.js"]')
Expand All @@ -149,14 +161,9 @@ class Kunai {
const url = url_kunai.replace(/\bkunai\/js\/kunai\.js([?#].*)?$/, "crsearch/crsearch.js")
if (url != url_kunai) return url

// Try to download "crsearch.json" from the project website, which is
// assumed to be stored in <meta name="twietter:url" content="..." />
// or in <meta property="og:url" content="..." />.
const meta = document.querySelector('meta[name="twitter:url"]') || document.querySelector('meta[property="og:url"]')
if (meta && meta.content) {
const m = meta.content.toString().match(/^https?:\/\/[^/]*\//)
if (m) return m[0] + "static/crsearch/crsearch.json"
}
// Try to download "crsearch.json" from the project website.
if (online_base_url)
return online_base_url + "static/crsearch/crsearch.json"
}

// Try to determine the position of crsearch.json
Expand All @@ -173,7 +180,8 @@ class Kunai {

let crs = new CRSearch({
onDatabase: this.onDatabase.bind(this),
base_url: dynamic_base_url
base_url: dynamic_base_url,
online_base_url: online_base_url
})
crs.database(database_url)

Expand Down

0 comments on commit 9c16b08

Please sign in to comment.