UNPKG

@venuecms/sdk-next

Version:

This is a work in progress and is heavily in flux until we launch 1.0 in February.

1 lines 10.9 kB
{"version":3,"sources":["../../../node_modules/.pnpm/remove-markdown@0.6.0/node_modules/remove-markdown/index.js","../src/lib/metadata/index.ts"],"sourcesContent":["module.exports = function(md, options) {\n options = options || {};\n options.listUnicodeChar = options.hasOwnProperty('listUnicodeChar') ? options.listUnicodeChar : false;\n options.stripListLeaders = options.hasOwnProperty('stripListLeaders') ? options.stripListLeaders : true;\n options.gfm = options.hasOwnProperty('gfm') ? options.gfm : true;\n options.useImgAltText = options.hasOwnProperty('useImgAltText') ? options.useImgAltText : true;\n options.abbr = options.hasOwnProperty('abbr') ? options.abbr : false;\n options.replaceLinksWithURL = options.hasOwnProperty('replaceLinksWithURL') ? options.replaceLinksWithURL : false;\n options.htmlTagsToSkip = options.hasOwnProperty('htmlTagsToSkip') ? options.htmlTagsToSkip : [];\n options.throwError = options.hasOwnProperty('throwError') ? options.throwError : false;\n\n var output = md || '';\n\n // Remove horizontal rules (stripListHeaders conflict with this rule, which is why it has been moved to the top)\n output = output.replace(/^ {0,3}((?:-[\\t ]*){3,}|(?:_[ \\t]*){3,}|(?:\\*[ \\t]*){3,})(?:\\n+|$)/gm, '');\n\n try {\n if (options.stripListLeaders) {\n if (options.listUnicodeChar)\n output = output.replace(/^([\\s\\t]*)([\\*\\-\\+]|\\d+\\.)\\s+/gm, options.listUnicodeChar + ' $1');\n else\n output = output.replace(/^([\\s\\t]*)([\\*\\-\\+]|\\d+\\.)\\s+/gm, '$1');\n }\n if (options.gfm) {\n output = output\n // Header\n .replace(/\\n={2,}/g, '\\n')\n // Fenced codeblocks\n .replace(/~{3}.*\\n/g, '')\n // Strikethrough\n .replace(/~~/g, '')\n // Fenced codeblocks\n .replace(/`{3}.*\\n/g, '');\n }\n if (options.abbr) {\n // Remove abbreviations\n output = output.replace(/\\*\\[.*\\]:.*\\n/, '');\n }\n \n let htmlReplaceRegex = /<[^>]*>/g\n if (options.htmlTagsToSkip && options.htmlTagsToSkip.length > 0) {\n // Create a regex that matches tags not in htmlTagsToSkip\n const joinedHtmlTagsToSkip = options.htmlTagsToSkip.join('|')\n htmlReplaceRegex = new RegExp(\n `<(?!\\/?(${joinedHtmlTagsToSkip})(?=>|\\s[^>]*>))[^>]*>`,\n 'g',\n )\n }\n\n output = output\n // Remove HTML tags\n .replace(htmlReplaceRegex, '')\n // Remove setext-style headers\n .replace(/^[=\\-]{2,}\\s*$/g, '')\n // Remove footnotes?\n .replace(/\\[\\^.+?\\](\\: .*?$)?/g, '')\n .replace(/\\s{0,2}\\[.*?\\]: .*?$/g, '')\n // Remove images\n .replace(/\\!\\[(.*?)\\][\\[\\(].*?[\\]\\)]/g, options.useImgAltText ? '$1' : '')\n // Remove inline links\n .replace(/\\[([^\\]]*?)\\][\\[\\(].*?[\\]\\)]/g, options.replaceLinksWithURL ? '$2' : '$1')\n // Remove blockquotes\n .replace(/^(\\n)?\\s{0,3}>\\s?/gm, '$1')\n // .replace(/(^|\\n)\\s{0,3}>\\s?/g, '\\n\\n')\n // Remove reference-style links?\n .replace(/^\\s{1,2}\\[(.*?)\\]: (\\S+)( \".*?\")?\\s*$/g, '')\n // Remove atx-style headers\n .replace(/^(\\n)?\\s{0,}#{1,6}\\s*( (.+))? +#+$|^(\\n)?\\s{0,}#{1,6}\\s*( (.+))?$/gm, '$1$3$4$6')\n // Remove * emphasis\n .replace(/([\\*]+)(\\S)(.*?\\S)??\\1/g, '$2$3')\n // Remove _ emphasis. Unlike *, _ emphasis gets rendered only if \n // 1. Either there is a whitespace character before opening _ and after closing _.\n // 2. Or _ is at the start/end of the string.\n .replace(/(^|\\W)([_]+)(\\S)(.*?\\S)??\\2($|\\W)/g, '$1$3$4$5')\n // Remove code blocks\n .replace(/(`{3,})(.*?)\\1/gm, '$2')\n // Remove inline code\n .replace(/`(.+?)`/g, '$1')\n // // Replace two or more newlines with exactly two? Not entirely sure this belongs here...\n // .replace(/\\n{2,}/g, '\\n\\n')\n // // Remove newlines in a paragraph\n // .replace(/(\\S+)\\n\\s*(\\S+)/g, '$1 $2')\n // Replace strike through\n .replace(/~(.*?)~/g, '$1');\n } catch(e) {\n if (options.throwError) throw e;\n\n console.error(\"remove-markdown encountered error: %s\", e);\n return md;\n }\n return output;\n};\n","import {\n type LocalizedContent,\n MediaItem,\n type Site,\n getLocalizedContent,\n getSite,\n setConfig,\n} from \"@venuecms/sdk\";\nimport removeMarkdown from \"remove-markdown\";\nimport { getPublicImage } from \"../../components/utils\";\n\n\ntype Params = { locale: string; siteKey: string };\n\ntype LocalizedItem = {\n image?: MediaItem;\n localizedContent: Array<LocalizedContent>;\n};\n\ntype Metadata = {\n title: string;\n siteName: string;\n metaTitle: string;\n metaDescription: string;\n keywords: string;\n\n content: string;\n shortContent: string;\n};\n\nexport const getLocalizedMetadata = ({\n locale,\n item,\n site,\n overrides = {},\n}: {\n locale: string;\n item?: LocalizedItem;\n site: Site;\n overrides?: Partial<Metadata>;\n}) => {\n const { content } = item?.localizedContent\n ? getLocalizedContent(item?.localizedContent, locale)\n : {};\n\n const {\n title,\n content: description,\n shortContent,\n metaTitle,\n metaDescription,\n keywords,\n } = content ?? overrides;\n\n const getOpenGraphFromLocalizedContent = (item?: LocalizedItem) => {\n const imageUrl = item?.image && getPublicImage(item.image);\n const siteImageUrl = site.image && getPublicImage(site.image);\n\n const trimDescription = description\n ? removeMarkdown(description).split(\"\\n\")[0]\n : undefined;\n return {\n title: metaTitle || title,\n description: metaDescription || shortContent || trimDescription,\n siteName: site.name,\n ...(item?.image && imageUrl\n ? {\n images: [\n {\n width: item.image.metadata?.width,\n height: item.image.metadata?.height,\n url: imageUrl,\n },\n ],\n }\n : {\n images: [\n {\n width: site.image?.metadata?.width,\n height: site.image?.metadata?.height,\n url: siteImageUrl,\n },\n ],\n }),\n locale,\n type: \"website\",\n ...overrides,\n };\n };\n\n return {\n title: `${site.name}${title ? ` - ${title}` : \"\"}`,\n description:\n metaDescription ||\n shortContent ||\n (description ? removeMarkdown(description) : undefined),\n keywords: keywords?.split(\", \"),\n openGraph: getOpenGraphFromLocalizedContent(item),\n ...overrides,\n };\n};\n\n// Gets metadata for a single item that is queried by a slug.\n// When a getItem is not passed, it will simply use the overrides passed\nexport const getGenerateMetadata =\n (getItem: (params: { slug: string }) => Promise<{ data: any }>) =>\n async ({ params }: { params: Promise<Params & { slug: string }> }) => {\n try {\n const { siteKey, slug, locale } = await params;\n setConfig({ siteKey });\n\n const [{ data: site }, { data: item }] = await Promise.all([\n getSite(),\n getItem({ slug }),\n ]);\n\n if (!site || !item) {\n return {};\n }\n\n const metadata = getLocalizedMetadata({\n locale,\n item,\n site,\n });\n\n return metadata;\n } catch (e) {\n return {};\n }\n };\n"],"mappings":";gJAAA,IAAAA,EAAAC,EAAA,CAAAC,EAAAC,IAAA,cAAAA,EAAO,QAAU,SAASC,EAAIC,EAAS,CACrCA,EAAUA,GAAW,CAAC,EACtBA,EAAQ,gBAAkBA,EAAQ,eAAe,iBAAiB,EAAIA,EAAQ,gBAAkB,GAChGA,EAAQ,iBAAmBA,EAAQ,eAAe,kBAAkB,EAAIA,EAAQ,iBAAmB,GACnGA,EAAQ,IAAMA,EAAQ,eAAe,KAAK,EAAIA,EAAQ,IAAM,GAC5DA,EAAQ,cAAgBA,EAAQ,eAAe,eAAe,EAAIA,EAAQ,cAAgB,GAC1FA,EAAQ,KAAOA,EAAQ,eAAe,MAAM,EAAIA,EAAQ,KAAO,GAC/DA,EAAQ,oBAAsBA,EAAQ,eAAe,qBAAqB,EAAIA,EAAQ,oBAAsB,GAC5GA,EAAQ,eAAiBA,EAAQ,eAAe,gBAAgB,EAAIA,EAAQ,eAAiB,CAAC,EAC9FA,EAAQ,WAAaA,EAAQ,eAAe,YAAY,EAAIA,EAAQ,WAAa,GAEjF,IAAIC,EAASF,GAAM,GAGnBE,EAASA,EAAO,QAAQ,uEAAwE,EAAE,EAElG,GAAI,CACED,EAAQ,mBACNA,EAAQ,gBACVC,EAASA,EAAO,QAA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K,CAAC,CAClB,CAAC,EAED,MAAI,CAACpB,GAAQ,CAACD,EACL,CAAC,EAGOF,EAAqB,CACpC,OAAAC,EACA,KAAAC,EACA,KAAAC,CACF,CAAC,CAGH,MAAY,CACV,MAAO,CAAC,CACV,CACF","names":["require_remove_markdown","__commonJSMin","exports","module","md","options","output","htmlReplaceRegex","joinedHtmlTagsToSkip","e","import_remove_markdown","getLocalizedMetadata","locale","item","site","overrides","content","getLocalizedContent","title","description","shortContent","metaTitle","metaDescription","keywords","getOpenGraphFromLocalizedContent","imageUrl","getPublicImage","siteImageUrl","trimDescription","removeMarkdown","getGenerateMetadata","getItem","params","siteKey","slug","setConfig","getSite2"]}