-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake-md.sh
executable file
·78 lines (62 loc) · 2.04 KB
/
make-md.sh
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/bin/bash
# Convert Literate BASH to Jekyll Markdown
# =================================
# text-processing
#
# What the title says. This script powers this repository. If you're viewing
# this as a webpage, it was generated by running this script with it's own
# source code as input.
#
# make-md.sh
# --------------------------
#
# ### Literate BASH Requirements
# We require bash scripts that are intended to be converted to be formatted
# roughly as follows, with the first 10 lines being the essential part:
#
# #!/bin/bash
#
# # Human readable title on this line
# # =================================
# # space-separated tags go here
# #
# # Descriptive excerpt goes here. These end up on the Jekyll home page.
# #
# # First subheading marks end of excerpt
# # -------------------------------------
#
# # We might put some code we actually want executed here...
#
# echo "Hello World!"
#
# # We can even put code in the comments in our code:
# #
# # echo "Infinite recursion happens here. Except it doesn't. Or does it?"
# #
# # Scary, huh?
#
# exit 1
#
# Here's [an actual example of Literate BASH](https://github.com/matt2000/practical-solutions/blob/gh-pages/encrypted-swap.sh)
# in source code form.
# ### And now, teh codez that make that^^ into Markdown that Jekyll can make into HTML.
# Get the date, from the command-line, or from today.
day="$2"
if [[ -z $day ]]
then
day=`date +%Y-%m-%d`
fi
# Store to the Jekyll posts folder.
outfile="_posts/$day-$1.md"
# Strip the hash-bang.
tail -n +3 $1 > $outfile
# Indent everything, so the code gets indented.
sed -i 's/\(^.*$\)/ \1/' $outfile
# Dedent and strip leading # from comments.
sed -i 's/^\s*#$//' $outfile
sed -i 's/^\s*# \(.*$\)/\1/' $outfile
# Add Jekyll front-matter. If we just wanted Markdown and not Jekyll posts, we
# could exit here.
sed -i "1s;^;---\nlayout: post\ntitle: ;" $outfile
# Treat the first line after the Heading as tags, and close out the front-matter.
sed -i '/^===/N;s/=\+\n\(.*\)/tags: \1\n---/' $outfile