disqs
[my-sputnik-extensions.git] / sputnik / actions / blog.lua
blobf38179518ff7fea5f57cdd1a78fa69796d8f5e6e
1 --
2 -- Blog actions
3 --
4 module(..., package.seeall)
6 actions = {}
8 local disqs_tpl = [=[
9 <div id="disqus_thread"></div>
10 <script type="text/javascript">
11 /* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
12 var disqus_shortname = 'rubberbytes'; // required: replace example with your forum shortname
14 // The following are highly recommended additional parameters. Remove the slashes in front to use.
15 var disqus_identifier = "$id";
16 var disqus_url = "$id";
18 (function() {
19 var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
20 dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';
21 (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
22 })();
23 </script>
24 <noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
25 <a href="http://disqus.com" class="dsq-brlink">blog comments powered by <span class="logo-disqus">Disqus</span></a>
26 ]=]
29 local template = [=[
30 $most_recent
32 <h1>Comments</h1>
33 $disqs
34 <h1>Older posts</h1>
35 <ol>
36 $do_entries[[<li><a href="?p=$id">$name</a></li>]]
37 </ol>
38 ]=]
40 local function pages_in_order(sputnik)
41 local pages = sputnik.saci:get_nodes_by_prefix'blog'
42 local res = {}
43 for id,page in pairs(pages) do
44 res[#res+1] = page
45 end
46 table.sort(res,function(p1,p2) return (p1.creation_time or '') < (p2.creation_time or '') end)
47 return res
48 end
50 local wiki = require("sputnik.actions.wiki")
51 function actions.show_blog(node, request, sputnik)
52 -- XXX: Falta el cas on no hi ha cap subpàgina...
53 -- i documentar una mica això
54 local pages = pages_in_order(sputnik)
55 local most_recent = sputnik:get_node(table.remove(pages, 1).id)
57 most_recent = sputnik:decorate_node(most_recent)
58 most_recent = sputnik:activate_node(most_recent)
60 node.title = most_recent.title:gsub('blog/','')
61 node.inner_html = cosmo.f(template) {
62 test = "Prova",
63 disqs = cosmo.f(disqs_tpl){ id = most_recent.id },
64 most_recent = most_recent.actions.show_content(most_recent, request, sputnik),
65 do_entries = function()
66 for _, page in ipairs(pages) do
67 cosmo.yield{
68 id = page.id,
69 name = page.title:gsub('blog/',''),
71 end
72 end
75 return node.wrappers.default(node, request, sputnik)
76 end
79 function actions.show_blog_entry(node, request, sputnik)
80 node.title = node.title:gsub('blog/', '')
81 return wiki.actions.show(node, request, sputnik)
82 end