summaryrefslogtreecommitdiff
path: root/apps/dirdir
diff options
context:
space:
mode:
authorglenda <glenda@9front.local>2020-11-15 15:13:27 +0000
committerglenda <glenda@9front.local>2020-11-15 15:13:27 +0000
commit39318169e0b50551db511851829f9337c5fa6313 (patch)
tree65a0ef5c1da9677532fa8105293d017919473057 /apps/dirdir
Import site to git
Diffstat (limited to 'apps/dirdir')
-rwxr-xr-xapps/dirdir/app.rc40
-rwxr-xr-xapps/dirdir/edit.tpl25
-rwxr-xr-xapps/dirdir/sidebar_controls.tpl3
3 files changed, 68 insertions, 0 deletions
diff --git a/apps/dirdir/app.rc b/apps/dirdir/app.rc
new file mode 100755
index 0000000..1aa9cbd
--- /dev/null
+++ b/apps/dirdir/app.rc
@@ -0,0 +1,40 @@
+fn conf_enable_wiki {
+ enable_wiki=yes
+ wiki_editors_groups=$*
+ conf_enable_app dirdir
+}
+
+fn dirdir_init {
+ if(! ~ $#enable_wiki 0 && check_user $wiki_editors_groups) {
+ lp=$local_path
+ # werc.rc doesn't append /index when $local_path doesn't exist
+ # maybe it should, but for now we can fix it up here.
+ if(~ $lp */)
+ lp=$lp^'index'
+ dirdir_file=$lp.md
+ dirdir_dir=$dirdir_file^'_werc/dirdir/'
+
+ if(~ 1 $#post_arg_dirdir_edit $#post_arg_dirdir_preview)
+ handler_body_main=(tpl_handler `{get_lib_file dirdir/edit.tpl apps/dirdir/edit.tpl})
+
+ if not if(! ~ '' $"post_arg_dirdir_save $"post_arg_edit_text)
+ save_page
+
+ if not if(~ $"handler_body_main '' || {~ $REQUEST_METHOD GET && test -f $local_path.md})
+ ll_add handlers_bar_left tpl_handler apps/dirdir/sidebar_controls.tpl
+ }
+}
+
+fn save_page {
+ dirdir_verdir=$dirdir_dir/^`{date -n}^/
+ mkdir -p $dirdir_verdir
+ umask 002
+
+ # XXX Use a tmp file and mv(1) to ensure updates are atomic?
+ echo $logged_user > $dirdir_verdir/author
+ echo $post_arg_edit_text > $dirdir_verdir/data
+ echo $post_arg_edit_text > $dirdir_file
+
+ post_redirect $base_url^$req_path
+ #notify_notes='Saved <a href="'$"req_path'">'$"req_path'</a>!'
+}
diff --git a/apps/dirdir/edit.tpl b/apps/dirdir/edit.tpl
new file mode 100755
index 0000000..1a5b206
--- /dev/null
+++ b/apps/dirdir/edit.tpl
@@ -0,0 +1,25 @@
+<div>
+ <h1>Editing: <a href="%($req_path%)">%($req_path%)</a></h1>
+ <br>
+ <form action="" method="POST">
+ <textarea name="edit_text" id="edit_text" cols="80" rows="43">%{
+# FIXME Extra trailing new lines get added to the content somehow, should avoid it.
+ if(~ $#post_arg_edit_text 0 && test -f $dirdir_file)
+ cat $dirdir_file | escape_html
+ if not
+ echo -n $post_arg_edit_text | escape_html
+
+ %}</textarea>
+ <br>
+ <input type="submit" name="dirdir_save" value="Save">
+ <input type="submit" name="dirdir_preview" value="Preview">
+ <small>DirDir documents are written using <a href="http://daringfireball.net/projects/markdown/syntax">Markdown syntax</a>.</small>
+ </form>
+</div>
+
+% if(! ~ $"post_arg_dirdir_preview '') {
+ <h2>Preview:</h2>
+ <div id="preview">
+% echo $post_arg_edit_text | $formatter
+ </div>
+% }
diff --git a/apps/dirdir/sidebar_controls.tpl b/apps/dirdir/sidebar_controls.tpl
new file mode 100755
index 0000000..a897fc1
--- /dev/null
+++ b/apps/dirdir/sidebar_controls.tpl
@@ -0,0 +1,3 @@
+<form action="" method="POST">
+<input type="submit" name="dirdir_edit" value="Edit page" />
+</form>