lanhu-summarize.mjs 800 B

123456789101112131415161718192021
  1. import { readFile } from 'node:fs/promises';
  2. const source = new URL('./lanhu-flash-delivery/analysis.json', import.meta.url);
  3. const payload = JSON.parse(await readFile(source, 'utf8'));
  4. for (const design of payload.designs ?? []) {
  5. const annotations = design.sketch_annotations ?? '';
  6. const textStart = annotations.indexOf('📝 文本图层:');
  7. const shapeStart = annotations.indexOf('🔷 形状图层:');
  8. const textSection = textStart >= 0
  9. ? annotations.slice(textStart, shapeStart >= 0 ? shapeStart : undefined)
  10. : '';
  11. const texts = [...textSection.matchAll(/^ "(.+)"$/gm)].map((match) => match[1]);
  12. console.log(JSON.stringify({
  13. name: design.name,
  14. status: design.status,
  15. imageBytes: design.image_bytes,
  16. layoutSource: design.layout_source,
  17. texts
  18. }));
  19. }