Skip to content
This repository has been archived by the owner on Sep 17, 2022. It is now read-only.

How should I make a pagetree with poly sources? #23

Closed
oldmankit opened this issue Dec 6, 2019 · 4 comments
Closed

How should I make a pagetree with poly sources? #23

oldmankit opened this issue Dec 6, 2019 · 4 comments

Comments

@oldmankit
Copy link

Do pagetrees only work with one output source?

Let's say I'm using poly sources (1.poly.pm and 2.poly.pm) to generate both html and txt output. If my pagetree contains:

  • 1.html
  • 2.html

then Pollen functions which rely on the pagetree (for example, previous here) work only when generating html output. The txt output seems to be unaware that there is any pagetree. So previous, next, parent and children links don't produce anything.

I tried making a pagetree with:

  • 1.poly
  • 2.poly

But that didn't fix it. None of the pagetree-depenent functions worked for either html or for txt.

@mbutterick
Copy link
Owner

So you want two pagetrees that are the same, except the file extension for each pagenode is txt rather than html?

@oldmankit
Copy link
Author

So you want two pagetrees that are the same, except the file extension for each pagenode is txt rather than html?

Yes, that's exactly right.

@mbutterick
Copy link
Owner

I suppose I’d write the pagetree using poly extensions and then pass the tree through a tag function that converts tnem. Here’s one approach:

#lang pollen/ptree
◊(require racket/match txexpr pollen/setup racket/string)

◊(define (change-ext . xs)
  (cons '@
        (let loop ([x xs])
          (match x
            [(? list? xs) (map loop xs)]
            [(? string? str) #:when (string-suffix? str ".poly")
                             (string-replace str ".poly" (format ".~a" (current-poly-target)))]
            [(? symbol? sym) (string->symbol (loop (symbol->string sym)))]
            [_ x]))))

◊change-ext{
hello.poly
◊world.poly{
            this.poly
            that.poly
            }
}

(Taking the shortcut here of using string-manipulation functions on path-like things, which is not the most enviable practice but it shortens the example)

@oldmankit
Copy link
Author

Thank you so much, @mbutterick That works perfectly.

I had a little flash of insight when I saw what you'd done: truly everything is programmable, even the .ptree which I was thinking of as a kind of black box.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants