diff options
Diffstat (limited to '')
-rw-r--r-- | v2/dynamic.mk | 4 | ||||
-rwxr-xr-x | v2/src/bin/extract | 18 |
2 files changed, 14 insertions, 8 deletions
diff --git a/v2/dynamic.mk b/v2/dynamic.mk index 01b8917..b9cd5fc 100644 --- a/v2/dynamic.mk +++ b/v2/dynamic.mk @@ -25,10 +25,10 @@ include generated.mk sh src/development/genhtml.sh $< > $@ .md.entry-content: - extract -t content < $? > $@ + extract -t content $? > $@ .md.entry-env: - extract -t env < $? > $@ + extract -t env $? > $@ pastebins.html = $(pastebins.md:.md=.html) diff --git a/v2/src/bin/extract b/v2/src/bin/extract index ce4b115..4380be7 100755 --- a/v2/src/bin/extract +++ b/v2/src/bin/extract @@ -5,7 +5,7 @@ set -eu usage() { cat <<-'EOF' Usage: - extract -t TYPE < STDIN + extract -t TYPE FILENAME extract -h EOF } @@ -17,21 +17,24 @@ help() { -t TYPE the type of extraction to perform ("content" or "env") -h, --help show this message + FILENAME the name of the input file, also to be used as + URL. + Separate the content from the "frontmatter", and emit the - selected one. + selected one, given the FILENAME. Examples: Get the content: - $ extract -t content < src/file.md > src/file.entry-content + $ extract -t content src/file.md > src/file.entry-content Get the "frontmatter": - $ extract -t env < src/f.md > src/f.entry-env + $ extract -t env src/f.md > src/f.entry-env EOF } @@ -71,6 +74,8 @@ done shift $((OPTIND - 1)) +FILENAME="${1:-}" +eval "$(assert-arg "$FILENAME" 'FILENAME')" eval "$(assert-arg "$TYPE" '-t TYPE')" @@ -79,7 +84,7 @@ case "$TYPE" in awk ' separator >= 2 /^---$/ { separator++ } - ' + ' "$FILENAME" ;; env) awk ' @@ -92,7 +97,8 @@ case "$TYPE" in } { print } - ' + ' "$FILENAME" + printf "FILENAME='%s'\n" "$FILENAME" ;; *) printf 'Bad value for TYPE: "%s".\n\n' \ |