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(DeadLinks): add config override for resolving custom link markDefs #3

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

aliameur
Copy link

@aliameur aliameur commented Aug 6, 2024

This PR proposes customisation for the DeadLinks plugin to solve #2

Example usage

Simple override

Preflight({
  plugins: [
    DeadLinks({
      content: "content",
      overrideLinkKeys: ["url", "href"],
    }),
  ],
})

A slightly more advanced override

// these types could be generated with sanity typegen generate
type MyExternalLinkType = {
  url: string;
  target: string;
}

type MyProductLinkType = {
  fullUrl: string;
  showOnHover?: boolean;
}

type MyCustomLinkType = {
  hrefForAdmin: string;
  hrefForGuest: string;
}

Preflight({
  plugins: [
    DeadLinks<MyExternalLinkType | MyProductLinkType | MyCustomLinkType>({
      content: "content",
      overrideLinkKeys: ["url", "fullUrl", "hrefForGuest"], // typescript will only allow keys of the generics above
    }),
  ],
})

Questions

  • Should this directly support doing typescript typeof mySchemaType? This adds a lot more complexity that at first thought may fall outside the scope of library, but admittedly a nice DX.
  • Are there any other ways links could be embedded in portable text that this proposed override would not pick up?
  • How should an example be portrayed in the README.md?

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.

1 participant