Sample Header Ad - 728x90

Map over file tree, preserving structure

0 votes
2 answers
247 views
I have a file tree that looks like:
$ tree src
src
├── bible
│   ├── index.md
│   └── README.md
├── index.md
└── other.md
I want to render every Markdown file within this file tree to HTML via pandoc(1) -- **preserving structure**. This new file tree should be rooted at out, like so:
$ tree out
out
├── bible
│   ├── index.html
│   └── README.html
├── index.html
└── other.html
Ideally, I'd like to do this via make(1). This is what I have so far:
SRC_DIR=src
OUT_DIR=out

.PHONY: all
all: $(SRC_DIR)/*.md
	find . -name "*.md" -exec pandoc '{}' -o '{}'.html \;
	find -name "*.html" -exec bash -c 'mv {} $(OUT_DIR)/dirname {}/basename {} .md.html.html' \;
	# mv $(SRC_DIR)/*.html $(OUT_DIR)
	firefox $(OUT_DIR)/index.html

.PHONY: clean
clean:
	rm $(OUT_DIR)/*.html
This fails:
$ make
find . -name "*.md" -exec pandoc '{}' -o '{}'.html \;
find . -name "*.html" -exec bash -c 'mv {} basename {} .md.html.html' \;
mv src/*.html out
mv: cannot stat 'src/*.html': No such file or directory
make: *** [Makefile:8: all] Error 1
Asked by jmcph4 (75 rep)
Jul 16, 2021, 03:28 AM
Last activity: Jul 16, 2021, 04:19 PM