both of these scripts break on perfectly valid filenames with whitespace, it's pretty rough how shell scripting directs you towards writing subtly broken scripts.
Perfectly valid file names in your case can be quite poor choice of names in the context of generating static site. And even if the code could be perfectly runnable, I expect them to be pseudo-code here to illustrate a point, not to ask people to run it.