Skip to content

Instantly share code, notes, and snippets.

@markandrus
Last active January 5, 2023 08:02
Show Gist options
  • Save markandrus/d5116bc621ca641acd33 to your computer and use it in GitHub Desktop.
Save markandrus/d5116bc621ca641acd33 to your computer and use it in GitHub Desktop.
Makefile to convert a directory of Markdown sources to HTML
SRC_MD_FILES=$(shell find src -name \*.md)
MD_FILES=$(SRC_MD_FILES:src/%=%)
HTML_FILES=$(MD_FILES:.md=.html)
BUILD_HTML_FILES=$(HTML_FILES:%=build/%)
all: $(BUILD_HTML_FILES)
build/%.html: src/%.md
mkdir -p $$(dirname $@)
pandoc -o $@ $?
clean:
rm -rf build
.PHONY: clean
@markandrus
Copy link
Author

$ tree
.
├── Makefile
└── src
    ├── a.md
    └── b
        └── b.md

2 directories, 3 files
$ make
mkdir -p $(dirname build/a.html)
pandoc -o build/a.html src/a.md
mkdir -p $(dirname build/b/b.html)
pandoc -o build/b/b.html src/b/b.md
$ tree
.
├── Makefile
├── build
│   ├── a.html
│   └── b
│       └── b.html
└── src
    ├── a.md
    └── b
        └── b.md

4 directories, 5 files

@travula
Copy link

travula commented Feb 11, 2018

@markandrus
Thanks, I am using this makefile

@travula
Copy link

travula commented Feb 12, 2018

@markandrus
Is there a way to generate a sitemap.html ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment