|
From: <jh...@us...> - 2008-09-15 20:06:15
|
Update of /cvsroot/aolserver/havardblog/tcl In directory sc8-pr-cvs11.sourceforge.net:/tmp/cvs-serv18580/tcl Added Files: init.tcl Log Message: Initial import of Havard's Crappy Blog as seen at http://johnhavard.com/ --- NEW FILE: init.tcl --- proc do_article {} { set mainStuff "" # /article/YYYY/MM/DD/slug/article.html if {[nsv_exists entries [ns_conn url]] == 1} { set entry [nsv_get entries [ns_conn url]] set slug [lindex $entry 0] set pubdate [lindex $entry 1] set updated [lindex $entry 2] set author [lindex $entry 3] set title [lindex $entry 4] set lead [lindex $entry 5] set body [lindex $entry 6] set mainStuff [ns_adp_parse -file template/article.adp] set rPole [ns_adp_parse -file template/rpole.adp] ns_return 200 "text/html" [ns_adp_parse -file template/template.adp] } else { ns_returnnotfound } } proc init_entries_nsv {} { set qry "SELECT ARTICLE.*,AUTHOR.PERSONAL_NAME FROM ARTICLE,AUTHOR WHERE AUTHOR.ID=ARTICLE.AUTHOR ORDER BY PUBDATE DESC, UPDATED DESC" catch { set hdl [ns_db gethandle pool1] set res [ns_db select $hdl $qry] while {[ns_db getrow $hdl $res]} { set slug [subst [ns_set get $res slug ]] set pubdate [subst [ns_set get $res pubdate]] set updated [subst [ns_set get $res updated]] set author [subst [ns_set get $res author ]] set title [subst [ns_set get $res title ]] set lead [subst [ns_set get $res lead ]] set body [subst [ns_set get $res body ]] set pubdate [string map {- /} $pubdate] nsv_set entries "/article/${pubdate}/${slug}/article.html" [list $slug $pubdate $updated $author $title $lead $body] #set mainStuff "$mainStuff [ns_adp_parse -file template/entry.adp]" } ns_db releasehandle $hdl } } proc most_recent_articles {n} { set mainStuff "" set qry "SELECT ARTICLE.*,AUTHOR.PERSONAL_NAME FROM ARTICLE,AUTHOR WHERE AUTHOR.ID=ARTICLE.AUTHOR ORDER BY PUBDATE DESC, UPDATED DESC LIMIT ${n}" catch { set hdl [ns_db gethandle pool1] set res [ns_db select $hdl $qry] while {[ns_db getrow $hdl $res]} { set slug [subst [ns_set get $res slug ]] set pubdate [subst [ns_set get $res pubdate]] set updated [subst [ns_set get $res updated]] set author [subst [ns_set get $res author ]] set title [subst [ns_set get $res title ]] set lead [subst [ns_set get $res lead ]] set body [subst [ns_set get $res body ]] set pubdate [string map {- /} $pubdate] set mainStuff "$mainStuff [ns_adp_parse -file template/entry.adp]" } ns_db releasehandle $hdl } set rPole [ns_adp_parse -file template/rpole.adp] nsv_set cache homepage [ns_adp_parse -file template/template.adp] } proc do_home_page {} { ns_return 200 "text/html" [nsv_get cache homepage] } ns_register_proc GET /article do_article ns_register_proc -noinherit GET / do_home_page ns_register_proc -noinherit GET /index.html do_home_page init_entries_nsv most_recent_articles 15 ns_schedule_proc -thread 900 { most_recent_articles 15 } |