How to use the prismic-dom.Link function in prismic-dom

To help you get started, we’ve selected a few prismic-dom examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github angeloashmore / gatsby-source-prismic / src / normalizeBrowser.js View on Github external
const node = await api.getByID(value.id, { fetchLinks })

        node.data = await normalizeBrowserFields({
          ...args,
          value: node.data,
          node: node,
        })

        // Now that we have this node's normallized data, place it in our cache.
        store.set(value.id, node)
      }

      return new Proxy(
        {
          ...value,
          url: PrismicDOM.Link.url(value, linkResolver),
          target: value.target || '',
          raw: value,
        },
        {
          get: (obj, prop) => {
            if (obj.hasOwnProperty(prop)) return obj[prop]
            if (prop === 'document') return [store.get(value.id)]
          },
        },
      )

    case 'Media':
    case 'Web':
      return {
        ...value,
        target: value.target || '',
github angeloashmore / gatsby-source-prismic / src / browser / normalizers.js View on Github external
const proxyHandler = {
    get: (obj, prop) => {
      if (prop === 'document') {
        if (value.link_type === 'Document' && value.type !== 'broken_type') return getNodeById(linkedDocId)

        return null
      }

      return obj[prop]
    },
  }
  return new Proxy(
    {
      ...value,
      url: PrismicDOM.Link.url(value, linkResolverForField),
      raw: value,
      document: null, // TODO: ???????
    },
    proxyHandler,
  )
}
github angeloashmore / gatsby-source-prismic / src / node / normalizers.js View on Github external
export const normalizeLinkField = async (id, value, _depth, context) => {
  const { doc, createNodeId, pluginOptions } = context
  const { linkResolver } = pluginOptions

  const linkResolverForField = linkResolver({ key: id, value, node: doc })

  let documentId = null
  if (value.link_type === 'Document')
    documentId = createNodeId(`${value.type} ${value.id}`)

  return {
    ...value,
    url: PrismicDOM.Link.url(value, linkResolverForField),
    document: documentId,
    raw: value,
  }
}
github andrewscwei / aristotl / src / utils / prismic.ts View on Github external
export function getUrl(doc?: Document, path: string = ''): string | undefined {
  const fragment = _.get(doc, path);

  if (!fragment) return undefined;

  return PrismicDOM.Link.url(fragment, linkResolver);
}
github angeloashmore / gatsby-source-prismic / src / normalize.js View on Github external
const normalizeLinkField = (value, linkResolver, generateNodeId) => {
  switch (value.link_type) {
    case 'Document':
      if (!value.type || !value.id || value.isBroken) return undefined
      return {
        ...value,
        document___NODE: [generateNodeId(value.type, value.id)],
        url: PrismicDOM.Link.url(value, linkResolver),
        target: value.target || '',
        raw: value,
      }

    case 'Media':
    case 'Web':
      return {
        ...value,
        target: value.target || '',
        raw: value,
      }

    default:
      return undefined
  }
}
github wellcometrust / wellcomecollection.org / common / services / prismic / html-serializers.js View on Github external
);
    case Elements.embed:
      return (
        <div data-oembed-provider="{element.oembed.provider_name}" data-oembed-type="{element.oembed.type}" data-oembed="{element.oembed.embed_url}">
          {element.oembed.html}
        </div>
      );
    case Elements.hyperlink:
      const target = element.data.target || undefined;
      const rel = target ? 'noopener' : undefined;
      const linkUrl = PrismicDOM.Link.url(element.data, linkResolver);
      const isDocument = element.data.kind === 'document';
      const documentSize = isDocument
        ? Math.round(element.data.size / 1000)
        : '';

      const isInPage = linkUrl.match(/^https:\/\/(#.*)/i);
      const hashLink = isInPage &amp;&amp; isInPage[1];

      const fileExtension = linkUrl.match(/\.[0-9a-z]+$/i);
      const documentType =
        fileExtension &amp;&amp; fileExtension[0].substr(1).toUpperCase();

      if (hashLink) {
        return (
          <a href="{hashLink}" rel="{rel}">
            {children}</a>

prismic-dom

Set of helpers to manage Prismic data

Apache-2.0
Latest version published 3 years ago

Package Health Score

45 / 100
Full package analysis