Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | 1x 1x 1x 1x 1x 1x 1x 4x 1x 1x 4x 1x 1x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 1x 1x 1x 1x | import type { Links, LinksContext } from "./types";
export type { LinksContext };
import type { PageMetadataMap } from "$lib/loadPageMetadataMap";
export const linksKey = Symbol("contentfulRichTextLinks");
const getAssetLinksMap = (links: Links, key: "block" | "hyperlink") =>
new Map(links.assets?.[key]?.flatMap((link) => (link ? [[link?.sys?.id, link]] : [])));
const getAssetEntriesMap = (links: Links, key: "block" | "hyperlink") =>
new Map(links.entries?.[key]?.flatMap((link) => (link ? [[link?.sys?.id, link]] : [])));
export const createLinksContext = (
links: Links,
pageMetadataMap: PageMetadataMap,
): LinksContext => {
return {
pageMetadataMap,
links: {
assets: {
block: links.assets?.block?.filter(Boolean),
hyperlink: links.assets?.hyperlink?.filter(Boolean),
},
entries: {
block: links.entries?.block?.filter(Boolean),
hyperlink: links.entries?.hyperlink?.filter(Boolean),
},
},
linksAssetsMaps: {
block: getAssetLinksMap(links, "block"),
hyperlink: getAssetLinksMap(links, "hyperlink"),
},
linksEntriesMaps: {
block: getAssetEntriesMap(links, "block"),
hyperlink: getAssetEntriesMap(links, "hyperlink"),
},
};
};
export const blurhashesKey = Symbol("blurhashes");
export const imageSizeTypeKey = Symbol("sizeType");
|