Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support Route Resolver uid, lang, and brokenRoute options #258

Merged
merged 3 commits into from
Aug 23, 2022

Conversation

angeloashmore
Copy link
Member

@angeloashmore angeloashmore commented Aug 20, 2022

Types of changes

  • Chore (a non-breaking change which is related to package maintenance)
  • Bug fix (a non-breaking change which fixes an issue)
  • New feature (a non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Description

This PR adds support for Route Resolver's recently added uid, lang, and brokenRoute options. Route Resolver definitions can be provided to @prismicio/client's routes option.

import * as prismic from "@prismicio/client";

const client = prismic.createClient("your-repo-name", {
  routes: [
    {
      type: "page",
      uid: "home",
      path: "/",
    },
    {
      type: "page",
      path: "/:uid",
    },
  ],
  brokenRoute: "/404",
});

Closes #257.

uid option

The uid option allows a route to be scoped to a document with a specific UID.

In the following example, a Page document with a UID of home will result in a / path. All other Page documents will use a computed path of /:uid.

[
  {
    "type": "page",
    "uid": "home",
    "path": "/"
  },
  {
    "type": "page",
    "path": "/:uid"
  }
]

lang option

The lang option allows a route to be scoped to a specific language.

In the following example, a Page document with a language of fr-fr will result in a /fr/:uid path. All other Page documents will use a computed path of /:uid.

[
  {
    "type": "page",
    "lang": "fr-fr",
    "path": "/fr/:uid"
  },
  {
    "type": "page",
    "path": "/:uid"
  }
]

brokenRoute option

The brokenRoute option allows a route to be defined for Link or Content Relationship fields where its linked document has since been unpublished or deleted.

The brokenRoute option is provided adjacent to the routes option.

In the following example, a Link field linked to a document that has been unpublished will have a url property of /404. Link fields whose documents have not been deleted will follow the other given route definitions.

import * as prismic from "@prismicio/client";

const client = prismic.createClient("your-repo-name", {
  routes: [
    // List of routes...
  ],
  brokenRoute: "/404",
});

Checklist:

  • My change requires an update to the official documentation.
  • All TSDoc comments are up-to-date and new ones have been added where necessary.
  • All new and existing tests are passing.

🚓

@github-actions
Copy link

github-actions bot commented Aug 20, 2022

size-limit report 📦

Path Size
dist/index.js 4.15 KB (+0.5% 🔺)
dist/index.cjs 7.08 KB (+0.3% 🔺)

@codecov-commenter
Copy link

Codecov Report

Merging #258 (b89044b) into master (10c2c5a) will not change coverage.
The diff coverage is 100.00%.

@@            Coverage Diff            @@
##            master      #258   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           23        23           
  Lines         2628      2630    +2     
  Branches       145       145           
=========================================
+ Hits          2628      2630    +2     
Impacted Files Coverage Δ
src/index.ts 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@lihbr
Copy link
Member

lihbr commented Aug 22, 2022

OK, there might have been an issue in communication somewhere (we'll review that), I updated the PR to match the expected API:

Route Resolver route definition interface:

type Route = {
	type: string;
	uid?: string;  // Filters by UID
	lang?: string; // Filters by lang
	path: string;
	resolvers?: Record<string, string>;
};

brokenRoute is an additional API parameters living alongside the routes array.

Should be alright 🤔


For reference here's a test HTML file I've been using to test the new API: routeResolverTest.zip

@angeloashmore
Copy link
Member Author

Thanks for catching that! 🙂

The PR description has been updated to reflect the correct brokenRoute API.

@angeloashmore angeloashmore changed the title feat: support Route Resolver uid and brokenRoute options feat: support Route Resolver uid, lang, and brokenRoute options Aug 23, 2022
@angeloashmore angeloashmore merged commit 22f01c6 into master Aug 23, 2022
@angeloashmore angeloashmore deleted the aa/broken-route branch August 23, 2022 00:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support new brokenRoute parameter in types
3 participants