chore(deps): upgrade algoliasearch from v4 to v5 lite client

- Update CDN paths to dist/lite/builds/browser.umd.js in jsdelivr.yml and unpkg.yml
- Replace local assets/lib/algoliasearch/algoliasearch-lite.umd.min.js with browser.umd.js
- Update librarybot.yml sync source to dist/lite/builds/browser.umd.js
- Update Hugo template fallback path to lib/algoliasearch/browser.umd.js
- Rewrite search.ts algolia integration to use window['algoliasearch/lite'].liteClient (v5 API, removes initIndex compat)
- Update window type declaration in ui.ts to match v5 UMD global
This commit is contained in:
Cell
2026-06-11 11:42:37 +08:00
parent 53620404e4
commit 9ed063f32d
9 changed files with 90 additions and 57 deletions
+1 -1
View File
@@ -7,7 +7,7 @@ prefix:
simpleIcons: https://cdn.jsdelivr.net/npm/simple-icons@16.22.0/icons/
libFiles:
# algoliasearch@5.53.0 https://github.com/algolia/algoliasearch-client-javascript
algoliasearchJS: algoliasearch@5.53.0/dist/algoliasearch-lite.umd.min.js
algoliasearchJS: algoliasearch@5.53.0/dist/lite/builds/browser.umd.js
# animate.css@4.1.1 https://github.com/daneden/animate.css
animateCSS: animate.css@4.1.1/animate.min.css
# aplayer@1.10.1 https://github.com/MoePlayer/APlayer
+1 -1
View File
@@ -7,7 +7,7 @@ prefix:
simpleIcons: https://unpkg.com/simple-icons@16.22.0/icons/
libFiles:
# algoliasearch@5.53.0 https://github.com/algolia/algoliasearch-client-javascript
algoliasearchJS: algoliasearch@5.53.0/dist/algoliasearch-lite.umd.js
algoliasearchJS: algoliasearch@5.53.0/dist/lite/builds/browser.umd.js
# animate.css@4.1.1 https://github.com/daneden/animate.css
animateCSS: animate.css@4.1.1/animate.min.css
# aplayer@1.10.1 https://github.com/MoePlayer/APlayer
+31 -6
View File
@@ -177,12 +177,37 @@ export class SearchModule implements SearchService {
callback(results)
}
if (searchConfig.type === 'algolia') {
this.#algoliaIndex
= this.#algoliaIndex
|| window.algoliasearch!(
searchConfig.algoliaAppID,
searchConfig.algoliaSearchKey,
).initIndex(searchConfig.algoliaIndex)
if (!this.#algoliaIndex) {
// Algolia v5 lite UMD exposes window['algoliasearch/lite'].liteClient.
const liteClient = (window as any)['algoliasearch/lite']?.liteClient
if (!liteClient) {
console.error('Algolia client is not available on window')
finish([])
return
}
const client = liteClient(searchConfig.algoliaAppID, searchConfig.algoliaSearchKey)
this.#algoliaIndex = {
search: (queryText: string, params: Record<string, any> = {}) => {
const {
offset,
length,
...rest
} = params
const request: Record<string, any> = {
indexName: searchConfig.algoliaIndex,
query: queryText,
...rest,
}
if (typeof length === 'number')
request.hitsPerPage = length
if (typeof offset === 'number' && typeof length === 'number' && length > 0)
request.page = Math.floor(offset / length)
return client
.search({ requests: [request] })
.then((response: any) => ({ hits: response.results?.[0]?.hits ?? [] }))
},
}
}
this.#algoliaIndex
.search(query, {
offset: 0,
+37 -37
View File
@@ -36,44 +36,44 @@ declare global {
interface Window {
// Third-party libraries
autocomplete?: any
algoliasearch?: any
Artalk?: any
APlayer?: any
CellTooltip?: any
cookieconsent?: any
CryptoJS?: any
echarts?: any
Fuse?: any
Gitalk?: any
JsonViewerElement?: any
lgThumbnail?: any
lgZoom?: any
lightGallery?: any
mapboxgl?: any
MapboxLanguage?: any
MathJax?: any
objectFitImages?: () => void
pangu?: any
postChatUser?: any
postChatConfig?: any
postChat_theme?: string
twemoji?: any
twikoo?: any
TypeIt?: any
Valine?: any
Waline?: any
Watermark?: any
xxhash?: any
Panzoom?: (element: SVGElement, options?: Record<string, unknown>) => PanzoomInstance
'autocomplete'?: any
'algoliasearch/lite'?: { liteClient: (...args: any[]) => any }
'Artalk'?: any
'APlayer'?: any
'CellTooltip'?: any
'cookieconsent'?: any
'CryptoJS'?: any
'echarts'?: any
'Fuse'?: any
'Gitalk'?: any
'JsonViewerElement'?: any
'lgThumbnail'?: any
'lgZoom'?: any
'lightGallery'?: any
'mapboxgl'?: any
'MapboxLanguage'?: any
'MathJax'?: any
'objectFitImages'?: () => void
'pangu'?: any
'postChatUser'?: any
'postChatConfig'?: any
'postChat_theme'?: string
'twemoji'?: any
'twikoo'?: any
'TypeIt'?: any
'Valine'?: any
'Waline'?: any
'Watermark'?: any
'xxhash'?: any
'Panzoom'?: (element: SVGElement, options?: Record<string, unknown>) => PanzoomInstance
// FixIt theme
fixit: FixItPublicAPI
config: FixItConfig
mermaid?: MermaidRuntimeModule
_fuseIndex?: any
_searchMobile?: any
_searchDesktop?: any
FixItDecryptor?: any
'fixit': FixItPublicAPI
'config': FixItConfig
'mermaid'?: MermaidRuntimeModule
'_fuseIndex'?: any
'_searchMobile'?: any
'_searchDesktop'?: any
'FixItDecryptor'?: any
}
}
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long