tinycm view plugins/export/export.cgi @ rev 33

Tiny edits
author Paul Issott <paul@slitaz.org>
date Mon Jan 06 21:22:04 2014 +0000 (2014-01-06)
parents 09f5185ff6e0
children c4a472d0a45e
line source
1 #!/bin/sh
2 #
3 # TinyCM Plugin - Export to static content
4 #
5 . /usr/lib/slitaz/httphelper
7 #
8 # NOTE: Exporting wiki and making all urls work is a bit tricky and
9 # actually doesn't work as expected. The goal is to have a SliTaz codex
10 # online that can be included on the ISO, so we could have an export
11 # including a small CGI script to simply display wiki pages via HTTPd
12 # knowing that with HTML we must also deal with ../../
13 #
15 if [ "$(GET export)" ]; then
16 d="Export"
17 date=$(date "+%Y%m%d")
18 tmpdir="$tmp/export/$$/wiki-$date"
19 header
20 html_header
21 user_box
22 cat << EOT
23 <h2>Export</h2>
24 <p>
25 $(gettext "EXPERIMENTAL: Export to HTML and create a tarball of your text
26 content or plugins files.")
27 </p>
28 <form method="get" action="$WEB_URL">
29 <select name="export">
30 EOT
31 for c in $(ls -1 content/)
32 do
33 echo "<option value="$c">$c</option>"
34 done
35 cat << EOT
36 </select>
37 <input type="submit" value="$(gettext "Export")" />
38 </form>
39 EOT
40 # Functions
41 css_path() {
42 # Sed CSS style path in all documents
43 sed -i s'/style.css/..\/style.css/' */*.html
44 sed -i s'/style.css/..\/..\/style.css/' */*/*.html
45 sed -i s'/style.css/..\/..\/..\/style.css/' */*/*/*.html
46 }
47 gen_tarball() {
48 gettext "Creating tarball"; echo -n ": "
49 cd $tmpdir && mkdir $tiny/$cache/export
50 # Clean cache
51 find $tiny/$cache/export -mtime +1 | xargs rm -rf
52 tar czf $tiny/$cache/export/$export-$date.tar.gz $export
53 cd $tiny/$cache/export && du -sh $export-$date.tar.gz
54 }
55 dl_link() {
56 gettext "Download"; echo \
57 ": <a href='cache/export/$export-$date.tar.gz'>$export-$date.tar.gz</a>"
58 }
59 # Export requested content
60 case " $(GET export) " in
61 *\ cloud\ *)
62 export="cloud"
63 tmpdir="content"
64 echo '<pre>'
65 gettext "Exporting:"; echo " $export"
66 gen_tarball
67 echo '</pre>'
68 dl_link ;;
69 *\ wiki\ *)
70 export="wiki"
71 echo '<pre>'
72 gettext "Exporting:"; echo " $export"
73 mkdir -p $tmpdir/$export
74 gettext "Copying CSS style and images..."; echo
75 cp -a style.css images $tmpdir/$export
76 cd $content/$export
77 for d in $(find . -type f | sed s'!./!!')
78 do
79 d=${d%.txt}
80 [ "$d" == "en/help" ] && continue
81 gettext "Exporting: "; echo "$d.txt"
82 mkdir -p $tmpdir/$export/$(dirname $d)
83 f=$tmpdir/$export/$d.html
84 html_header > ${f}
85 sed -i '/functions.js/'d ${f}
86 sed -i '/favicon.ico/'d ${f}
87 sed -i s'/index.cgi/index.html/'/ ${f}
88 doc="[0-9a-zA-Z\.\#/~\_%=\?\&,\+\:@;!\(\)\*\$'\-]*"
89 #
90 # The sed from wiki urls to html bug if there is 2 links
91 # on same line: [test|Test] tralala [en/index|English]
92 #
93 cat $d.txt | wiki_parser | sed \
94 s"#href='\([^]]*\)?d=\($doc\)'>#href='\2.html'>#"g >> ${f}
95 html_footer >> ${f}
96 done
97 cd $tmpdir/$export
98 css_path
99 gen_tarball
100 rm -rf $tmp/export/$$
101 echo '</pre>'
102 dl_link ;;
103 *\ export\ ) html_footer && exit 0 ;;
104 *)
105 echo '<pre>'
106 gettext "Export not yet implemented for"; echo ": $(GET export)"
107 echo '</pre>' ;;
108 esac
110 html_footer && exit 0
111 fi