HTTPArchive / almanac.httparchive.org

HTTP Archive's annual "State of the Web" report made by the web community

Home Page:https://almanac.httparchive.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Create image dir as part of of figure-images script

rviscomi opened this issue · comments

While trying to run npm run figure-images on a chapter that had no images yet, I got the following error:

$ npm run figure-images en/2021/caching

> almanac.httparchive.org@0.0.1 figure-images
> node ./tools/generate/generate_figure_images "en/2021/caching"

Generating for the 2021 caching chapter:
  Generating image top-cdns.png...
[Error: ENOENT: no such file or directory, open 'static/images/2021/caching/top-cdns.png'] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: 'static/images/2021/caching/top-cdns.png'
}

It's failing because the static/images/2021/caching directory doesn't exist.

Instead of failing, could we create the directory?

Yeah been thinking about that.

I would be worried about typos creating directories in error. Maybe a confirmation prompt would avoid that?

Why would there be typos?

Oh I guess we could only create the dir if we have a chapter md file and/or an image to put in it.

Was more thinking npm run figure-images preformance in error and it just creating a pointless directory.

Could also load JSON config and confirm it’s a valid chapter slug.

Ah ok. Yeah I had imagined that the script would generate the image file path based on the markdown file. I think we can trust that the markdown filename is valid. Won't preformance fail anyway since there is no preformance.md?

Yes, as long as we don’t blindly create the directory at the beginning like I initially (stupidly) presumed - before checking for the existence of the markdown file.