diff options
Diffstat (limited to 'desk/lib/trill.hoon')
-rw-r--r-- | desk/lib/trill.hoon | 249 |
1 files changed, 249 insertions, 0 deletions
diff --git a/desk/lib/trill.hoon b/desk/lib/trill.hoon new file mode 100644 index 0000000..7b912dd --- /dev/null +++ b/desk/lib/trill.hoon @@ -0,0 +1,249 @@ +/- post=trill-post +/+ lib=boke, sr=sortug, plib=post +|% +++ node-to-full-fake +|= p=post:post ^- full-node:post +=/ fake-children=full-graph:post %- ~(rep in children.p) +|= [=id:post acc=full-graph:post] +(put:form:post acc id *full-node:post) +p(children fake-children) +++ node-to-full +|= [p=post:post f=feed:post] ^- full-node:post +p(children (convert-children children.p f)) +++ convert-children +|= [children=(set id:post) f=feed:post] +^- full-graph:post +%- ~(rep in children) + |= [=id:post acc=full-graph:post] + =/ n (get:orm:post f id) + ?~ n acc + =/ full-node (node-to-full u.n f) + (put:form:post acc id full-node) +++ find-mention-2 +|= [our=@p l=(list inline:contents-1:post)] ^- ? +%+ roll l |= [i=inline:contents-1:post a=_|] +?. ?=(%ship -.i) a +.=(our p.i) +++ sanitize +|= c=contents:contents-1:post ^- ? +%+ roll c |= [i=block:contents-1:post acc=_&] +?. ?=(%paragraph -.i) acc +%+ roll p.i |= [ii=inline:contents-1:post iacc=_acc] +?. ?=(%link -.ii) iacc +?~ (de-purl:html href.ii) .n .y +++ post-size +|= c=contents:contents-1:post +=| count=@ +|- +?~ c count +=/ lc=@ +?- -.i.c +%tasklist 0 :: TODO +%paragraph (inline-size p.i.c) +%blockquote (inline-size p.i.c) +%heading (lent (trip p.i.c)) +%list (inline-size p.i.c) +%media (media-size media.i.c) +%codeblock +?: (gth (lent (trip lang.i.c)) 400) 10.000 +(lent (trip code.i.c)) +%eval (lent (trip hoon.i.c)) +%ref +?: (gth (lent (trip app.i.c)) 400) 10.000 +(roll path.i.c |=([i=@t a=@] (add a (lent (trip i))))) +%json +?: (gth (lent (trip content.i.c)) 5.000) 10.000 +?: (gth (lent (trip origin.i.c)) 1.000) 10.000 +0 +%table +%+ roll rows.i.c |= [i=(list contents:contents-1:post) a=@] +=/ inner-count=@ +%+ roll i |= [ii=contents:contents-1:post ia=@] +(add ia (post-size ii)) +(add inner-count a) +== +$(c t.c, count (add count lc)) +++ inline-size +|= l=(list inline:contents-1:post) ^- @ +=| count=@ +|- +?~ l count +=/ lc=@ +?+ -.i.l (lent (trip p.i.l)) +%date 0 :: TODO +%note 0 :: TODO +%break 0 +%ruby (lent (trip p.i.l)) +%link +?: (gth (lent (trip href.i.l)) 400) 10.000 +(lent (trip show.i.l)) +== +$(l t.l, count (add count lc)) +++ media-size +|= =media:contents-1:post ^- @ +?- -.media +%video (lent (trip p.media)) +%audio (lent (trip p.media)) +%images %+ roll p.media +|= [[url=@t caption=@t] a=@] +%+ add a (lent (trip caption)) +== +:: search +++ text-search +|= [q=@t p=post:post case=?] ^- tape +=/ t (content-to-md:lib contents.p) +=? t !case (cass t) +=/ qt ?: case (trip q) (cass (trip q)) +=/ i (find qt t) +?~ i "" +=/ start ?: (lte u.i 50) 0 (sub u.i 50) +?: .=(start 0) +"{(swag [start 100] t)}..." +"...{(swag [start 100] t)}..." + +++ search +|= [q=@t p=post:post] ^- ? +?~ contents.p .n +=/ latest=content-list:post val:head:(pop:corm:post contents.p) +=/ in-tags %+ roll ~(tap in tags.p) |= [i=cord a=_|] +?: (contains i q) %& a +=/ in-blocks %+ roll latest |= [i=block:contents-1:post a=_|] +?: ?- -.i + %paragraph (in-inline p.i q) + %blockquote (in-inline p.i q) + %list (in-inline p.i q) + %heading (contains p.i q) + %codeblock (contains code.i q) + %eval (contains hoon.i q) + %json (contains content.i q) + %media (in-media media.i q) + %ref %| :: TODO + %table %| :: TODO + %tasklist .n :: TODO +== %& a +?| in-tags in-blocks == +++ contains +|= [container=cord query=cord] ^- ? +?~ (find (trip query) (trip container)) %| %& +++ in-media +|= [=media:contents-1:post q=@t] ^- ? +?. ?=(%images -.media) (contains p.media q) +%+ roll p.media |= [[url=cord caption=cord] a=_|] +?: (contains caption q) %& a +:: +++ text-search2 +|= [q=@t p=post:post case=?] ^- @t +?~ contents.p '' +=/ bl=(list block:contents-1:post) val:head:(pop:corm:post contents.p) +=| snippet=@t +|- +?~ bl snippet +:: TODO proper counts +?: (gth (met 3 snippet) 50) snippet +=/ ns +?+ -.i.bl snippet + %paragraph (from-inline p.i.bl q case) + %blockquote (from-inline p.i.bl q case) + %list (from-inline p.i.bl q case) + :: %heading (cfind:sr q p.i .n) + :: %codeblock (cfind:sr q code.i .n) + :: %eval (cfind:sr q hoon.i .n) + :: %json (cfind:sr q content.i .n) + :: %media (in-media2 media.i q) + %ref snippet :: TODO + %table snippet :: TODO + %tasklist snippet +== +$(bl t.bl, snippet (cat 3 snippet ns)) +++ from-inline +|= [l=(list inline:contents-1:post) q=@t case=?] ^- @t +=| snippet=@t +|- +?~ l snippet +?: (gth (met 3 snippet) 50) snippet +=/ r +?+ -.i.l (cfindi:sr q p.i.l .n) +%break .n +%date .n :: TODO +%note .n ::TODO +%ship (cfindi:sr q (scot %p p.i.l) .n) +%link (cat 3 (cfindi:sr q href.i.l .n) (cfindi:sr q show.i.l .n)) +%ruby (cat 3 (cfindi:sr q p.i.l .n) (cfindi:sr q q.i.l .n)) +== +$(l t.l, snippet (cat 3 snippet r)) + +++ search2 +|= [q=@t p=post:post] ^- ? +?~ contents.p .n +=/ latest=content-list:post val:head:(pop:corm:post contents.p) +=/ in-tags %+ roll ~(tap in tags.p) |= [i=cord a=_|] +?: (cfind:sr q i .n) %& a +=/ in-blocks %+ roll latest |= [i=block:contents-1:post a=_|] +?: ?- -.i + %paragraph (in-inline2 p.i q) + %blockquote (in-inline2 p.i q) + %list (in-inline2 p.i q) + %heading (cfind:sr q p.i .n) + %codeblock (cfind:sr q code.i .n) + %eval (cfind:sr q hoon.i .n) + %json (cfind:sr q content.i .n) + %media (in-media2 media.i q) + %ref %| :: TODO + %table %| :: TODO + %tasklist .n +== %& a +?| in-tags in-blocks == +++ in-media2 +|= [=media:contents-1:post q=@t] ^- ? +?. ?=(%images -.media) (cfind:sr q p.media .n) +%+ roll p.media |= [[url=cord caption=cord] a=_|] +?: (cfind:sr q url .n) %& a +++ in-inline2 +|= [l=(list inline:contents-1:post) q=@t] ^- ? +|- +?~ l .n +=/ i i.l +=/ r=? +?+ -.i (cfind:sr q p.i .n) +%break .n +%date .n +%note .n +%ship (cfind:sr q (scot %p p.i) .n) +%link ?|((cfind:sr q href.i .n) (cfind:sr q show.i .n)) +%ruby ?|((cfind:sr q p.i .n) (cfind:sr q q.i .n)) +== +?| r $(l t.l) == +:: +++ in-inline +|= [l=(list inline:contents-1:post) q=@t] ^- ? +%+ roll l |= [i=inline:contents-1:post a=_|] +?: ?+ -.i (contains p.i q) +%break %| +%date .n +%note ?|((contains id.i q) (in-inline text.i q)) +%ship (contains (scot %p p.i) q) +%link ?|((contains href.i q) (contains show.i q)) +%ruby ?|((contains p.i q) (contains q.i q)) +== %& a +++ is-my-reply +|= [p=post:post r=post:post our=@p] ^- ? +?~ parent.r .n +?& .=(author.r our) !.=(author.p our) == +++ is-thread-child +|= [p=post:post r=post:post our=@p] ^- ? +?~ parent.r .n +?& .=(author.r our) .=(author.p our) == +++ tag-search +|= [l=(list @t) =feed:post] ^- (list full-node:post) +%+ roll (tap:orm:post feed) |= [[* =post:post] acc=(list full-node:post)] +=/ found +=/ has .y +|- +?~ l has +?& has +=/ ns (~(has in tags.post) (crip (cass (trip i.l)))) +$(l t.l, has ns) +== +?. found acc :_ acc +(node-to-full:plib post feed) +-- |