diff --git a/.dockerignore b/.dockerignore index b6200cb..c094d29 100644 --- a/.dockerignore +++ b/.dockerignore @@ -2,9 +2,6 @@ # Ignore the heavy PDFs during build public/files/* -# (Optional) Keep a placeholder file so the directory structure isn't completely lost locally -!public/files/.gitkeep - # Dependency directories node_modules npm-debug.log diff --git a/app/data/documents.json b/app/data/documents.json index b0ea946..2fd3e43 100644 --- a/app/data/documents.json +++ b/app/data/documents.json @@ -3,38 +3,32 @@ { "title": "Turistkarta", "icon": "Map", - "file": "/files/Turistkarta - Kullaberg.pdf", - "size": "2.51 MB" + "file": "/files/Turistkarta - Kullaberg.pdf" }, { "title": "Orienteringskarta", "icon": "MapPlus", - "file": "/files/Orienteringskarta - Kullaberg.pdf", - "size": "3.74 MB" + "file": "/files/Orienteringskarta - Kullaberg.pdf" }, { "title": "Badplatser att besöka", "icon": "WavesLadder", - "file": "/files/Badplatser på Kullaberg.pdf", - "size": "1.88 MB" + "file": "/files/Badplatser på Kullaberg.pdf" }, { "title": "Vandringsrutter", "icon": "MapPinned", - "file": "/files/Vandringsrutter.pdf", - "size": "4.42 MB" + "file": "/files/Vandringsrutter.pdf" }, { "title": "Underlag för guidediplomering", "icon": "BookCopy", - "file": "/files/Underlag för guidediplomering.pdf", - "size": "3.18 MB" + "file": "/files/Underlag för guidediplomering.pdf" }, { "title": "Destinationskunskap Kullahalvön", "icon": "BookCopy", - "file": "/files/Destinationskunskap.pdf", - "size": "1.97 MB" + "file": "/files/Destinationskunskap.pdf" } ], "links": [ diff --git a/app/documents/page.tsx b/app/documents/page.tsx index 0f0be9f..78dcf13 100644 --- a/app/documents/page.tsx +++ b/app/documents/page.tsx @@ -18,6 +18,20 @@ const IconMap: Record = { "FileText": FileText }; +const fetchFileSize = async (url: string) => { + try { + const res = await fetch(url, { method: 'HEAD' }); + const bytes = res.headers.get('content-length'); + if (bytes) { + const mb = (parseInt(bytes) / (1024 * 1024)).toFixed(2); + return `${mb} MB`; + } + } catch (error) { + console.error("Kunde inte hämta filstorlek för", url); + } + return "Okänd"; +}; + export default function Documents() { const [isHydrated, setIsHydrated] = useState(false); const [isOffline, setIsOffline] = useState(false); @@ -48,10 +62,22 @@ export default function Documents() { if (navigator.onLine) { const res = await readJsonFile('documents.json'); if (res.success && res.data) { - setDocs(res.data.docs || []); + const docsWithSizes = await Promise.all( + (res.data.docs || []).map(async (doc: DocumentItem) => { + if (!doc.size || doc.size === "") { + const calculatedSize = await fetchFileSize(doc.file); + return { ...doc, size: calculatedSize }; + } + return doc; + }) + ); + + setDocs(docsWithSizes); setLinks(res.data.links || []); - localStorage.setItem('kullaberg_documents_cache', JSON.stringify(res.data)); - checkCacheStatus(res.data.docs || []); + const dataToCache = { ...res.data, docs: docsWithSizes }; + localStorage.setItem('kullaberg_documents_cache', JSON.stringify(dataToCache)); + + checkCacheStatus(docsWithSizes); } } else { const cachedData = localStorage.getItem('kullaberg_documents_cache'); diff --git a/public/files/.gitkeep b/public/files/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/public/files/Badplatser på Kullaberg.pdf b/public/files/Badplatser på Kullaberg.pdf new file mode 100644 index 0000000..feada97 Binary files /dev/null and b/public/files/Badplatser på Kullaberg.pdf differ diff --git a/public/files/Destinationskunskap.pdf b/public/files/Destinationskunskap.pdf new file mode 100644 index 0000000..3edc6c5 Binary files /dev/null and b/public/files/Destinationskunskap.pdf differ diff --git a/public/files/Orienteringskarta - Kullaberg.pdf b/public/files/Orienteringskarta - Kullaberg.pdf new file mode 100644 index 0000000..732ac7e Binary files /dev/null and b/public/files/Orienteringskarta - Kullaberg.pdf differ diff --git a/public/files/Turistkarta - Kullaberg.pdf b/public/files/Turistkarta - Kullaberg.pdf new file mode 100644 index 0000000..2363686 Binary files /dev/null and b/public/files/Turistkarta - Kullaberg.pdf differ diff --git a/public/files/Underlag för guidediplomering.pdf b/public/files/Underlag för guidediplomering.pdf new file mode 100644 index 0000000..26cbb5d Binary files /dev/null and b/public/files/Underlag för guidediplomering.pdf differ diff --git a/public/files/Vandringsrutter.pdf b/public/files/Vandringsrutter.pdf new file mode 100644 index 0000000..c4c6dbf Binary files /dev/null and b/public/files/Vandringsrutter.pdf differ