urbit/pkg/arvo/lib/publish.hoon

246 lines
6.2 KiB
Plaintext
Raw Normal View History

2019-07-12 01:07:05 +03:00
/- *publish
/+ elem-to-react-json
|%
::
++ tang-to-json
|= tan=tang
%- wall:enjs:format
%- zing
%+ turn tan
|= a=tank
(wash [0 80] a)
::
++ string-to-symbol
|= tap=tape
^- @tas
%- crip
%+ turn tap
|= a=@
?: ?| &((gte a 'a') (lte a 'z'))
&((gte a '0') (lte a '9'))
==
a
?: &((gte a 'A') (lte a 'Z'))
(add 32 a)
'-'
2019-12-14 01:27:37 +03:00
::
++ note-build-to-json
|= build=(each manx tang)
^- json
?: ?=(%.y -.build)
%- pairs:enjs:format
:~ success+b+%.y
result+(elem-to-react-json p.build)
==
%- pairs:enjs:format
:~ success+b+%.n
result+(tang-to-json p.build)
==
::
2019-12-19 01:45:37 +03:00
++ count-unread
|= notes=(map @tas note)
^- @ud
%- ~(rep by notes)
|= [[key=@tas val=note] count=@ud]
?: read.val
count
+(count)
::
2019-12-14 01:27:37 +03:00
++ notebooks-list-json
|= [our=@p books=(map @tas notebook) subs=(map [@p @tas] notebook)]
^- json
=, enjs:format
:- %a
%+ weld
%+ turn ~(tap by books)
|= [name=@tas book=notebook]
2019-12-19 01:45:37 +03:00
(notebook-short-json book)
2019-12-14 01:27:37 +03:00
%+ turn ~(tap by subs)
|= [[host=@p name=@tas] book=notebook]
2019-12-19 01:45:37 +03:00
(notebook-short-json book)
::
++ notebooks-map-json
|= [our=@p books=(map @tas notebook) subs=(map [@p @tas] notebook)]
^- json
=, enjs:format
=/ subs-notebooks-map=json
%- ~(rep by subs)
|= [[[host=@p book-name=@tas] book=notebook] out=json]
^- json
=/ host-ta (scot %p host)
?~ out
(frond host-ta (frond book-name (notebook-short-json book)))
?> ?=(%o -.out)
=/ books (~(get by p.out) host-ta)
?~ books
:- %o
(~(put by p.out) host-ta (frond book-name (notebook-short-json book)))
?> ?=(%o -.u.books)
=. p.u.books (~(put by p.u.books) book-name (notebook-short-json book))
:- %o
(~(put by p.out) host-ta u.books)
=? subs-notebooks-map ?=(~ subs-notebooks-map)
[%o ~]
=/ our-notebooks-map=json
%- ~(rep by books)
|= [[book-name=@tas book=notebook] out=json]
^- json
?~ out
(frond book-name (notebook-short-json book))
?> ?=(%o -.out)
:- %o
(~(put by p.out) book-name (notebook-short-json book))
?~ our-notebooks-map
subs-notebooks-map
?> ?=(%o -.subs-notebooks-map)
:- %o
(~(put by p.subs-notebooks-map) (scot %p our) our-notebooks-map)
2019-12-14 01:27:37 +03:00
::
++ notebook-short-json
2019-12-19 01:45:37 +03:00
|= book=notebook
2019-12-14 01:27:37 +03:00
^- json
=, enjs:format
%- pairs
2019-12-19 01:45:37 +03:00
:~ title+s+title.book
2019-12-14 01:27:37 +03:00
date-created+(time date-created.book)
num-notes+(numb ~(wyt by notes.book))
2019-12-19 01:45:37 +03:00
num-unread+(numb (count-unread notes.book))
2019-12-14 01:27:37 +03:00
==
::
++ notebook-full-json
2019-12-19 01:45:37 +03:00
|= [host=@p book-name=@tas book=notebook]
2019-12-14 01:27:37 +03:00
^- json
=, enjs:format
%- pairs
2019-12-19 01:45:37 +03:00
:~ title+s+title.book
2019-12-14 01:27:37 +03:00
date-created+(time date-created.book)
2019-12-19 01:45:37 +03:00
num-notes+(numb ~(wyt by notes.book))
num-unread+(numb (count-unread notes.book))
notes-by-date+(notes-by-date notes.book)
comments+b+comments.book
writers-group-path+s+(spat writers.book)
subscribers-group-path+s+(spat subscribers.book)
2019-12-14 01:27:37 +03:00
==
::
2019-12-19 01:45:37 +03:00
++ note-presentation-json
|= [book=notebook note-name=@tas not=note]
^- (map @t json)
2019-12-14 01:27:37 +03:00
=, enjs:format
2019-12-19 01:45:37 +03:00
=/ notes-list=(list [@tas note])
%+ sort ~(tap by notes.book)
|= [[@tas n1=note] [@tas n2=note]]
(gte date-created.n1 date-created.n2)
=/ idx=@ (need (find [note-name not]~ notes-list))
=/ next=(unit [name=@tas not=note])
?: =(idx 0) ~
`(snag (dec idx) notes-list)
=/ prev=(unit [name=@tas not=note])
?: =(+(idx) (lent notes-list)) ~
`(snag +(idx) notes-list)
=/ current=json (note-full-json note-name not)
?> ?=(%o -.current)
=. p.current (~(put by p.current) %prev-note ?~(prev ~ s+name.u.prev))
=. p.current (~(put by p.current) %next-note ?~(next ~ s+name.u.next))
=/ notes=(list [@t json]) [note-name current]~
=? notes ?=(^ prev)
[[name.u.prev (note-short-json name.u.prev not.u.prev)] notes]
=? notes ?=(^ next)
[[name.u.next (note-short-json name.u.next not.u.next)] notes]
%- my
:~ notes+(pairs notes)
notes-by-date+a+(turn notes-list |=([name=@tas *] s+name))
2019-12-14 01:27:37 +03:00
==
::
++ note-full-json
2019-12-19 01:45:37 +03:00
|= [note-name=@tas =note]
2019-12-14 01:27:37 +03:00
^- json
=, enjs:format
%- pairs
2019-12-19 01:45:37 +03:00
:~ note-id+s+note-name
author+s+(scot %p author.note)
2019-12-14 01:27:37 +03:00
title+s+title.note
date-created+(time date-created.note)
build+(note-build-to-json build.note)
file+s+file.note
2019-12-19 01:45:37 +03:00
num-comments+(numb ~(wyt by comments.note))
comments+(comments-page comments.note 0 50)
read+b+read.note
2019-12-14 01:27:37 +03:00
==
::
2019-12-19 01:45:37 +03:00
++ notes-by-date
|= notes=(map @tas note)
2019-12-14 01:27:37 +03:00
^- json
=/ notes-list=(list [@tas note])
%+ sort ~(tap by notes)
|= [[@tas n1=note] [@tas n2=note]]
(gte date-created.n1 date-created.n2)
:- %a
2019-12-19 01:45:37 +03:00
%+ turn notes-list
|= [name=@tas note]
^- json
[%s name]
::
++ note-short-json
2019-12-14 01:27:37 +03:00
|= [note-name=@tas =note]
^- json
2019-12-19 01:45:37 +03:00
=, enjs:format
2019-12-14 01:27:37 +03:00
%- pairs
:~ note-id+s+note-name
2019-12-19 01:45:37 +03:00
author+s+(scot %p author.note)
2019-12-14 01:27:37 +03:00
title+s+title.note
date-created+(time date-created.note)
num-comments+(numb ~(wyt by comments.note))
2019-12-19 01:45:37 +03:00
read+b+read.note
:: XX snippet
2019-12-14 01:27:37 +03:00
==
::
2019-12-19 01:45:37 +03:00
++ notes-page
|= [notes=(map @tas note) start=@ud length=@ud]
^- (map @t json)
=/ notes-list=(list [@tas note])
%+ sort ~(tap by notes)
|= [[@tas n1=note] [@tas n2=note]]
(gte date-created.n1 date-created.n2)
%- my
:~ notes-by-date+a+(turn notes-list |=([name=@tas *] s+name))
notes+o+(notes-list-json (scag length (slag start notes-list)))
==
::
++ notes-list-json
|= notes=(list [@tas note])
^- (map @t json)
%+ roll notes
|= [[name=@tas not=note] out-map=(map @t json)]
^- (map @t json)
(~(put by out-map) name (note-short-json name not))
::
2019-12-14 01:27:37 +03:00
++ comments-page
|= [comments=(map @da comment) start=@ud end=@ud]
^- json
=/ coms=(list [@da comment])
%+ sort ~(tap by comments)
|= [[d1=@da comment] [d2=@da comment]]
(gte d1 d2)
%- comments-list-json
(scag end (slag start coms))
::
++ comments-list-json
|= comments=(list [@da comment])
^- json
=, enjs:format
:- %a
(turn comments comment-json)
::
++ comment-json
|= [date=@da com=comment]
^- json
=, enjs:format
%+ frond:enjs:format
(scot %da date)
%- pairs
2019-12-19 01:45:37 +03:00
:~ author+s+(scot %p author.com)
2019-12-14 01:27:37 +03:00
date-created+(time date-created.com)
content+s+content.com
==
--