Afegint rss
[my-sputnik-extensions.git] / sputnik / actions / blog.lua
blob16c76c31448a1a003a817ca2a18eb8c080e2c138
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 = "http://rubberbytes.nfshost.com/$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 blog_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 entry_template = [=[
41 $entry_content
43 <h1>Comments</h1>
44 $disqs
45 ]=]
48 local function pages_in_order(sputnik)
49 local pages = sputnik.saci:get_nodes_by_prefix'blog'
50 local res = {}
51 for id,page in pairs(pages) do
52 res[#res+1] = page
53 end
54 table.sort(res,function(p1,p2) return (p1.creation_time or '') < (p2.creation_time or '') end)
55 return res
56 end
58 local wiki = require("sputnik.actions.wiki")
59 function actions.show_blog(node, request, sputnik)
60 -- XXX: Falta el cas on no hi ha cap subpàgina...
61 -- i documentar una mica això
62 local pages = pages_in_order(sputnik)
63 local most_recent = sputnik:get_node(table.remove(pages, 1).id)
65 most_recent = sputnik:decorate_node(most_recent)
66 most_recent = sputnik:activate_node(most_recent)
68 node.title = most_recent.title:gsub('blog/','')
69 node.inner_html = cosmo.f(blog_template) {
70 disqs = cosmo.f(disqs_tpl){ id = most_recent.id },
71 most_recent = most_recent.actions.show_content(most_recent, request, sputnik),
72 do_entries = function()
73 for _, page in ipairs(pages) do
74 cosmo.yield{
75 id = page.id,
76 name = page.title:gsub('blog/',''),
78 end
79 end
82 return node.wrappers.default(node, request, sputnik)
83 end
85 function actions.show_blog_entry(node, request, sputnik)
86 node.title = node.title:gsub('blog/', '')
87 node.inner_html = cosmo.f(entry_template) {
88 disqs = cosmo.f(disqs_tpl){ id = node.id },
89 entry_content = node.actions.show_content(node, request, sputnik)
92 return node.wrappers.default(node, request, sputnik)
93 -- return wiki.actions.show(node, request, sputnik)
94 end
96 function actions.rss(node, request, sputnik)
97 local pages = pages_in_order(sputnik)
100 return cosmo.f(node.templates.RSS){
101 title= "Recent Updates to Rubberbytes Blog",
102 channel_url = "http://" .. sputnik.config.DOMAIN .. sputnik:make_url(node.id),
103 items = function()
104 for i, page in ipairs(pages) do
105 page = sputnik:decorate_node(page)
106 page = sputnik:activate_node(page)
108 local last_edit = sputnik:get_history(page.id, 1)[0]
110 cosmo.yield{
111 link = "http://" .. sputnik.config.DOMAIN .. sputnik:make_url(page.id),
112 title = page.title:gsub('blog/',''),
113 ispermalink = "false",
114 guid = page.id,
115 pub_date = sputnik:format_time_RFC822(page.creation_time), --sputnik:format_time_RFC822(last_edit.timestamp),
116 author = "Joan Arnaldich",
117 summary = sputnik:escape(page.actions.show_content(page, request, sputnik))
121 }, "application/rss+xml"
125 function actions.save_page(node, request, sputnik)
126 if not node.creation_time then
127 local params = {}
128 params.author = request.user
129 params.creation_time = os.time()
130 node = sputnik:update_node_with_params(node, params)
132 return node