Verified Commit 6bbaf11e authored by Adam Matoušek's avatar Adam Matoušek
Browse files

Markdown support for articles

parent 8ad81946
Loading
Loading
Loading
Loading
+13 −1
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@ set cc /usr/bin/cc
set cflags -O2
set outdir _build
set prefix $(srcdir)/_deploy
set markdown markdown

# for gib -V dbg
set dbg
@@ -150,7 +151,18 @@ out nav.html
dep generate navigation
use transient

# TODO: md2html or sth
# markdown
for c $(srcdir)/$(sources:articles/*/content.md)
out $(c:$(srcdir)/articles/*.md:$1).tt.html
dep $(c)
dep article dirs
cmd $(tool) into $(out) $(markdown) $(c)

for c $(unbundled-files:*.md)
out $(c:*.md:$1).tt.html
dep $(c)
dep article dirs
cmd $(tool) into $(out) $(markdown) $(c)

# copy ready-made (templated) .htmls
for c $(sources:articles/*/content.html)
+24 −4
Original line number Diff line number Diff line
#!/bin/sh
#!/bin/bash
set -e
bundle="$1"
dstdir="$2"

sed -ne '/^$/q;p' < "$bundle" > "$dstdir/meta"
sed -ne '1,/^$/d;p' < "$bundle" > "$dstdir/content.tt.html"
metafile="$dstdir/meta"
tmpfile="$dstdir/content.tmp"

sed -ne '/^$/q;p' < "$bundle" > "$metafile"
sed -ne '1,/^$/d;p' < "$bundle" > "$tmpfile"

# Guess content type (or use the specified one)
content_type=$(sed -ne 's/^Content-Type:\s*//p' "$metafile")
if [[ -z "$content_type" ]] ; then
    if grep -s '<p>' "$tmpfile" ; then
        suffix='tt.html'
    else
        suffix='md'
    fi
elif [[ "$content_type" =~ html ]] ; then
    suffix='tt.html'
elif [[ "$content_type" =~ md ]] || [[ "$content_type" =~ markdown ]] ; then
    suffix='md'
fi

mv "$tmpfile" "$dstdir/content.$suffix"

echo "set unbundled-files.$dstdir" > "$dstdir/bundle.gib"
echo "add= unbundled-files.$dstdir content.tt.html" >> "$dstdir/bundle.gib"
echo "add= unbundled-files.$dstdir content.$suffix" >> "$dstdir/bundle.gib"
echo >> "$dstdir/bundle.gib"