diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c3e0db..3b7b953 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,22 @@ ## master +## 3.0.23 (2024-05-18) + +- "内部リンクを相対リンクで生成する機能"にまつわる修正を適用 + +## 3.0.22 (2022-11-06) + +- 依存ライブラリを修正 + +## 3.0.21 (2022-11-06) + +- 依存ライブラリを修正 + +## 3.0.20 (2022-11-06) + +- 依存ライブラリを修正 + ## 3.0.19 (2022-11-06) - 依存ライブラリを更新 diff --git a/js/crsearch/crsearch.js b/js/crsearch/crsearch.js index 9d56939..c57974c 100644 --- a/js/crsearch/crsearch.js +++ b/js/crsearch/crsearch.js @@ -25,6 +25,8 @@ export default class CRSearch { }, google_url: new URL('https://www.google.co.jp/search'), force_new_window: false, + base_url: null, + online_base_url: null, } static _KLASS = 'crsearch' @@ -98,10 +100,16 @@ export default class CRSearch { this._log.info(`fetching database (${i + 1}/${size}): ${url}`) try { - const data = await $.ajax({ + const ajaxSettings = { url: url, dataType: "json", - }) + } + if (/\.js([?#].*)?$/.test(url.toString())) { + ajaxSettings.dataType = "jsonp" + ajaxSettings.jsonpCallback = "callback" + ajaxSettings.crossDomain = true + } + const data = await $.ajax(ajaxSettings) this._log.info('fetched') this._parse(url, data) @@ -118,6 +126,10 @@ export default class CRSearch { _parse(url, json) { this._log.info('parsing...', json) + if (this._opts.base_url) + json.base_url = this._opts.base_url + if (this._opts.online_base_url) + json.online_base_url = this._opts.online_base_url const db = new Database(this._log, json) this._db.set(db.name, db) @@ -229,9 +241,10 @@ export default class CRSearch { for (const [name, db] of this._db) { // always include fallback + const fallback_site = db.online_base_url ? db.online_base_url.host : db.base_url.host const e = this._make_result(null, q.original_text, { name: db.name, - url: db.base_url.host, + url: fallback_site, }) e.attr('data-result-id', result_id++) result_list.append(e) @@ -266,7 +279,8 @@ export default class CRSearch { _make_google_url(q, site) { const url = this._opts.google_url - url.set('query', {q: `${q} site:${site}`}) + if (site != '') q = `${q} site:${site}` + url.set('query', {q: q}) return url } diff --git a/js/crsearch/database.js b/js/crsearch/database.js index e956803..e3dd32b 100644 --- a/js/crsearch/database.js +++ b/js/crsearch/database.js @@ -13,6 +13,7 @@ export default class Database { this._log = log.makeContext('Database') this._name = json.database_name this._base_url = new URL(json.base_url) + this._online_base_url = json.online_base_url ? new URL(json.online_base_url) : null this._path_ns_map = new Map this._ids = [] @@ -97,6 +98,10 @@ export default class Database { return this._base_url } + get online_base_url() { + return this._online_base_url + } + get all_fullpath_pages() { return this._all_fullpath_pages } diff --git a/js/crsearch/index.js b/js/crsearch/index.js index 6a9c5d4..5380e1c 100644 --- a/js/crsearch/index.js +++ b/js/crsearch/index.js @@ -100,7 +100,7 @@ export default class Index { } url() { - return new URL(`/${this.fullpath}.html`, this._ns.base_url) + return new URL(`${this.fullpath}.html`, this._ns.base_url) } get ns() { diff --git a/package-lock.json b/package-lock.json index a9f4215..a422bd8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "crsearch", - "version": "3.0.22", + "version": "3.0.23", "lockfileVersion": 2, "requires": true, "packages": { diff --git a/package.json b/package.json index 6372b4c..df747dd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "crsearch", - "version": "3.0.22", + "version": "3.0.23", "description": "cpprefjp / boostjp searcher", "main": "dist/js/crsearch.js", "module": "js/crsearch.js",