On this page:
top
src-path
src/  posts-path
post-template.html
page-template.html
index-template.html
obj-path
www-path
www/  tags-path
www/  feeds-path
www/  img-path
www/  index-pathname
abs->rel/  www
abs->rel/  src
abs->rel/  top
canonical-uri
full-uri
slug

9 Paths

Although you may use these definitions in your darwin.rkt, they are more likely to be used by third-party Body enhancers.

 (require darwin/paths) package: darwin

(This module is automatically required for you by the darwin/config language used in darwin.rkt.)

These definitions represent locations of certain local directories and files — as well as translating between local filesystem paths and URI paths that will work on the deployed web site. One wrinkle is that the local file paths might be Windows style, which differs from the Unix style used by URI paths.

parameter

(top)  (or/c #f absolute-path?)

(top path)  void?
  path : (or/c #f absolute-path?)
The project directory root. Darwin sets the value after it has initialized and found the location of darwin.rkt. Many other functions in this module expect top to be non-#f, so for example in unit tests you may need to set this yourself.

procedure

(src-path)  absolute-path?

Resolved location of current-source-dir.
The "posts" subdirectory of src-path.
The "post-template.html" file in src-path.
The "page-template.html" file in src-path.
The "index-template.html" in src-path.

procedure

(obj-path)  absolute-path?

The ".darwin" build cache subdirectory.

procedure

(www-path)  absolute-path?

Root of the output files, as determined by current-output-dir.

procedure

(www/tags-path)  absolute-path?

The "tags/" subdirectory of www-path.
The "feeds/" subdirectory of www-path.

procedure

(www/img-path)  absolute-path?

The "img/" subdirectory of www-path.
Resolves current-posts-index-uri regardless of it being any of "/path/index.html", "\path\index.html", or "c:\path\index.html"

procedure

(abs->rel/www path)  string?

  path : absolute-path?
Convert an absolute local path to a URI path string relative to www-path which in turn is relative to current-output-dir. The result is always in Unix style (even on Windows) so it is suitable for use as a URI path.

For example if top is "/project/blog" and current-output-dir is "../build", then given "/project/build/css" this should return "/css". Same result if on Windows and top is "c:\project\blog" and current-output-dir is "..\build".

NOTE: If you’re creating a URI that a client will use to make an HTTP request — e.g. you will write it in an HTML, feed, or sitemap file — this result isn’t sufficient. You should run the result through canonical-uri, and if you need current-scheme/host prepended, in turn through full-uri.

Examples:
> (require darwin/paths darwin/params)
> (parameterize ([top "/projects/blog"]
                 [current-output-dir "."])
    (abs->rel/www (string->path "/projects/blog/css")))

"/css"

> (parameterize ([top "/projects/blog"]
                 [current-output-dir "../build"])
    (abs->rel/www (string->path "/projects/build/css")))

"/css"

procedure

(abs->rel/src path)  path-string?

  path : absolute-path?
Convert an absolute local path to a local path-string relative to src-path.

procedure

(abs->rel/top path)  path-string?

  path : absolute-path?
Convert an absolute local path to a local path-string relative to top.

procedure

(canonical-uri uri-path)  string?

  uri-path : string?
Possibly rewrite a URI path to take account of non-#f current-uri-prefix and uri-path-segment-encode it.

Examples:
> (require darwin/paths darwin/params)
> (canonical-uri "relative/λ/path")

"relative/%3F/path"

> (parameterize ([current-uri-prefix #f])
    (canonical-uri "/absolute/λ/path"))

"/absolute/%3F/path"

> (parameterize ([current-uri-prefix "/prefix"])
    (canonical-uri "/absolute/λ/path"))

"/prefix/absolute/%3F/path"

procedure

(full-uri uri-path)  string?

  uri-path : string?
Given a URI path string, prepend the scheme & host to make a full URI.

Examples:
> (require darwin/paths darwin/params)
> (parameterize ([current-scheme/host "https://www.example.com"])
    (full-uri "/absolute/path/to/file.html"))

"https://www.example.com/absolute/path/to/file.html"

procedure

(slug s)  string?

  s : string?
Convert a string into a "slug", in which:

Examples:
> (require darwin/paths)
> (slug "Foo? Bar. Baz.")

"Foo-Bar-Baz"

> (slug "Here's a question--how many hyphens???")

"Here-s-a-question-how-many-hyphens"

> (slug "La biblioteca está en el estómago de Godzilla")

"La-biblioteca-está-en-el-estómago-de-Godzilla"