add offline support
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
|
||||
/** Only the app shell; route data is downloaded separately on explicit request. */
|
||||
export function offlineManifest(publicDirectory) {
|
||||
const resources = new Set(['/']);
|
||||
const appDirectories = new Set(['css', 'js', 'vendor', 'assets', 'images']);
|
||||
function visit(directory, prefix = '') {
|
||||
for (const entry of fs.readdirSync(directory, { withFileTypes: true })) {
|
||||
if (entry.name.startsWith('.')) continue;
|
||||
if (!prefix && entry.isDirectory() && !appDirectories.has(entry.name)) continue;
|
||||
if (prefix === '/images' && entry.isDirectory() && !['icons', 'group-symbols'].includes(entry.name)) continue;
|
||||
const relative = `${prefix}/${encodeURIComponent(entry.name)}`;
|
||||
if (entry.isDirectory()) visit(path.join(directory, entry.name), relative);
|
||||
else if (entry.isFile() && /\.(?:html|css|js|svg|png|webp|jpg|jpeg|gif|ico|woff2?)$/i.test(entry.name)) resources.add(relative);
|
||||
}
|
||||
}
|
||||
visit(publicDirectory);
|
||||
return { resources: [...resources].sort() };
|
||||
}
|
||||
Reference in New Issue
Block a user