parent
cd042fbf44
commit
0018f122a5
|
@ -1,58 +0,0 @@
|
|||
# SPDX-FileCopyrightText: ☭ 2021 Emery Hemingway
|
||||
# SPDX-License-Identifier: Unlicense
|
||||
|
||||
import std/[asyncdispatch, os, parseopt, strutils, tables, xmltree]
|
||||
import preserves, preserves/xmlhooks
|
||||
import syndicate, syndicate/[actors, capabilities, relay]
|
||||
import parsegemini
|
||||
import gemclient
|
||||
import nimsvg
|
||||
import svui
|
||||
import eris
|
||||
|
||||
type Svui = svui.Svui[Ref]
|
||||
|
||||
proc main() =
|
||||
proc quitHook() {.noconv.} = quit()
|
||||
setControlCHook(quitHook)
|
||||
|
||||
waitFor runActor("client") do (turn: var Turn):
|
||||
|
||||
let cap = mint()
|
||||
|
||||
connectUnix(turn, "/run/syndicate/ds", cap) do (turn: var Turn; a: Assertion) -> TurnAction:
|
||||
let ds = unembed a
|
||||
let client = newGeminiClient()
|
||||
|
||||
for kind, arg, _ in getopt():
|
||||
if kind == cmdArgument and arg.startsWith"gemini":
|
||||
var
|
||||
nodes: seq[Nodes]
|
||||
p: GeminiParser
|
||||
let resp = client.fetch(arg)
|
||||
open(p, resp.bodyStream)
|
||||
# TODO: append to a text block until running into verbatim text,
|
||||
# then push the current text and open a new block
|
||||
while true:
|
||||
p.next()
|
||||
case p.kind
|
||||
of gmiEof: break
|
||||
else:
|
||||
let n = buildSvg:
|
||||
t: xmltree.escape p.text
|
||||
nodes.add n
|
||||
close(p)
|
||||
let doc = buildSvg:
|
||||
svg(viewBox="0 0 600 800", `font-family` = "Gentium Plus", `font-size`="20"):
|
||||
g(fill="white"):
|
||||
text(fill="black"):
|
||||
for n in nodes: embed n
|
||||
let
|
||||
buf = render doc
|
||||
bs = if buf.len < (16 shl 10): bs1k else: bs32k
|
||||
capPr = toPreserve($erisCap(buf, bs), Ref)
|
||||
discard publish(turn, ds, Svui(attrs: toTable {"urn": capPr}, svg: buf))
|
||||
|
||||
stderr.writeLine "done"
|
||||
|
||||
main()
|
Loading…
Reference in New Issue