mirror of
https://github.com/Sped0n/bridget.git
synced 2026-04-17 03:29:31 -07:00
* refactor: refactor navigateVector logic and remove unused functions * refactor: refactor HTML structure and styling in single.html - Modify the `.info` class to `article` in `_article.scss` - Remove the `nav.html` partial in `single.html` - Change the class name from `info` to `article` in `single.html` - Add the `nav.html` partial in `single.html` * refactor: update handling of 404 page - Now hugo will set unknown page title as "404" - Add condition to return an empty image array if the document title starts with "404" * docs: update documentation
34 lines
720 B
TypeScript
34 lines
720 B
TypeScript
// data structure for images info
|
|
export interface ImageJSON {
|
|
index: number
|
|
alt: string
|
|
loUrl: string
|
|
loImgH: number
|
|
loImgW: number
|
|
hiUrl: string
|
|
hiImgH: number
|
|
hiImgW: number
|
|
}
|
|
|
|
export async function initResources(): Promise<ImageJSON[]> {
|
|
if (document.title.split(' | ')[0] === '404') {
|
|
return [] // no images on 404 page
|
|
}
|
|
try {
|
|
const response = await fetch(`${window.location.href}index.json`, {
|
|
headers: {
|
|
Accept: 'application/json'
|
|
}
|
|
})
|
|
const data: ImageJSON[] = await response.json()
|
|
return data.sort((a: ImageJSON, b: ImageJSON) => {
|
|
if (a.index < b.index) {
|
|
return -1
|
|
}
|
|
return 1
|
|
})
|
|
} catch (_) {
|
|
return []
|
|
}
|
|
}
|