Skip to content

Improve URL generation across the app #1833

@ErisDS

Description

@ErisDS

At the moment there are an awful lot of places where config().subdir is concatenated with a string to create a URL.

This should be done using a function which takes sensible arguments and generates the URL from a set of constants as mentioned in #1820

Something like:

(adds subdir to any of these if needed)

urlFor('signup') -> /ghost/signup/
urlFor('editor', 3, true) -> http://localhost:2368/ghost/editor/3
urlFor('rss') -> /rss/
urlFor('rss', 2) -> /rss/2
urlFor('home') -> /
urlFor('home', null, true) -> http://localhost:2368/ or similar
urlFor('post', data) -> /:slug/ or /:year/:month/:day/:slug/

Where the first argument is the name of the url/route, the second is data, and the third is whether or not it should be absolute (always false by default).

We have the pageUrl helper which does something like this for /page/2/ and the config.paths.urlFor() function is currently a pending PR #1817 awaiting unit tests / further work which may take it closer to this.

The big issue we have right now is the need to be able to generate a url for a context from handlebars, which is what the existing urlFor is intended to do. i.e. we don't know if we're inside a post, a tag or a user, or inside nothing at all, but wherever we are we want this thing's url.

The other problem is the dependence on api.settings to get the permalink structure which means the url method has to be async.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions