Skip to content

Commit 5205ba2

Browse files
Merge pull request #69 from akinomyoga/relative_link
内部リンクを相対リンクで生成する機能 (cpprefjp/site_generator#81)
2 parents ea24591 + 0fab6a0 commit 5205ba2

6 files changed

Lines changed: 42 additions & 7 deletions

File tree

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,22 @@
22

33
## master
44

5+
## 3.0.23 (2024-05-18)
6+
7+
- "内部リンクを相対リンクで生成する機能"にまつわる修正を適用
8+
9+
## 3.0.22 (2022-11-06)
10+
11+
- 依存ライブラリを修正
12+
13+
## 3.0.21 (2022-11-06)
14+
15+
- 依存ライブラリを修正
16+
17+
## 3.0.20 (2022-11-06)
18+
19+
- 依存ライブラリを修正
20+
521
## 3.0.19 (2022-11-06)
622

723
- 依存ライブラリを更新

js/crsearch/crsearch.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ export default class CRSearch {
2525
},
2626
google_url: new URL('https://www.google.co.jp/search'),
2727
force_new_window: false,
28+
base_url: null,
29+
online_base_url: null,
2830
}
2931

3032
static _KLASS = 'crsearch'
@@ -98,10 +100,16 @@ export default class CRSearch {
98100
this._log.info(`fetching database (${i + 1}/${size}): ${url}`)
99101

100102
try {
101-
const data = await $.ajax({
103+
const ajaxSettings = {
102104
url: url,
103105
dataType: "json",
104-
})
106+
}
107+
if (/\.js([?#].*)?$/.test(url.toString())) {
108+
ajaxSettings.dataType = "jsonp"
109+
ajaxSettings.jsonpCallback = "callback"
110+
ajaxSettings.crossDomain = true
111+
}
112+
const data = await $.ajax(ajaxSettings)
105113

106114
this._log.info('fetched')
107115
this._parse(url, data)
@@ -118,6 +126,10 @@ export default class CRSearch {
118126

119127
_parse(url, json) {
120128
this._log.info('parsing...', json)
129+
if (this._opts.base_url)
130+
json.base_url = this._opts.base_url
131+
if (this._opts.online_base_url)
132+
json.online_base_url = this._opts.online_base_url
121133

122134
const db = new Database(this._log, json)
123135
this._db.set(db.name, db)
@@ -229,9 +241,10 @@ export default class CRSearch {
229241

230242
for (const [name, db] of this._db) {
231243
// always include fallback
244+
const fallback_site = db.online_base_url ? db.online_base_url.host : db.base_url.host
232245
const e = this._make_result(null, q.original_text, {
233246
name: db.name,
234-
url: db.base_url.host,
247+
url: fallback_site,
235248
})
236249
e.attr('data-result-id', result_id++)
237250
result_list.append(e)
@@ -266,7 +279,8 @@ export default class CRSearch {
266279

267280
_make_google_url(q, site) {
268281
const url = this._opts.google_url
269-
url.set('query', {q: `${q} site:${site}`})
282+
if (site != '') q = `${q} site:${site}`
283+
url.set('query', {q: q})
270284
return url
271285
}
272286

js/crsearch/database.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export default class Database {
1313
this._log = log.makeContext('Database')
1414
this._name = json.database_name
1515
this._base_url = new URL(json.base_url)
16+
this._online_base_url = json.online_base_url ? new URL(json.online_base_url) : null
1617
this._path_ns_map = new Map
1718
this._ids = []
1819

@@ -97,6 +98,10 @@ export default class Database {
9798
return this._base_url
9899
}
99100

101+
get online_base_url() {
102+
return this._online_base_url
103+
}
104+
100105
get all_fullpath_pages() {
101106
return this._all_fullpath_pages
102107
}

js/crsearch/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ export default class Index {
100100
}
101101

102102
url() {
103-
return new URL(`/${this.fullpath}.html`, this._ns.base_url)
103+
return new URL(`${this.fullpath}.html`, this._ns.base_url)
104104
}
105105

106106
get ns() {

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "crsearch",
3-
"version": "3.0.22",
3+
"version": "3.0.23",
44
"description": "cpprefjp / boostjp searcher",
55
"main": "dist/js/crsearch.js",
66
"module": "js/crsearch.js",

0 commit comments

Comments
 (0)