Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

- 依存ライブラリを更新
Expand Down
22 changes: 18 additions & 4 deletions js/crsearch/crsearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
}

Expand Down
5 changes: 5 additions & 0 deletions js/crsearch/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []

Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion js/crsearch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down