home · contact · privacy
Simplify all.do script.
[redo-blog] / processor / helpers.sh
1 #!/bin/sh
2
3 escape_html() {
4   out=`python3 -c 'import sys, html; print(html.escape(sys.argv[1]))' "$1"`
5   printf "%s" "$out"
6 }
7
8 read_and_escape_file() {
9   in=`cat "$1"`
10   escape_html "$in"
11 }
12
13 escape_url() {
14   out=`python3 -c 'import sys, urllib.parse; print(urllib.parse.quote(sys.argv[1]))' "$1"`
15   printf "%s" "$out"
16 }
17
18 get_basepath() {
19   url_file="$1"url
20   redo-ifchange "$url_file"
21   base_url=`cat "$url_file" | head -1`
22   url_protocol=`echo $base_url | cut -d ':' -f 1`
23   url_basepath=`echo $base_url | cut -d '/' -f 3-`
24   url_basepath_escaped=`escape_url "$url_basepath"`
25   basepath="$url_protocol""://""$url_basepath_escaped"
26   echo "$basepath"
27 }
28
29 get_source_file() {
30   md_file="../${1%.*}.md"
31   rst_file="../${1%.*}.rst"
32   if [ -f "$rst_file" ]; then
33     src_file="$rst_file"
34   elif [ -f "$md_file" ]; then
35     src_file="$md_file"
36   else
37     exit 1
38   fi
39   redo-ifchange "$src_file"
40   printf "$src_file"
41 }