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

Open
opened 3 years ago by femtomc · 5 comments
femtomc commented 3 years ago (Migrated from github.com)

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.

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 commented 3 years ago (Migrated from github.com)

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.

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.
mbutterick commented 3 years ago (Migrated from github.com)

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.)

> As far as I can tell, there's no way to attach metadata to page nodes Why not [`define-meta`](https://docs.racket-lang.org/pollen/Core.html#%28form._%28%28lib._pollen%2Fcore..rkt%29._define-meta%29%29)? > 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 commented 3 years ago (Migrated from github.com)

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

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

> The second one (forward and back links) I'm still stumped on. This is covered in [the second tutorial](https://docs.racket-lang.org/pollen/second-tutorial.html) in the Pollen docs.
femtomc commented 3 years ago (Migrated from github.com)

@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!

@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 commented 3 years ago (Migrated from github.com)

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).

> 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).
This repo is archived. You cannot comment on issues.
No Milestone
No project
No Assignees
1 Participants
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: mbutterick/pollen-users#124
Loading…
There is no content yet.