pollen-users icon indicating copy to clipboard operation
pollen-users copied to clipboard

Metadata on pagenodes (?) / how to render link traversal

Open femtomc opened this issue 3 years ago • 5 comments

I have two related questions (related in the sense that they motivated a common solution, but the solution is outside of pollen, and I was hoping I could somehow not resort to it).

I have an index.html.pm file -- I want to render an itemized list of the nodes in my pagetree (and I have an associated index.ptree file I curate). However, I want to render them with their titles (distinct from their node name). As far as I can tell, there's no way to attach metadata to page nodes -- except by keeping some state (a finite map, say) around (and then, when the preprocessor ingests a file, tell it to add a key with the current page node name, with value the metadata I want). The one thing I'm concerned about is the order of the traversal -- if the state is not updated before index.html.pm is preprocessed, that's going to be a problem.

The second question is about rendering the forward / backward links in a graphical form. I know that pollen must do this already (right?) -- I want to render a "knowledge graph" like representation of the link traversal. Is it possible to gain access to this structure through normal Racket? The alternative solution I had was another "stateful" thing where I keep a database around, and register forward/backward links in the database. I don't really want to do this, so I was hoping that there is an easier solution.

femtomc avatar Feb 08 '22 15:02 femtomc

Re -- I realized the first one was easy enough to work on:

◊(apply ol (map (lambda (node) `(li (a ((href ,(symbol->string node)))
        ,(car (select-from-doc 'h1 node)))))
        (pagetree->list (get-pagetree "index.ptree")))
)

e.g. this just uses the curated .ptree and a search over X-expressions to get the right thing.

The second one (forward and back links) I'm still stumped on.

femtomc avatar Feb 08 '22 16:02 femtomc

As far as I can tell, there's no way to attach metadata to page nodes

Why not define-meta?

The second question is about rendering the forward / backward links in a graphical form. I know that pollen must do this already (right?)

The forward & backward links can be computed from a pagetree. (They could be computed other ways too.) But no, Pollen does not automatically render them “in a graphical form” — you would do that yourself.

I want to render a "knowledge graph" like representation of the link traversal

What does this mean — a graph of all the hyperlinks between pages? If so, I don’t see any alternative to reading the link tags out of the source files (assuming the links of interest are already tagged there; if not you would have to read & parse the output files) and imperatively building a graph. Racket’s graph library will output to graphviz format, so once you have a graph object, it’s easy to get a rendered diagram. (Not necessarily a pretty diagram, though.)

mbutterick avatar Feb 08 '22 16:02 mbutterick

The second one (forward and back links) I'm still stumped on.

This is covered in the second tutorial in the Pollen docs.

mbutterick avatar Feb 08 '22 16:02 mbutterick

@mbutterick -- I'm looking into pollen/core more, I realized I misunderstood that you could access metadata about the document directly (e.g. by using the pagenode reference).

Right, so basically: iterate over nodes in the page tree, and grab all "special" links (e.g. cross links to other nodes), then offload to graphviz.

I'm pretty close now, thanks for the help!

femtomc avatar Feb 08 '22 16:02 femtomc

The forward & backward links can be computed from a pagetree. (They could be computed other ways too.) But no, Pollen does not automatically render them “in a graphical form” — you would do that yourself.

Here, I did a poor job -- I meant the traversal across the nodes (not the rendering).

femtomc avatar Feb 08 '22 16:02 femtomc