[READ-ONLY] Mirror of https://github.com/danielroe/dwaring87-webdev-wedding. Marissa & David's Wedding Website!
0

Configure Feed

Select the types of activity you want to include in your feed.

Images: cache static image data to file instead of memory

+23 -9
+2 -1
.gitignore
··· 7 7 .env 8 8 dist 9 9 .DS_Store 10 - .env 10 + .env 11 + .static_images.txt
+19 -5
modules/nuxt-image-generator/index.js
··· 23 23 addImportsDir(resolve(runtimeDir, 'composables')); 24 24 25 25 // Set runtime options 26 - nuxt.options.runtimeConfig.public.nuxt_image_generator = { root_dir: nuxt.options.rootDir, output_dir, image_dir }; 27 - nuxt.options.image.static_images = { }; 26 + const cache = resolve(nuxt.options.rootDir, ".static_images.txt"); 27 + nuxt.options.runtimeConfig.public.nuxt_image_generator = { root_dir: nuxt.options.rootDir, cache, output_dir, image_dir }; 28 + 29 + // Remove existing cache file 30 + fs.rm(cache, { force: true }); 28 31 29 32 // Set Close Hook (generate local images) 30 33 nuxt.hook('close', generateImages); ··· 39 42 const generateImages = async (nuxt) => { 40 43 41 44 // Get runtime options 42 - const { root_dir, output_dir, image_dir } = nuxt.options.runtimeConfig.public.nuxt_image_generator; 43 - const images = nuxt.options.image.static_images; 45 + const { cache, root_dir, output_dir, image_dir } = nuxt.options.runtimeConfig.public.nuxt_image_generator; 44 46 45 47 // Generate the during nuxt static generation 46 - if ( nuxt.options._generate && Object.keys(images).length > 0 ) { 48 + if ( nuxt.options._generate ) { 49 + 50 + // Read cache file and parse into images object 51 + const images = {}; 52 + const cache_contents = await fs.readFile(cache, 'utf-8'); 53 + const lines = cache_contents.split(/\r?\n/); 54 + lines.forEach((line) => { 55 + const [hash, url, image_name] = line.split('\t'); 56 + if ( hash && hash !== '' && url && image_name ) { 57 + images[hash] = { url, image_name }; 58 + } 59 + }); 60 + 47 61 console.log("Generating " + Object.keys(images).length + " static images..."); 48 62 const full_path_image_dir = (`${root_dir}/${output_dir}/${image_dir}`).replaceAll('//', '/'); 49 63
+2 -3
modules/nuxt-image-generator/runtime/composables/useNuxtImageGenerator.js
··· 1 - import { useNuxt } from "@nuxt/kit"; 1 + import fs from 'fs/promises'; 2 2 3 3 export const useNuxtImageGenerator = () => { 4 4 ··· 18 18 19 19 // Save image properties for prerender 20 20 if ( process.env.prerender ) { 21 - const nuxt = useNuxt(); 22 - nuxt.options.image.static_images[hash] = { url, image_name }; 21 + fs.appendFile(props.cache, [hash, url, image_name].join('\t') + '\n', { encoding: 'utf-8', flag: 'as' }); 23 22 } 24 23 25 24 return image_web_path;