diff --git a/.prettierignore b/.prettierignore index f349520..136eb57 100644 --- a/.prettierignore +++ b/.prettierignore @@ -3,3 +3,4 @@ static exmapleSite *.yaml *.yml +single.json diff --git a/assets/ts/main.ts b/assets/ts/main.ts index 1177033..455ae77 100644 --- a/assets/ts/main.ts +++ b/assets/ts/main.ts @@ -5,7 +5,7 @@ import { initState } from './state' import { isMobile } from './utils' initContainer() -const ijs = initResources() +const ijs = await initResources() initState(ijs.length) initNav() diff --git a/assets/ts/resources.ts b/assets/ts/resources.ts index 1adbb21..2a2effa 100644 --- a/assets/ts/resources.ts +++ b/assets/ts/resources.ts @@ -10,17 +10,21 @@ export interface ImageJSON { hiImgW: number } -export function initResources(): ImageJSON[] { - const imagesJson = document.getElementById('imagesSource') - if (imagesJson === null) { - return [] - } - return JSON.parse(imagesJson.textContent as string).sort( - (a: ImageJSON, b: ImageJSON) => { +export async function initResources(): Promise { + 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 [] + } } diff --git a/exampleSite/config/_default/outputs.toml b/exampleSite/config/_default/outputs.toml new file mode 100644 index 0000000..71e14da --- /dev/null +++ b/exampleSite/config/_default/outputs.toml @@ -0,0 +1 @@ +page = ["HTML", "JSON"] diff --git a/layouts/404.html b/layouts/404.html index e47c069..9ac594c 100644 --- a/layouts/404.html +++ b/layouts/404.html @@ -2,7 +2,6 @@ {{- $params := .Scratch.Get "params" -}} {{- $currentPage := . -}} {{- with partial "function/currentMenuItem.html" . -}} - {{- partial "resources/imageJSON.html" (dict "Path" .DirName "Page" $currentPage) -}} {{- end -}}
diff --git a/layouts/_default/single.html b/layouts/_default/single.html index 704e561..214cfef 100644 --- a/layouts/_default/single.html +++ b/layouts/_default/single.html @@ -2,7 +2,6 @@ {{- $params := .Scratch.Get "params" -}} {{- $currentPage := . -}} {{- with partial "function/currentMenuItem.html" . -}} - {{- partial "resources/imageJSON.html" (dict "Path" .DirName "Page" $currentPage) -}} + {{ $Page.Scratch.Get "img" | jsonify }} +{{- else -}} +[] {{- end -}}