Specifying multiple templates in metas can never succeed #271

Closed
opened 10 months ago by joel · 1 comments
joel commented 10 months ago

Originally reported by someone else on Discourse: it seems that when multiple templates are specified in the metas of a Pollen source, those templates will never be used.

Within an empty folder with these files:

#lang racket

;; pollen.rkt

(module setup racket/base
  (provide (all-defined-out))
  (define poly-targets '(md sexp html)))
#lang pollen

◊;; index.poly.pm

◊(define-meta template '("topic-welcome.html" "topic-welcome.md"))

◊title{Hello, new topic}

Do the following (I did this in the terminal because DrRacket was giving me weird errors, even in this simple scenario, both on Mac and Windows):

❯ racket
Welcome to Racket v8.9 [cs].
> (require pollen/setup pollen/render pollen/cache)
> (cached-metas "index.poly.pm")
'#hasheq((here-path . "/Users/joel/code/sandbox/pollen-issue-2/index.poly.pm")
         (template . '("topic-welcome.html" "topic-welcome.md")))
> (parameterize ([current-poly-target 'html])
    (displayln (get-template-for (simple-form-path "index.poly.pm"))))
/Users/joel/code/sandbox/pollen-issue-2/template.html

I think the original reporter is correct that the problem is in c182a30f57/pollen/render.rkt (L454-L463):

(define template-name (if (list? template-name-or-names)
                                (findf (λ (tn) (eq? (get-ext tn) output-path-ext)) template-name-or-names)
                                template-name-or-names))

The first argument to eq? here will always be a string, and output-path-ext might sometimes be a string and sometimes a symbol (if the result of (current-poly-target) is used); either way this comparison will always fail.

Originally reported by someone else [on Discourse](https://racket.discourse.group/t/pollens-define-meta-isnt-working-get-template-for-ignores-it/2028): it seems that when multiple templates are specified in the metas of a Pollen source, those templates will never be used. Within an empty folder with these files: ```racket #lang racket ;; pollen.rkt (module setup racket/base (provide (all-defined-out)) (define poly-targets '(md sexp html))) ``` ``` #lang pollen ◊;; index.poly.pm ◊(define-meta template '("topic-welcome.html" "topic-welcome.md")) ◊title{Hello, new topic} ``` Do the following (I did this in the terminal because DrRacket was giving me weird errors, even in this simple scenario, both on Mac and Windows): ``` ❯ racket Welcome to Racket v8.9 [cs]. > (require pollen/setup pollen/render pollen/cache) > (cached-metas "index.poly.pm") '#hasheq((here-path . "/Users/joel/code/sandbox/pollen-issue-2/index.poly.pm") (template . '("topic-welcome.html" "topic-welcome.md"))) > (parameterize ([current-poly-target 'html]) (displayln (get-template-for (simple-form-path "index.poly.pm")))) /Users/joel/code/sandbox/pollen-issue-2/template.html ``` I think the original reporter is correct that the problem is in https://git.matthewbutterick.com/mbutterick/pollen/src/commit/c182a30f57ea5096440aea3d097f5fe3b78bb236/pollen/render.rkt#L454-L463: ```racket (define template-name (if (list? template-name-or-names) (findf (λ (tn) (eq? (get-ext tn) output-path-ext)) template-name-or-names) template-name-or-names)) ``` The first argument to `eq?` here will always be a string, and `output-path-ext` might sometimes be a string and sometimes a symbol (if the result of `(current-poly-target)` is used); either way this comparison will always fail.
mbutterick referenced this issue from a commit 10 months ago
mbutterick closed this issue 10 months ago
Owner

Sounds right to me. Thanks.

Sounds right to me. Thanks.
Sign in to join this conversation.
No Label
No Milestone
No project
No Assignees
2 Participants
Notifications
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#271
Loading…
There is no content yet.