Skip to content

feat(DeadLinks): add config override for resolving custom link markDefs#3

Open
aliameur wants to merge 3 commits into
planetary:mainfrom
aliameur:main
Open

feat(DeadLinks): add config override for resolving custom link markDefs#3
aliameur wants to merge 3 commits into
planetary:mainfrom
aliameur:main

Conversation

@aliameur

@aliameur aliameur commented Aug 6, 2024

Copy link
Copy Markdown

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