Compare commits

...

5 Commits

7 changed files with 227 additions and 23 deletions

View File

@ -46,7 +46,7 @@ fn blagh_init {
if not if(~ $req_path $blagh_uri^index.rss)
blagh_setup_feed_handlers rss20.tpl 'text/xml; charset=utf-8'
if not if(~ $req_path $blagh_uri^feed.json)
if not if(~ $req_path $blagh_uri^feed.json)
blagh_setup_feed_handlers jsonfeed.tpl 'application/json; charset=utf-8'
if not if(~ $req_path $blagh_uri^new_post && ! ~ $#editor_mode 0) {
@ -84,16 +84,16 @@ fn blagh_body {
for(p in `{get_post_list $blagh_root^$blagh_dirs}) {
l=`{echo -n $p|sed 's!'$sitedir^'/?(.*)([0-9][0-9][0-9][0-9]/[0-9][0-9]/[0-9][0-9])(/[^/]+/)!\2 /\1\2\3!'}
sed '1s!.*![&]('^$l(2)^') ('^$l(1)^')!' < $p/index.md
# cat $p/index.md | sed '1s!.*![&]('^$l(2)^') ('^$l(1)^')!' | sed -n '/^.\{15\}/p' | echo
# cat $p/index.md | sed '1s!.*![&]('^$l(2)^') ('^$l(1)^')!' | sed -n '/^.\{15\}/p' | echo
echo # Needed extra \n so markdown doesn't mess up the formatting, probably can be done in sed.
echo #
echo #
} | head -n 9 | $formatter | sed 's/h[2-9]/i/g'| sed 's/h1/h3/g'
# HTML posts
for(p in `{get_post_list $blagh_root^$blagh_dirs}) {
cat < $p/index.html
echo # Needed extra \n so markdown doesn't mess up the formatting, probably can be done in sed.
} | sed 's/h[2-9]/i/g' | sed 's/h1/h3/g' | head -n 5
# XXX BUG! Markdown [references] break because multiple markdown documents are merged. Should format each blog post independently.
# XXX BUG! Markdown [references] break because multiple markdown documents are merged. Should format each blog post independently.
# TODO: use fltr_cache directly, that can fix the previous bug plus provide a perf boost by caching title generation.
echo '<p><a href="../sitemap">More content</a></p>'
}

View File

@ -5,8 +5,11 @@ fn statpost {
f = $1
post_uri = `{echo $f | sed 's,^'$sitedir',,'}
title=`{read $f/index.md}
post_uri=$base_url^`{cleanname `{echo $f | sed -e 's!^'$sitedir'!!'}}^'/'
relative_uri=`{cleanname `{echo $f | sed -e 's!^'$sitedir'!!'}}
post_uri=$base_url^$relative_uri^'/'
by=`{ls -m $f | sed 's/^\[//g; s/].*$//g' >[2]/dev/null}
extracted_on=`{echo $relative_uri | sed 's|/blog/||g' | head -c 10 }
published_on=`{ /bin/date -R -D '%Y/%m/%d' -d $extracted_on }
ifs=() {summary=`{ cat $f/index.md |strip_title_from_md_file | head -n 9 | ifs=$difs {$formatter | escape_html} }}
}
@ -38,7 +41,7 @@ fn statpost {
%}
<link>%($post_uri%)</link>
<guid isPermaLink="true">%($post_uri%)</guid>
<pubDate>%($pubdate%)</pubDate>
<pubDate>%( $published_on %)</pubDate>
<description> %($summary%) </description>
</item>
% }

103
apps/remarkbox/app.rc Normal file
View File

@ -0,0 +1,103 @@
comment_file_types=(md html)
fn conf_enable_comments {
if(~ $1 -n) {
allow_new_user_comments=yes
shift
}
if not if(~ $1 -a) {
bridge_anon_comments=yes
}
enable_comments=yes
groups_allowed_comments=$*
conf_enable_app bridge
}
fn bridge_init {
if(~ $#enable_comments 1 && ! ~ `{ls $local_path.$comment_file_types >[2]/dev/null|wc -l} 0) {
comments_dir=$sitedir$req_path'_werc/comments'
if(~ $REQUEST_METHOD GET && test -d $comments_dir)
ll_add handlers_body_foot template apps/bridge/comments_list.tpl
if(check_user $groups_allowed_comments || {~ $#logged_user 0 && ~ 1 $#allow_new_user_comments $#bridge_anon_comments}) {
if(~ $#post_arg_bridge_post 1) {
ll_add handlers_body_foot template apps/bridge/foot.tpl
if(mk_new_comment $comments_dir)
post_redirect $base_url^$req_path
if not
saved_comment_text=$post_arg_comment_text
}
if not if(~ $REQUEST_METHOD GET)
ll_add handlers_body_foot template apps/bridge/foot.tpl
}
if not if(~ $REQUEST_METHOD GET)
ll_add handlers_body_foot echo '<hr><p>To post a comment you need to <a href="/_users/login">login</a> first.</p>'
}
}
fn validate_new_user {
usr=$1; pass=$2; pass2=$3
_status=()
if(~ $"usr '' || ! echo $usr |sed 1q|grep -s '^'$allowed_user_chars'+$')
_status='Requested user name is invalid, must match: '^$allowed_user_chars^'+'
if not if(test -d etc/users/$usr)
_status='Sorry, user name '''^$usr^''' already taken, please pick a different one.'
if(~ $"pass '' || ! ~ $"pass $"pass2)
_status=($_status 'Provided passwords don''t match.')
status=$_status
}
fn mk_new_comment {
_status=()
dir=$1
if(~ $"post_arg_comment_text '')
_status='Provide a comment!'
if not if(~ $#logged_user 0) {
if(! ~ $#allow_new_user_comments 0) {
if(validate_new_user $"post_arg_comment_user $post_arg_comment_passwd $post_arg_comment_passwd2) {
u=$post_arg_comment_user':'$post_arg_comment_passwd
dir=$comments_dir^'_pending'
# XXX: This doesn't work because we then do a redirect.
notify_notes='Saved comment and registration info, they will be enabled when approved by an admin.'
}
if not
_status=$status
}
if not if(! ~ $#bridge_anon_comments 0) {
if(~ $"post_arg_ima_robot 'not')
u='Glenda' # Anonymous
if not
_status='You are a robot!'
}
if not
_status='You need to log in to comment.'
}
if not if(check_user $groups_allowed_comments)
u=$logged_user
if not
_status='You are not a member of a group allowed to comment.'
if(~ $#_status 0) {
umask 002
dir=$dir'/'`{date -n} # FIXME Obvious race
mkdir -m 775 -p $dir &&
echo $u > $dir/user &&
echo $current_date_time > $dir/posted &&
echo $post_arg_comment_text > $dir/body
_s=$status
if(! ~ $"_s '') {
dprint 'ERROR XXX: Could not create comment: ' $_s
_status='Could not post comment due internal error, sorry.'
}
}
notify_errors=$_status
status=$_status
}

View File

@ -0,0 +1,17 @@
<hr>
<h2>Comments</h2>
% for(c in `{ls $comments_dir/}) {
% if(test -s $c/body) {
<div class="comment">
<h5>By:
<b><i>%
(`{cat $c/user | sed 's/:.*//g'}%)
</i></b>
(%(`{cat $c/posted}%))
</h5>
% cat $c/body | escape_html | sed 's,$,<br>,'
<hr></div>
% }
% }

42
apps/remarkbox/foot.tpl Executable file
View File

@ -0,0 +1,42 @@
<hr>
% notices_handler
<form action="" method="post">
<textarea name="comment_text" id="comment_text" cols="80" rows="16">%($"saved_comment_text%)</textarea>
<br>
<input type="submit" name="bridge_post" value="Post a comment">
% if(~ $#logged_user 0) {
% if(~ $#allow_new_user_comments 1) {
</br>
</br>
<label>New user name:
<input type="text" name="comment_user" value="%($"post_arg_comment_user%)">
</label>
</br>
<label>Password:
<input type="password" name="comment_passwd" value="">
</label>
</br>
<label>Repeat password:
<input type="password" name="comment_passwd2" value="">
</label>
</br>
</br>
<div style="font-size: 70%">
Enter your desired user name/password and after your comment has been reviewed by an admin it will be posted and your account will be enabled. If you are already registered please <a href="/_users/login">login</a> before posting.
</div>
% }
% if not if(~ $#bridge_anon_comments 1) {
<label>Is <a href="http://glenda.cat-v.org">Glenda a cute bunny</a>?
<select name='ima_robot'>
<option value="yes">No</option>
<option value="not">Yes</option>
<option value="foobar">I hate bunnies!</option>
<option value="robot">I'm a robot!</option>
</select>
</label>
% }
% }
</form>

View File

@ -9,7 +9,7 @@
</header>
% if(! ~ $#handlers_bar_left 0) {
<nav id="side-bar">
<nav id="side-bar" class="hidden-mobile">
% for(h in $handlers_bar_left) {
<div>
% run_handler $$h
@ -24,6 +24,6 @@
% run_handlers $handlers_body_foot
</article>
<footer>
<footer class="hidden-mobile">
% cat `{ get_lib_file footer.inc }
</footer>

View File

@ -29,17 +29,6 @@ body {
}
/* If the screen size is 600px wide or less, set the font-size of <div> to 30px */
@media screen and (max-width: 600px) {
body {
font-size: 1em;
}
.hidden-mobile {
display: none;
}
}
/* header */
header {
flex-basis: 100%;
@ -68,7 +57,7 @@ header a {
header h1 span {
margin-left: 0em;
font-size: 70%;
/* font-size: 70%; */
color: #555;
/*
font-style: italic;
@ -127,8 +116,10 @@ article{
}
footer {
display: block;
flex-grow: 1;
display: flex;
flex-basis: 100%;
flex-shrink: 0;
justify-content: space-between;
padding: 1em 0em 1em 1em;
border-top: 2px solid #eee
@ -150,7 +141,7 @@ figure figcaption {
figcaption {
text-align: center;
font-size: 12px;
font-size: 16px;
}
img {
@ -164,7 +155,7 @@ img {
display: block;
margin-left: auto;
margin-right: auto;
width: 300px;
width: 25%;
}
.img-medium-center {
@ -223,4 +214,52 @@ li{
/* list-style-type: '- ' /* ndash, a*/
}
/* Tables */
table {
border-collapse: collapse;
margin-left: auto;
margin-right: auto;
margin-top: 1em;
margin-bottom: 1em;
}
td,
th {
border: 1px solid var(--border);
text-align: left;
padding: 0.5rem;
}
th {
background: var(--accent-bg);
font-weight: bold;
}
/* If the screen size is 600px wide or less, set the font-size of <div> to 30px */
@media screen and (max-width: 1400px) {
body {
display: block;
}
.hidden-mobile {
display: none;
}
article {
flex-basis: 100%;
padding: 5px;
}
header h1 {
margin-left: 0;
}
.img-frontpage-center {
display: block;
margin-left: auto;
margin-right: auto;
width: 200px;
}
}
@media screen and (min-width: 1400px) {
.hide-not-mobile {
display: none;
}
}