Accessing metas from Racket #103

Closed
opened 4 years ago by casouri · 2 comments
casouri commented 4 years ago (Migrated from github.com)

The tutorial mentions using (require "pollen-source.rkt") to gain access to metas outside Pollen. What does this "pollen-source.rkt" refer to? Currently in my pollen.rkt there is

(require
 pollen/decode
 pollen/file
 pollen/tag
 pollen/core
 txexpr)

which doesn't work. Apparently, none of them provide metas. What should I do?

Background:

I'm trying to write a little helper that turns the filename of the pollen source into the title of the page. For example, it turns "day-12.html.pm" into "Day 12". This is how I implemented it:

(define (title)
  (let* ([path (select-from-metas 'here-path metas)]
         [filename (file-name-from-path path)]
         [day (list-ref (regexp-match #rx"^day-(.+?)\\." filename) 1)])
    (format "Day ~a" day)))

The problem is when I wrote my function in pollen.rkt, Racket complains that metas is not defined.

My complete pollen.rkt:

#lang racket

(provide title jpns link image root)

(require
 pollen/decode
 pollen/file
 pollen/tag
 pollen/core
 txexpr)

(define (title)
  (let* ([path (select-from-metas 'here-path metas)]
         [filename (file-name-from-path path)]
         [day (list-ref (regexp-match #rx"^day-(.+?)\\." filename) 1)])
    (format "Day ~a" day)))

(define (jpns text)
  (txexpr 'span '((class "jpns")) (list text)))

(define (link url . tx-elements)
  (let* ([tx-elements (if (empty? tx-elements)
                          (list (string-normalize-nfc url))
                          tx-elements)]
         [link-tx (txexpr 'a empty tx-elements)]
         [link-tx (attr-set link-tx 'href url)])
    link-tx))


(define (image src)
  (attr-set* '(img) 'src src))

(define (root . elements)
  (txexpr 'root empty
          (decode-elements
           elements
           #:txexpr-elements-proc decode-paragraphs)))
The tutorial mentions using `(require "pollen-source.rkt")` to gain access to `metas` outside Pollen. What does this "pollen-source.rkt" refer to? Currently in my `pollen.rkt` there is ```racket (require pollen/decode pollen/file pollen/tag pollen/core txexpr) ``` which doesn't work. Apparently, none of them provide `metas`. What should I do? Background: I'm trying to write a little helper that turns the filename of the pollen source into the title of the page. For example, it turns "day-12.html.pm" into "Day 12". This is how I implemented it: ```racket (define (title) (let* ([path (select-from-metas 'here-path metas)] [filename (file-name-from-path path)] [day (list-ref (regexp-match #rx"^day-(.+?)\\." filename) 1)]) (format "Day ~a" day))) ``` The problem is when I wrote my function in `pollen.rkt`, Racket complains that `metas` is not defined. My complete `pollen.rkt`: ```racket #lang racket (provide title jpns link image root) (require pollen/decode pollen/file pollen/tag pollen/core txexpr) (define (title) (let* ([path (select-from-metas 'here-path metas)] [filename (file-name-from-path path)] [day (list-ref (regexp-match #rx"^day-(.+?)\\." filename) 1)]) (format "Day ~a" day))) (define (jpns text) (txexpr 'span '((class "jpns")) (list text))) (define (link url . tx-elements) (let* ([tx-elements (if (empty? tx-elements) (list (string-normalize-nfc url)) tx-elements)] [link-tx (txexpr 'a empty tx-elements)] [link-tx (attr-set link-tx 'href url)]) link-tx)) (define (image src) (attr-set* '(img) 'src src)) (define (root . elements) (txexpr 'root empty (decode-elements elements #:txexpr-elements-proc decode-paragraphs))) ```
mbutterick commented 4 years ago (Migrated from github.com)

What does this "pollen-source.rkt" refer to?

It’s a placeholder for the actual name. So if your source is "day-12.html.pm", then (require "day-12.html.pm").

Racket complains that metas is not defined.

If you want to use metas in a tag function, you probably want to use the (current-metas) parameter, which holds the metas of the Pollen source currently being evaluated (or #false if none is available)

> What does this "pollen-source.rkt" refer to? It’s a placeholder for the actual name. So if your source is `"day-12.html.pm"`, then `(require "day-12.html.pm")`. > Racket complains that metas is not defined. If you want to use `metas` in a tag function, you probably want to use the `(current-metas)` parameter, which holds the `metas` of the Pollen source currently being evaluated (or `#false` if none is available)
casouri commented 4 years ago (Migrated from github.com)

Thanks! (current-metas) is what I'm looking for. It would be nice if the tutorial can mention it in 12.3.1.5 Retrieving metas.

Thanks! `(current-metas)` is what I'm looking for. It would be nice if the tutorial can mention it in `12.3.1.5 Retrieving metas`.
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#103
Loading…
There is no content yet.