here using wrong slashes on Windows #71

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

Unfortunately functions and variables that generate paths such as ◊|here| end up using \ instead of / on Windows. This means that if you generate your website using Pollen on Windows you'll end up with wrong paths all over the place. It would be better if Pollen always used / since webservers kinda expect that to be the path separator.

Unfortunately functions and variables that generate paths such as `◊|here|` end up using `\` instead of `/` on Windows. This means that if you generate your website using Pollen on Windows you'll end up with wrong paths all over the place. It would be better if Pollen always used `/` since webservers kinda expect that to be the path separator.
mbutterick commented 4 years ago (Migrated from github.com)

Racket’s default policy is that “paths are created and manipulated for the current platform”. Furthermore, Pollen is not strictly a system for generating web pages. For these reasons, I’m not yet persuaded that it should adopt web-path conventions by default.

Racket’s [default policy](https://docs.racket-lang.org/reference/pathutils.html?q=path%3F) is that “paths are created and manipulated for the current platform”. Furthermore, Pollen is not strictly a system for generating web pages. For these reasons, I’m not yet persuaded that it should adopt web-path conventions by default.
soapdog commented 4 years ago (Migrated from github.com)

I understand, @mbutterick, no worries. I just built myself a little helper here to solve this when doing interpolation in HTML. Thanks.

I understand, @mbutterick, no worries. I just built myself a little helper here to solve this when doing interpolation in HTML. Thanks.
otherjoel commented 4 years ago (Migrated from github.com)

If working on Windows you can add a utility function to replace backslashes with slashes.

(define (windows->web s)
  (string-replace (symbol->string s) "\\" "/"))

It's surprising to me, though, that on Windows there seems to be no way to generate convert between Windows and Unix paths using only Racket’s path functions. build-path/convention-type simply refuses to generate a Unix path on a Windows system, even when building from plain strings.

> (build-path/convention-type 'windows "tutorial" "other.html")
#<path:tutorial\other.html>
> (build-path/convention-type 'unix "tutorial" "other.html")
build-path/convention-type: specified convention incompatible with string path element
  path element: "tutorial"
  convention: 'unix
If working on Windows you can add a utility function to replace backslashes with slashes. ```racket (define (windows->web s) (string-replace (symbol->string s) "\\" "/")) ``` It's surprising to me, though, that on Windows there seems to be no way to generate convert between Windows and Unix paths using only Racket’s path functions. `build-path/convention-type` simply refuses to generate a Unix path on a Windows system, even when building from plain strings. ```racket > (build-path/convention-type 'windows "tutorial" "other.html") #<path:tutorial\other.html> > (build-path/convention-type 'unix "tutorial" "other.html") build-path/convention-type: specified convention incompatible with string path element path element: "tutorial" convention: 'unix ```
soapdog commented 4 years ago (Migrated from github.com)

@otherjoel your windows->web function is exactly the same as the helper I built here. ❤️

@otherjoel your `windows->web` function is exactly the same as the helper I built here. :heart:
mbutterick commented 4 years ago (Migrated from github.com)

You can make a path for a different platform, but you have to make path elements that are compatible with the target by explicitly converting from byte strings On my Mac, I can’t do this:

(build-path/convention-type 'windows "tutorial" "other.html")

But this works:

(build-path/convention-type 'windows
                            (bytes->path-element #"tutorial" 'windows)
                            (bytes->path-element #"other.html" 'windows))
#<windows-path:tutorial\other.html>

Handling paths as if they were strings is a little like mixing up eq? and equal? — it seems to give good results, until it suddenly doesn’t. Likewise, be aware that windows->web won’t behave correctly on all cases, even if it behaves correctly on some.

You can make a path for a different platform, but you have to make path elements that are compatible with the target by explicitly converting from byte strings On my Mac, I can’t do this: ``` (build-path/convention-type 'windows "tutorial" "other.html") ``` But this works: ``` (build-path/convention-type 'windows (bytes->path-element #"tutorial" 'windows) (bytes->path-element #"other.html" 'windows)) ``` ``` #<windows-path:tutorial\other.html> ``` Handling paths as if they were strings is a little like mixing up `eq?` and `equal?` — it seems to give good results, until it suddenly doesn’t. Likewise, be aware that `windows->web` won’t behave correctly on all cases, even if it behaves correctly on some.
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#71
Loading…
There is no content yet.