summaryrefslogtreecommitdiff
path: root/build-index.sh
blob: 5fd7d14ecdee31065f1df06abfa4260ded1aa676 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/bin/bash

INPUT=$1
# OUTPUT=$3

# COMMIT_DATE=$(git log -n 1 --pretty=format:%cd --date=format:'%Y-%m-%dT%H:%M:%S' -- $INPUT)
# COMMIT_HASH=$(git log -n 1 --pretty=format:%h -- $INPUT)

# find all files not named `index.txt` in $INPUT folder,
# extract text after the `title: ` field and append it to file
# find $INPUT -name "*.txt" ! -name "index.txt" -type f -exec sed -n 's/^title:[[:space:]]*//p' {} \; > output.txt

# cd $INPUT
# find . -name "*.txt" ! -name "index.txt" -type f \
#   -exec sed -n 's/^title:[[:space:]]*//p' {} \;

extracttitle () {
  local file=$1
  sed -n "s/^title:[[:space:]]*//p"
}

{
		printf '%s\n' "# All posts"
		# local f
		for f in ????-??-??-*.md; do
			printf -- ':::\n[%s](%s)\n:::indexTitle\n\n:::\n%s\n:::indexDate\n\n' \
				"$(extracttitle "$f")" "${f/%.txt/.html}" "${f:0:10}" 
			md2html "$f"
		done | tac
	} > output.txt