1 local new_uuid = require "util.uuid".generate; |
1 local new_uuid = require "util.uuid".generate; |
2 local datetime = require "util.datetime".datetime; |
2 local datetime = require "util.datetime".datetime; |
|
3 |
|
4 local xmlns_atom = "http://www.w3.org/2005/Atom"; |
3 |
5 |
4 return function (opts, arg) |
6 return function (opts, arg) |
5 if opts.short_help then |
7 if opts.short_help then |
6 print("Publish an Atom entry to a pubsub node"); |
8 print("Publish an Atom entry to a pubsub node"); |
7 return; |
9 return; |
18 return 0; |
20 return 0; |
19 end |
21 end |
20 local function on_connect(conn) |
22 local function on_connect(conn) |
21 -- Required: id, title, updated, author (which must have a name) |
23 -- Required: id, title, updated, author (which must have a name) |
22 local entry_id = opts.entry_id or ("clix-"..new_uuid()); |
24 local entry_id = opts.entry_id or ("clix-"..new_uuid()); |
23 local atom_entry = verse.stanza("entry", { xmlns="http://www.w3.org/2005/Atom" }) |
25 local atom_entry = verse.stanza("entry", { xmlns = xmlns_atom}) |
24 :tag("id"):text(entry_id):up(id) |
26 :tag("id"):text(entry_id):up(id) |
25 :tag("title"):text(opts.title or ""):up() |
27 :tag("title"):text(opts.title or ""):up() |
26 :tag("updated"):text(opts.updated or datetime()):up(); |
28 :tag("updated"):text(opts.updated or datetime()):up(); |
27 atom_entry:tag("author"):tag("name"):text(opts.author or os.getenv("USER") or "Unknown author"):up(); |
29 atom_entry:tag("author"):tag("name"):text(opts.author or os.getenv("USER") or "Unknown author"):up(); |
28 atom_entry:up(); |
30 atom_entry:up(); |