diff options
Diffstat (limited to 'bin/mail/comment.sh')
-rwxr-xr-x | bin/mail/comment.sh | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/bin/mail/comment.sh b/bin/mail/comment.sh index 6c95dc3..be86070 100755 --- a/bin/mail/comment.sh +++ b/bin/mail/comment.sh | |||
@@ -3,21 +3,29 @@ | |||
3 | # Save incoming mail as comment | 3 | # Save incoming mail as comment |
4 | # Usage: | 4 | # Usage: |
5 | # Step1. Add script into forward(5) for MDA | 5 | # Step1. Add script into forward(5) for MDA |
6 | # echo '|<PATH_TO_THIS_SCRIPT> --output_dir=<PATH_OF_HTML_FILES>' >>~/.forward | 6 | # Some MDA won't accept arguments for command. If --output_dir is not specified, |
7 | # directory of this script would be used instead | ||
8 | # | ||
9 | # echo '|<PATH_TO_THIS_SCRIPT> --output_dir <PATH_OF_HTML_FILES>' >>~/.forward | ||
7 | # | 10 | # |
8 | # Step2. Insert related html file into target page, the following example use <object> element | 11 | # Step2. Insert related html file into target page, the following example use <object> element |
9 | # Please replace <PATH> for your target page: | 12 | # * Please replace <PATH> for your target page, relative to value of --output_dir |
13 | # * Set <RECIPIENT> for mail address which can achive MDA | ||
14 | # * Change <PATH> in data attribute of <object> based on routing if necessary | ||
15 | # | ||
16 | # <!-- START OF COMMENT BLOCK --> | ||
10 | # <div style="border-radius: 6px; background: lightyellow"> | 17 | # <div style="border-radius: 6px; background: lightyellow"> |
11 | # <a style="display: inline-block; margin: 0.5em 0.5em 0 0; float: right" href="mailto:comment@topo.tw?subject=Comment on page: ${path}">[Comment on this page]</a> | 18 | # <a style="display: inline-block; margin: 0.5em 0.5em 0 0; float: right" href="mailto:<RECIPIENT>?subject=Comment on page: <PATH>">[Comment on this page]</a> |
12 | # <object type="text/html" data="/<PATH>.comment.html" onload="observeResize(this)" style="width: 100%;"></object> | 19 | # <object type="text/html" data="<PATH>.comment.html" onload="observeResize(this)" style="width: 100%;"></object> |
13 | # <script> | 20 | # <script> |
14 | # function observeResize(commentBlock) { | 21 | # function observeResize(commentBlock) { |
15 | # new ResizeObserver((entries) => { | 22 | # new ResizeObserver((entries) => { |
16 | # commentBlock.style.height = entries[-1].clientHeight + 'px'; | 23 | # commentBlock.style.height = entries[0].target.clientHeight + 'px'; |
17 | # }).observe(commentBlock.contentDocument.documentElement); | 24 | # }).observe(commentBlock.contentDocument.documentElement); |
18 | # } | 25 | # } |
19 | # </script> | 26 | # </script> |
20 | # </div> | 27 | # </div> |
28 | # <!-- END OF COMMENT BLOCK --> | ||
21 | 29 | ||
22 | # 1. Check mail is for comment {{{ | 30 | # 1. Check mail is for comment {{{ |
23 | 31 | ||
@@ -43,9 +51,10 @@ while [[ "$1" =~ ^-- && ! "$1" == "--" ]]; do | |||
43 | shift | 51 | shift |
44 | done | 52 | done |
45 | 53 | ||
46 | output_dir=${output_dir:?} | 54 | export PATH=/bin:/usr/bin:/usr/local/bin:~/.local/bin |
47 | markdown_bin=${markdown_bin:-markdown} | 55 | output_dir=${output_dir:-$(dirname $0)} |
48 | [ -x $(which $markdown_bin) ] || markdown_bin=cat | 56 | markdown_bin=${markdown_bin:-$(which markdown)} |
57 | [ -x "$markdown_bin" ] || markdown_bin=cat | ||
49 | 58 | ||
50 | # }}} | 59 | # }}} |
51 | # 3. Read header fields {{{ | 60 | # 3. Read header fields {{{ |
@@ -74,10 +83,11 @@ if [ $path = "" ]; then | |||
74 | fi | 83 | fi |
75 | 84 | ||
76 | # get output path | 85 | # get output path |
77 | [[ "$path" =~ '/$' ]] && path+=index | 86 | [[ "$path" =~ /$ ]] && path+=index |
78 | path=${path#/} | 87 | path=${path#/} |
79 | path=${path/.html} | 88 | path=${path/.html} |
80 | output=$output_dir/${path}.comment.html | 89 | output=$output_dir/${path}.comment.html |
90 | umask 022; mkdir -p $(dirname $output) | ||
81 | 91 | ||
82 | # }}} | 92 | # }}} |
83 | # 5. Get comment from mail body {{{ | 93 | # 5. Get comment from mail body {{{ |
@@ -93,6 +103,7 @@ fi | |||
93 | # }}} | 103 | # }}} |
94 | # 6. Write comment to output file {{{ | 104 | # 6. Write comment to output file {{{ |
95 | 105 | ||
106 | umask 133 | ||
96 | # add basic html layout for output file if necessary {{{ | 107 | # add basic html layout for output file if necessary {{{ |
97 | if [ ! -f $output ] || ! xmllint --html --nofixup-base-uris $output &>/dev/null; then | 108 | if [ ! -f $output ] || ! xmllint --html --nofixup-base-uris $output &>/dev/null; then |
98 | <<-LAYOUT cat >$output | 109 | <<-LAYOUT cat >$output |
@@ -161,4 +172,4 @@ COMMENT | |||
161 | 172 | ||
162 | # }}} | 173 | # }}} |
163 | 174 | ||
164 | # vim:fdm=marker | 175 | # vim:fdm=marker fdl=0 |