-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2md
More file actions
executable file
·79 lines (70 loc) · 1.72 KB
/
2md
File metadata and controls
executable file
·79 lines (70 loc) · 1.72 KB
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
79
#!/usr/bin/env bash
# todo. add yaml front matter include "code: true"
Top=$(git rev-parse --show-toplevel)
There=$Top/../web
Url="https://github.com/se4ai/code/tree/master"
md2md() {
cat $1 | gawk '
/^# /{ sub(/^#/,"")
print "---"
print "title: \"" $0 "\""
print "layout: default"
print "---"
next
}
1 '
}
py2md() {
url="$2"
file="$1"
cat $file | gawk 'BEGIN {
q="\""
print ""
First = 1
In = 1
}
/^# /{ sub(/^#/,"")
print "---"
print "title: \"" $0 "\""
print "layout: default"
print "code: true"
print "---"
print ""
print "Read the code on [Github]('$url') <font color=orange><i class=\"fab fa-github-3x\"></i></font>."
print ""
}
/^"""</,/^>"""/ { next }
/^"""/ { In = 1 - In
if (In)
print "````python"
else
if (First)
First = 0
else
print "````"
next }
! First { print (In ? sprintf("%4s. ",++n) : "") $0 }
END { if (In) print "````"
}'
}
main() {
com=$2
arg=$1
file=$(basename $arg)
stem="${file%%.*}"
out=$There/${stem}.md
rm -rf $out
#if [ "$1" -nt "$out" ]; then
echo "# $(basename $arg) ==> $out"
$com $1 $Url/$file > $out
(cd $There; git add $out)
#fi
}
mkdir -p $There/img
cp $Top/img/* $There/img
(cd $There; git add $There/img/*)
for f in src/*.py; do main $f py2md ; done
for f in src/*.md; do main $f md2md ; done
cd $There
git commit -am as
git push