diff --git a/api/package.json b/api/package.json index 82c3d252..c50f53cf 100644 --- a/api/package.json +++ b/api/package.json @@ -22,7 +22,9 @@ "esbuild": "^0.14.47", "express": "^4.18.1", "express-basic-auth": "^1.2.1", + "hast-util-from-html": "^1.0.0", "hast-util-parse-selector": "^3.1.0", + "headless-mermaid": "^1.3.0", "http-status": "^1.5.2", "is-badge": "^2.1.0", "js-yaml": "^4.1.0", diff --git a/api/src/bundler/bundler.ts b/api/src/bundler/bundler.ts index 7aae9b4e..39ccbdef 100644 --- a/api/src/bundler/bundler.ts +++ b/api/src/bundler/bundler.ts @@ -70,6 +70,7 @@ export async function bundle( return { code, frontmatter, + //@ts-ignore errors, headings: output.headings, }; diff --git a/api/src/bundler/plugins/rehype-code-blocks.ts b/api/src/bundler/plugins/rehype-code-blocks.ts index 69120452..2f1e88a3 100644 --- a/api/src/bundler/plugins/rehype-code-blocks.ts +++ b/api/src/bundler/plugins/rehype-code-blocks.ts @@ -4,39 +4,73 @@ import { visit } from 'unist-util-visit'; import { Node } from 'hast-util-heading-rank'; import { toString } from 'mdast-util-to-string'; import * as shiki from 'shiki'; - let highlighter: shiki.Highlighter; - +//@ts-ignore +import mermaid from 'headless-mermaid'; +//@ts-ignore +import { fromHtml } from 'hast-util-from-html'; /** * Matches any `pre code` elements and extracts the raw code and titles from the code block and assigns to the parent. * @returns */ export default function rehypeCodeBlocks(): (ast: Node) => void { - function visitor(node: any, _i: number, parent: any) { - if (!parent || parent.tagName !== 'pre' || node.tagName !== 'code') { - return; - } - const language = getLanguage(node); - const raw = toString(node); + return async (ast: Node): Promise => { - // Raw value of the `code` block - used for copy/paste - parent.properties['raw'] = raw; - parent.properties['html'] = highlighter.codeToHtml(raw, language); + const promises: any[] = []; - // Get any metadata from the code block - const meta = (node.data?.meta as string) ?? ''; + async function visitor(node: any, i: number, parent: any) { + if (!parent || parent.tagName !== 'pre' || node.tagName !== 'code') { + return; + } - const title = extractTitle(meta); - if (title) parent.properties['title'] = title; - } + const language = getLanguage(node); + + const raw = toString(node); + + if (language === 'mermaid') { + + const value = node.children[0].value; + + + promises.push(mermaid.execute(value).then((svgResult: string) => { + //@ts-ignore + console.log(fromHtml(svgResult).children[0].children[1].children) + //@ts-ignore + const svgNode = fromHtml(svgResult).children[0].children[1].children[0]; + + Object.assign(parent, svgNode); + })) + + return; + } + + // If the user provides the `console` language, we add the 'shell' language and remove $ from the raw code, for copying purposes. + if (language === 'console') { + const removedDollarSymbol = raw.replace(/^(^ *)\$/g, ''); + + parent.properties['raw'] = removedDollarSymbol; + parent.properties['html'] = highlighter.codeToHtml(raw, { lang: 'shell' }); + } else { + parent.properties['raw'] = raw; + parent.properties['html'] = highlighter.codeToHtml(raw, { lang: language }); + } + + // Get any metadata from the code block + const meta = (node.data?.meta as string) ?? ''; + + const title = extractTitle(meta); + if (title) parent.properties['title'] = title; + } - return async (ast: Node): Promise => { highlighter = await shiki.getHighlighter({ theme: 'github-dark', }); // @ts-ignore visit(ast, 'element', visitor); + + await Promise.all(promises); + return null; }; } @@ -76,4 +110,4 @@ function getLanguage(node: any): string | undefined { return value.slice(9); } } -} +} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 69bbe249..06a524e6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -561,9 +561,9 @@ } }, "node_modules/@astrojs/compiler": { - "version": "0.30.1", - "resolved": "https://registry.npmjs.org/@astrojs/compiler/-/compiler-0.30.1.tgz", - "integrity": "sha512-sH3hvGA9JR5eE2bHG3sr5QjaJl5ER9EmmZzSwBHkMPoBj0XU7XzQjSGoyCbIML6sSaelJEPnfsr9NsypvKOecg==" + "version": "0.31.0", + "resolved": "https://registry.npmjs.org/@astrojs/compiler/-/compiler-0.31.0.tgz", + "integrity": "sha512-V8/Re/wXgXTZzpfWs4KZBLU5dRhnO6kSd4e3vObGuj+HFGHjaD11wws1zvaC9cXLQyQsM5CSrGagFGYlRZKvVQ==" }, "node_modules/@astrojs/language-server": { "version": "0.28.3", @@ -635,15 +635,24 @@ } }, "node_modules/@astrojs/node": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/@astrojs/node/-/node-3.1.0.tgz", - "integrity": "sha512-teKbDU3u1BIhh3pIVtLsBF/Hxr6NioInfnVFLlPp9afFFlVhakO3N+nR8fPkXrpNXGP3AxQmk+ROI4YHvhIIFw==", + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/@astrojs/node/-/node-3.1.1.tgz", + "integrity": "sha512-EWfsvCtOGvN1ugpxhiW4sr0xD8xUGltFOcU/ysOHdVpP6WXWQUTZbYbqDo+fgYhYHksLIcBLxg8vLi+gBQMA1Q==", + "dev": true, "dependencies": { "@astrojs/webapi": "^1.1.1", "send": "^0.18.0" }, "peerDependencies": { - "astro": "^1.6.10" + "astro": "^1.6.15" + } + }, + "node_modules/@astrojs/prefetch": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/@astrojs/prefetch/-/prefetch-0.1.1.tgz", + "integrity": "sha512-+XZcjivPHTo9thQshDWKnnORHJ1dE6odIzhmKHac2ptwla092eohkiJw7Y31+PYmuJkc3Jp+3AawuCvfqCnQ2Q==", + "dependencies": { + "throttles": "^1.0.1" } }, "node_modules/@astrojs/prism": { @@ -708,9 +717,9 @@ } }, "node_modules/@astrojs/vercel": { - "version": "2.3.5", - "resolved": "https://registry.npmjs.org/@astrojs/vercel/-/vercel-2.3.5.tgz", - "integrity": "sha512-kjbIKsbaHX41llEV2Qzj9/R8SfYjy/gNG6CdVATuQM1GGBayEvJYn7pU75YalrvLTrqfMKywS+oFPW9fwJl8yA==", + "version": "2.3.6", + "resolved": "https://registry.npmjs.org/@astrojs/vercel/-/vercel-2.3.6.tgz", + "integrity": "sha512-OAfu1d6pgzhKIi48rAKemfhNO6s8ZF/38zSRqGZwl9HnY5qfacccqWmoVeUJ9lSqB/rljxA5Xzh3s+jMqyd9mA==", "dev": true, "dependencies": { "@astrojs/webapi": "^1.1.1", @@ -5216,6 +5225,15 @@ "@types/react": "*" } }, + "node_modules/@types/request-ip": { + "version": "0.0.37", + "resolved": "https://registry.npmjs.org/@types/request-ip/-/request-ip-0.0.37.tgz", + "integrity": "sha512-uw6/i3rQnpznxD7LtLaeuZytLhKZK6bRoTS6XVJlwxIOoOpEBU7bgKoVXDNtOg4Xl6riUKHa9bjMVrL6ESqYlQ==", + "dev": true, + "dependencies": { + "@types/node": "*" + } + }, "node_modules/@types/resolve": { "version": "1.20.2", "resolved": "https://registry.npmjs.org/@types/resolve/-/resolve-1.20.2.tgz", @@ -6587,11 +6605,11 @@ } }, "node_modules/astro": { - "version": "1.6.14", - "resolved": "https://registry.npmjs.org/astro/-/astro-1.6.14.tgz", - "integrity": "sha512-8ljrWPKEU5Hrrbupan48ba4gLWPY14Aqiv4u0U92wSl3wtsqPJUWWlHGGkXcgS/9dx8aiLkUm4RzCPFVnP7V2w==", + "version": "1.6.15", + "resolved": "https://registry.npmjs.org/astro/-/astro-1.6.15.tgz", + "integrity": "sha512-FT60PalffV0bCNxqEHadRzb+Rd3g3lYxV3fR9+bZ2CRlbSfC3UdoaLDh5wC6gJiz91caH1R0XiYaV0WT2Zg91g==", "dependencies": { - "@astrojs/compiler": "^0.30.0", + "@astrojs/compiler": "^0.31.0", "@astrojs/language-server": "^0.28.3", "@astrojs/markdown-remark": "^1.1.3", "@astrojs/telemetry": "^1.0.1", @@ -6623,7 +6641,7 @@ "html-escaper": "^3.0.3", "import-meta-resolve": "^2.1.0", "kleur": "^4.1.4", - "magic-string": "^0.25.9", + "magic-string": "^0.27.0", "mime": "^3.0.0", "ora": "^6.1.0", "path-browserify": "^1.0.1", @@ -6660,10 +6678,21 @@ "npm": ">=6.14.0" } }, + "node_modules/astro/node_modules/magic-string": { + "version": "0.27.0", + "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.27.0.tgz", + "integrity": "sha512-8UnnX2PeRAPZuN12svgR9j7M1uWMovg/CEnIwIG0LFkXSJJe4PdfUGiTGl8V9bsBHFUtfVINcSyYxd7q+kx9fA==", + "dependencies": { + "@jridgewell/sourcemap-codec": "^1.4.13" + }, + "engines": { + "node": ">=12" + } + }, "node_modules/astro/node_modules/semver": { - "version": "7.3.7", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.7.tgz", - "integrity": "sha512-QlYTucUYOews+WeEujDoEGziz4K6c47V/Bd+LjSSYcA94p+DmINdf7ncaUinThfvZyu13lN9OY1XDxt8C0Tw0g==", + "version": "7.3.8", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.8.tgz", + "integrity": "sha512-NB1ctGL5rlHrPJtFDVIVzTyQylMLu9N9VICA6HSFJo8MCGVTMW6gfpicwKmmK/dAjTOrqu5l63JJOpDSrAis3A==", "dependencies": { "lru-cache": "^6.0.0" }, @@ -11182,27 +11211,27 @@ } }, "node_modules/hast-to-hyperscript/node_modules/comma-separated-tokens": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/comma-separated-tokens/-/comma-separated-tokens-2.0.2.tgz", - "integrity": "sha512-G5yTt3KQN4Yn7Yk4ed73hlZ1evrFKXeUW3086p3PRFNp7m2vIjI6Pg+Kgb+oyzhd9F2qdcoj67+y3SdxL5XWsg==", + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/comma-separated-tokens/-/comma-separated-tokens-2.0.3.tgz", + "integrity": "sha512-Fu4hJdvzeylCfQPp9SGWidpzrMs7tTrlu6Vb8XGaRGck8QSNZJJp538Wrb60Lax4fPwR64ViY468OIUTbRlGZg==", "funding": { "type": "github", "url": "https://github.com/sponsors/wooorm" } }, "node_modules/hast-to-hyperscript/node_modules/property-information": { - "version": "6.1.1", - "resolved": "https://registry.npmjs.org/property-information/-/property-information-6.1.1.tgz", - "integrity": "sha512-hrzC564QIl0r0vy4l6MvRLhafmUowhO/O3KgVSoXIbbA2Sz4j8HGpJc6T2cubRVwMwpdiG/vKGfhT4IixmKN9w==", + "version": "6.2.0", + "resolved": "https://registry.npmjs.org/property-information/-/property-information-6.2.0.tgz", + "integrity": "sha512-kma4U7AFCTwpqq5twzC1YVIDXSqg6qQK6JN0smOw8fgRy1OkMi0CYSzFmsy6dnqSenamAtj0CyXMUJ1Mf6oROg==", "funding": { "type": "github", "url": "https://github.com/sponsors/wooorm" } }, "node_modules/hast-to-hyperscript/node_modules/space-separated-tokens": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/space-separated-tokens/-/space-separated-tokens-2.0.1.tgz", - "integrity": "sha512-ekwEbFp5aqSPKaqeY1PGrlGQxPNaq+Cnx4+bE2D8sciBQrHpbwoBbawqTN2+6jPs9IdWxxiUcN0K2pkczD3zmw==", + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/space-separated-tokens/-/space-separated-tokens-2.0.2.tgz", + "integrity": "sha512-PEGlAwrG8yXGXRjW32fGbg66JAlOAwbObuqVoJpv/mRgoWDQfgH1wDPvtzWyUSNAXBGSk8h755YDbbcEy3SH2Q==", "funding": { "type": "github", "url": "https://github.com/sponsors/wooorm" @@ -11317,9 +11346,9 @@ } }, "node_modules/hast-util-raw/node_modules/zwitch": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/zwitch/-/zwitch-2.0.2.tgz", - "integrity": "sha512-JZxotl7SxAJH0j7dN4pxsTV6ZLXoLdGME+PsjkL/DaBrVryK9kTGq06GfKrwcSOqypP+fdXGoCHE36b99fWVoA==", + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/zwitch/-/zwitch-2.0.4.tgz", + "integrity": "sha512-bXE4cR/kVZhKZX/RjPEflHaKVhUVl85noU3v6b8apfQEc1x4A+zBxjZ4lN8LqGd6WZ3dl98pY4o717VFmoPp+A==", "funding": { "type": "github", "url": "https://github.com/sponsors/wooorm" @@ -11376,9 +11405,9 @@ } }, "node_modules/hast-util-to-html/node_modules/comma-separated-tokens": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/comma-separated-tokens/-/comma-separated-tokens-2.0.2.tgz", - "integrity": "sha512-G5yTt3KQN4Yn7Yk4ed73hlZ1evrFKXeUW3086p3PRFNp7m2vIjI6Pg+Kgb+oyzhd9F2qdcoj67+y3SdxL5XWsg==", + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/comma-separated-tokens/-/comma-separated-tokens-2.0.3.tgz", + "integrity": "sha512-Fu4hJdvzeylCfQPp9SGWidpzrMs7tTrlu6Vb8XGaRGck8QSNZJJp538Wrb60Lax4fPwR64ViY468OIUTbRlGZg==", "funding": { "type": "github", "url": "https://github.com/sponsors/wooorm" @@ -11394,18 +11423,18 @@ } }, "node_modules/hast-util-to-html/node_modules/property-information": { - "version": "6.1.1", - "resolved": "https://registry.npmjs.org/property-information/-/property-information-6.1.1.tgz", - "integrity": "sha512-hrzC564QIl0r0vy4l6MvRLhafmUowhO/O3KgVSoXIbbA2Sz4j8HGpJc6T2cubRVwMwpdiG/vKGfhT4IixmKN9w==", + "version": "6.2.0", + "resolved": "https://registry.npmjs.org/property-information/-/property-information-6.2.0.tgz", + "integrity": "sha512-kma4U7AFCTwpqq5twzC1YVIDXSqg6qQK6JN0smOw8fgRy1OkMi0CYSzFmsy6dnqSenamAtj0CyXMUJ1Mf6oROg==", "funding": { "type": "github", "url": "https://github.com/sponsors/wooorm" } }, "node_modules/hast-util-to-html/node_modules/space-separated-tokens": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/space-separated-tokens/-/space-separated-tokens-2.0.1.tgz", - "integrity": "sha512-ekwEbFp5aqSPKaqeY1PGrlGQxPNaq+Cnx4+bE2D8sciBQrHpbwoBbawqTN2+6jPs9IdWxxiUcN0K2pkczD3zmw==", + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/space-separated-tokens/-/space-separated-tokens-2.0.2.tgz", + "integrity": "sha512-PEGlAwrG8yXGXRjW32fGbg66JAlOAwbObuqVoJpv/mRgoWDQfgH1wDPvtzWyUSNAXBGSk8h755YDbbcEy3SH2Q==", "funding": { "type": "github", "url": "https://github.com/sponsors/wooorm" @@ -11429,18 +11458,18 @@ } }, "node_modules/hast-util-to-parse5/node_modules/property-information": { - "version": "6.1.1", - "resolved": "https://registry.npmjs.org/property-information/-/property-information-6.1.1.tgz", - "integrity": "sha512-hrzC564QIl0r0vy4l6MvRLhafmUowhO/O3KgVSoXIbbA2Sz4j8HGpJc6T2cubRVwMwpdiG/vKGfhT4IixmKN9w==", + "version": "6.2.0", + "resolved": "https://registry.npmjs.org/property-information/-/property-information-6.2.0.tgz", + "integrity": "sha512-kma4U7AFCTwpqq5twzC1YVIDXSqg6qQK6JN0smOw8fgRy1OkMi0CYSzFmsy6dnqSenamAtj0CyXMUJ1Mf6oROg==", "funding": { "type": "github", "url": "https://github.com/sponsors/wooorm" } }, "node_modules/hast-util-to-parse5/node_modules/zwitch": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/zwitch/-/zwitch-2.0.2.tgz", - "integrity": "sha512-JZxotl7SxAJH0j7dN4pxsTV6ZLXoLdGME+PsjkL/DaBrVryK9kTGq06GfKrwcSOqypP+fdXGoCHE36b99fWVoA==", + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/zwitch/-/zwitch-2.0.4.tgz", + "integrity": "sha512-bXE4cR/kVZhKZX/RjPEflHaKVhUVl85noU3v6b8apfQEc1x4A+zBxjZ4lN8LqGd6WZ3dl98pY4o717VFmoPp+A==", "funding": { "type": "github", "url": "https://github.com/sponsors/wooorm" @@ -13840,6 +13869,11 @@ "node": ">= 0.6" } }, + "node_modules/medium-zoom": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/medium-zoom/-/medium-zoom-1.0.8.tgz", + "integrity": "sha512-CjFVuFq/IfrdqesAXfg+hzlDKu6A2n80ZIq0Kl9kWjoHh9j1N9Uvk5X0/MmN0hOfm5F9YBswlClhcwnmtwz7gA==" + }, "node_modules/merge-descriptors": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz", @@ -17345,6 +17379,11 @@ "node": ">=0.10" } }, + "node_modules/request-ip": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/request-ip/-/request-ip-3.3.0.tgz", + "integrity": "sha512-cA6Xh6e0fDBBBwH77SLJaJPBmD3nWVAcF9/XAcsrIHdjhFzFiB5aNQFytdjCGPezU3ROwrR11IddKAM08vohxA==" + }, "node_modules/require-directory": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", @@ -19086,6 +19125,14 @@ "integrity": "sha512-N+8UisAXDGk8PFXP4HAzVR9nbfmVJ3zYLAWiTIoqC5v5isinhr+r5uaO8+7r3BMfuNIufIsA7RdpVgacC2cSpw==", "dev": true }, + "node_modules/throttles": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/throttles/-/throttles-1.0.1.tgz", + "integrity": "sha512-fab7Xg+zELr9KOv4fkaBoe/b3L0GMGLd0IBSCn16GoE/Qx6/OfCr1eGNyEcDU2pUA79qQfZ8kPQWlRuok4YwTw==", + "engines": { + "node": ">=6" + } + }, "node_modules/through": { "version": "2.3.8", "resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz", @@ -20965,9 +21012,9 @@ "integrity": "sha512-Uw5ooOQxRASHgu6C7GVvUxisKXfSgW4oFlO+aa+PAkgmH89O3CXxEEzNRNtHSqtXFTl0nAC1uYj0GMSH27uwtQ==" }, "node_modules/vscode-uri": { - "version": "3.0.6", - "resolved": "https://registry.npmjs.org/vscode-uri/-/vscode-uri-3.0.6.tgz", - "integrity": "sha512-fmL7V1eiDBFRRnu+gfRWTzyPpNIHJTc4mWnFkwBUmO9U3KPgJAmTx7oxi2bl/Rh6HLdU7+4C9wlj0k2E4AdKFQ==" + "version": "3.0.7", + "resolved": "https://registry.npmjs.org/vscode-uri/-/vscode-uri-3.0.7.tgz", + "integrity": "sha512-eOpPHogvorZRobNqJGhapa0JdwaxpjVvyBp0QIUMRMSf8ZAlqOdEquKuRmw9Qwu0qXtJIWqFtMkmvJjUZmMjVA==" }, "node_modules/wcwidth": { "version": "1.0.1", @@ -22393,28 +22440,32 @@ "name": "@example/minimal", "version": "0.0.1", "dependencies": { - "@astrojs/node": "^3.1.0", + "@astrojs/prefetch": "^0.1.1", "@astrojs/tailwind": "^2.1.3", "@docsearch/js": "^3.3.0", "@docsearch/react": "^3.3.0", "@vercel/og": "^0.0.21", - "astro": "^1.6.14", + "astro": "^1.6.15", "classnames": "^2.3.2", "color": "^4.2.3", "cookie": "^0.5.0", "lodash.get": "^4.4.2", "mdx-bundler": "^9.0.1", + "medium-zoom": "^1.0.8", "nanostores": "^0.7.1", "querystring": "^0.2.1", + "request-ip": "^3.3.0", "tailwindcss": "^3.2.4", "zod": "^3.19.1" }, "devDependencies": { + "@astrojs/node": "^3.1.1", "@astrojs/react": "^1.2.2", - "@astrojs/vercel": "^2.3.5", + "@astrojs/vercel": "^2.3.6", "@tailwindcss/typography": "^0.5.8", "@types/classnames": "^2.3.1", "@types/color": "^3.0.3", + "@types/request-ip": "^0.0.37", "react": "^18.2.0", "react-dom": "^18.2.0", "typescript": "^4.9.4" @@ -22594,9 +22645,9 @@ } }, "@astrojs/compiler": { - "version": "0.30.1", - "resolved": "https://registry.npmjs.org/@astrojs/compiler/-/compiler-0.30.1.tgz", - "integrity": "sha512-sH3hvGA9JR5eE2bHG3sr5QjaJl5ER9EmmZzSwBHkMPoBj0XU7XzQjSGoyCbIML6sSaelJEPnfsr9NsypvKOecg==" + "version": "0.31.0", + "resolved": "https://registry.npmjs.org/@astrojs/compiler/-/compiler-0.31.0.tgz", + "integrity": "sha512-V8/Re/wXgXTZzpfWs4KZBLU5dRhnO6kSd4e3vObGuj+HFGHjaD11wws1zvaC9cXLQyQsM5CSrGagFGYlRZKvVQ==" }, "@astrojs/language-server": { "version": "0.28.3", @@ -22665,14 +22716,23 @@ } }, "@astrojs/node": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/@astrojs/node/-/node-3.1.0.tgz", - "integrity": "sha512-teKbDU3u1BIhh3pIVtLsBF/Hxr6NioInfnVFLlPp9afFFlVhakO3N+nR8fPkXrpNXGP3AxQmk+ROI4YHvhIIFw==", + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/@astrojs/node/-/node-3.1.1.tgz", + "integrity": "sha512-EWfsvCtOGvN1ugpxhiW4sr0xD8xUGltFOcU/ysOHdVpP6WXWQUTZbYbqDo+fgYhYHksLIcBLxg8vLi+gBQMA1Q==", + "dev": true, "requires": { "@astrojs/webapi": "^1.1.1", "send": "^0.18.0" } }, + "@astrojs/prefetch": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/@astrojs/prefetch/-/prefetch-0.1.1.tgz", + "integrity": "sha512-+XZcjivPHTo9thQshDWKnnORHJ1dE6odIzhmKHac2ptwla092eohkiJw7Y31+PYmuJkc3Jp+3AawuCvfqCnQ2Q==", + "requires": { + "throttles": "^1.0.1" + } + }, "@astrojs/prism": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/@astrojs/prism/-/prism-1.0.2.tgz", @@ -22717,9 +22777,9 @@ } }, "@astrojs/vercel": { - "version": "2.3.5", - "resolved": "https://registry.npmjs.org/@astrojs/vercel/-/vercel-2.3.5.tgz", - "integrity": "sha512-kjbIKsbaHX41llEV2Qzj9/R8SfYjy/gNG6CdVATuQM1GGBayEvJYn7pU75YalrvLTrqfMKywS+oFPW9fwJl8yA==", + "version": "2.3.6", + "resolved": "https://registry.npmjs.org/@astrojs/vercel/-/vercel-2.3.6.tgz", + "integrity": "sha512-OAfu1d6pgzhKIi48rAKemfhNO6s8ZF/38zSRqGZwl9HnY5qfacccqWmoVeUJ9lSqB/rljxA5Xzh3s+jMqyd9mA==", "dev": true, "requires": { "@astrojs/webapi": "^1.1.1", @@ -24574,26 +24634,30 @@ "@example/minimal": { "version": "file:website-v3", "requires": { - "@astrojs/node": "^3.1.0", + "@astrojs/node": "^3.1.1", + "@astrojs/prefetch": "^0.1.1", "@astrojs/react": "^1.2.2", "@astrojs/tailwind": "^2.1.3", - "@astrojs/vercel": "*", + "@astrojs/vercel": "^2.3.6", "@docsearch/js": "^3.3.0", "@docsearch/react": "^3.3.0", "@tailwindcss/typography": "^0.5.8", "@types/classnames": "^2.3.1", "@types/color": "^3.0.3", + "@types/request-ip": "*", "@vercel/og": "^0.0.21", - "astro": "^1.6.14", + "astro": "^1.6.15", "classnames": "^2.3.2", "color": "^4.2.3", "cookie": "^0.5.0", "lodash.get": "^4.4.2", "mdx-bundler": "^9.0.1", + "medium-zoom": "^1.0.8", "nanostores": "^0.7.1", "querystring": "^0.2.1", "react": "^18.2.0", "react-dom": "^18.2.0", + "request-ip": "^3.3.0", "tailwindcss": "^3.2.4", "typescript": "^4.9.4", "zod": "^3.19.1" @@ -26496,6 +26560,15 @@ "@types/react": "*" } }, + "@types/request-ip": { + "version": "0.0.37", + "resolved": "https://registry.npmjs.org/@types/request-ip/-/request-ip-0.0.37.tgz", + "integrity": "sha512-uw6/i3rQnpznxD7LtLaeuZytLhKZK6bRoTS6XVJlwxIOoOpEBU7bgKoVXDNtOg4Xl6riUKHa9bjMVrL6ESqYlQ==", + "dev": true, + "requires": { + "@types/node": "*" + } + }, "@types/resolve": { "version": "1.20.2", "resolved": "https://registry.npmjs.org/@types/resolve/-/resolve-1.20.2.tgz", @@ -27416,11 +27489,11 @@ "integrity": "sha512-sRpyiNrx2dEYIMmUXprS8nlpRg2Drs8m9ElX9vVEXaCB4XEAJhKfs7IcX0IwShjuOAjLR6wzIrgoptz1n19i1A==" }, "astro": { - "version": "1.6.14", - "resolved": "https://registry.npmjs.org/astro/-/astro-1.6.14.tgz", - "integrity": "sha512-8ljrWPKEU5Hrrbupan48ba4gLWPY14Aqiv4u0U92wSl3wtsqPJUWWlHGGkXcgS/9dx8aiLkUm4RzCPFVnP7V2w==", + "version": "1.6.15", + "resolved": "https://registry.npmjs.org/astro/-/astro-1.6.15.tgz", + "integrity": "sha512-FT60PalffV0bCNxqEHadRzb+Rd3g3lYxV3fR9+bZ2CRlbSfC3UdoaLDh5wC6gJiz91caH1R0XiYaV0WT2Zg91g==", "requires": { - "@astrojs/compiler": "^0.30.0", + "@astrojs/compiler": "^0.31.0", "@astrojs/language-server": "^0.28.3", "@astrojs/markdown-remark": "^1.1.3", "@astrojs/telemetry": "^1.0.1", @@ -27452,7 +27525,7 @@ "html-escaper": "^3.0.3", "import-meta-resolve": "^2.1.0", "kleur": "^4.1.4", - "magic-string": "^0.25.9", + "magic-string": "^0.27.0", "mime": "^3.0.0", "ora": "^6.1.0", "path-browserify": "^1.0.1", @@ -27482,10 +27555,18 @@ "zod": "^3.17.3" }, "dependencies": { + "magic-string": { + "version": "0.27.0", + "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.27.0.tgz", + "integrity": "sha512-8UnnX2PeRAPZuN12svgR9j7M1uWMovg/CEnIwIG0LFkXSJJe4PdfUGiTGl8V9bsBHFUtfVINcSyYxd7q+kx9fA==", + "requires": { + "@jridgewell/sourcemap-codec": "^1.4.13" + } + }, "semver": { - "version": "7.3.7", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.7.tgz", - "integrity": "sha512-QlYTucUYOews+WeEujDoEGziz4K6c47V/Bd+LjSSYcA94p+DmINdf7ncaUinThfvZyu13lN9OY1XDxt8C0Tw0g==", + "version": "7.3.8", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.8.tgz", + "integrity": "sha512-NB1ctGL5rlHrPJtFDVIVzTyQylMLu9N9VICA6HSFJo8MCGVTMW6gfpicwKmmK/dAjTOrqu5l63JJOpDSrAis3A==", "requires": { "lru-cache": "^6.0.0" } @@ -31005,19 +31086,19 @@ }, "dependencies": { "comma-separated-tokens": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/comma-separated-tokens/-/comma-separated-tokens-2.0.2.tgz", - "integrity": "sha512-G5yTt3KQN4Yn7Yk4ed73hlZ1evrFKXeUW3086p3PRFNp7m2vIjI6Pg+Kgb+oyzhd9F2qdcoj67+y3SdxL5XWsg==" + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/comma-separated-tokens/-/comma-separated-tokens-2.0.3.tgz", + "integrity": "sha512-Fu4hJdvzeylCfQPp9SGWidpzrMs7tTrlu6Vb8XGaRGck8QSNZJJp538Wrb60Lax4fPwR64ViY468OIUTbRlGZg==" }, "property-information": { - "version": "6.1.1", - "resolved": "https://registry.npmjs.org/property-information/-/property-information-6.1.1.tgz", - "integrity": "sha512-hrzC564QIl0r0vy4l6MvRLhafmUowhO/O3KgVSoXIbbA2Sz4j8HGpJc6T2cubRVwMwpdiG/vKGfhT4IixmKN9w==" + "version": "6.2.0", + "resolved": "https://registry.npmjs.org/property-information/-/property-information-6.2.0.tgz", + "integrity": "sha512-kma4U7AFCTwpqq5twzC1YVIDXSqg6qQK6JN0smOw8fgRy1OkMi0CYSzFmsy6dnqSenamAtj0CyXMUJ1Mf6oROg==" }, "space-separated-tokens": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/space-separated-tokens/-/space-separated-tokens-2.0.1.tgz", - "integrity": "sha512-ekwEbFp5aqSPKaqeY1PGrlGQxPNaq+Cnx4+bE2D8sciBQrHpbwoBbawqTN2+6jPs9IdWxxiUcN0K2pkczD3zmw==" + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/space-separated-tokens/-/space-separated-tokens-2.0.2.tgz", + "integrity": "sha512-PEGlAwrG8yXGXRjW32fGbg66JAlOAwbObuqVoJpv/mRgoWDQfgH1wDPvtzWyUSNAXBGSk8h755YDbbcEy3SH2Q==" } } }, @@ -31100,9 +31181,9 @@ } }, "zwitch": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/zwitch/-/zwitch-2.0.2.tgz", - "integrity": "sha512-JZxotl7SxAJH0j7dN4pxsTV6ZLXoLdGME+PsjkL/DaBrVryK9kTGq06GfKrwcSOqypP+fdXGoCHE36b99fWVoA==" + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/zwitch/-/zwitch-2.0.4.tgz", + "integrity": "sha512-bXE4cR/kVZhKZX/RjPEflHaKVhUVl85noU3v6b8apfQEc1x4A+zBxjZ4lN8LqGd6WZ3dl98pY4o717VFmoPp+A==" } } }, @@ -31147,9 +31228,9 @@ }, "dependencies": { "comma-separated-tokens": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/comma-separated-tokens/-/comma-separated-tokens-2.0.2.tgz", - "integrity": "sha512-G5yTt3KQN4Yn7Yk4ed73hlZ1evrFKXeUW3086p3PRFNp7m2vIjI6Pg+Kgb+oyzhd9F2qdcoj67+y3SdxL5XWsg==" + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/comma-separated-tokens/-/comma-separated-tokens-2.0.3.tgz", + "integrity": "sha512-Fu4hJdvzeylCfQPp9SGWidpzrMs7tTrlu6Vb8XGaRGck8QSNZJJp538Wrb60Lax4fPwR64ViY468OIUTbRlGZg==" }, "hast-util-whitespace": { "version": "2.0.0", @@ -31157,14 +31238,14 @@ "integrity": "sha512-Pkw+xBHuV6xFeJprJe2BBEoDV+AvQySaz3pPDRUs5PNZEMQjpXJJueqrpcHIXxnWTcAGi/UOCgVShlkY6kLoqg==" }, "property-information": { - "version": "6.1.1", - "resolved": "https://registry.npmjs.org/property-information/-/property-information-6.1.1.tgz", - "integrity": "sha512-hrzC564QIl0r0vy4l6MvRLhafmUowhO/O3KgVSoXIbbA2Sz4j8HGpJc6T2cubRVwMwpdiG/vKGfhT4IixmKN9w==" + "version": "6.2.0", + "resolved": "https://registry.npmjs.org/property-information/-/property-information-6.2.0.tgz", + "integrity": "sha512-kma4U7AFCTwpqq5twzC1YVIDXSqg6qQK6JN0smOw8fgRy1OkMi0CYSzFmsy6dnqSenamAtj0CyXMUJ1Mf6oROg==" }, "space-separated-tokens": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/space-separated-tokens/-/space-separated-tokens-2.0.1.tgz", - "integrity": "sha512-ekwEbFp5aqSPKaqeY1PGrlGQxPNaq+Cnx4+bE2D8sciBQrHpbwoBbawqTN2+6jPs9IdWxxiUcN0K2pkczD3zmw==" + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/space-separated-tokens/-/space-separated-tokens-2.0.2.tgz", + "integrity": "sha512-PEGlAwrG8yXGXRjW32fGbg66JAlOAwbObuqVoJpv/mRgoWDQfgH1wDPvtzWyUSNAXBGSk8h755YDbbcEy3SH2Q==" } } }, @@ -31182,14 +31263,14 @@ }, "dependencies": { "property-information": { - "version": "6.1.1", - "resolved": "https://registry.npmjs.org/property-information/-/property-information-6.1.1.tgz", - "integrity": "sha512-hrzC564QIl0r0vy4l6MvRLhafmUowhO/O3KgVSoXIbbA2Sz4j8HGpJc6T2cubRVwMwpdiG/vKGfhT4IixmKN9w==" + "version": "6.2.0", + "resolved": "https://registry.npmjs.org/property-information/-/property-information-6.2.0.tgz", + "integrity": "sha512-kma4U7AFCTwpqq5twzC1YVIDXSqg6qQK6JN0smOw8fgRy1OkMi0CYSzFmsy6dnqSenamAtj0CyXMUJ1Mf6oROg==" }, "zwitch": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/zwitch/-/zwitch-2.0.2.tgz", - "integrity": "sha512-JZxotl7SxAJH0j7dN4pxsTV6ZLXoLdGME+PsjkL/DaBrVryK9kTGq06GfKrwcSOqypP+fdXGoCHE36b99fWVoA==" + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/zwitch/-/zwitch-2.0.4.tgz", + "integrity": "sha512-bXE4cR/kVZhKZX/RjPEflHaKVhUVl85noU3v6b8apfQEc1x4A+zBxjZ4lN8LqGd6WZ3dl98pY4o717VFmoPp+A==" } } }, @@ -32936,6 +33017,11 @@ "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", "integrity": "sha512-dq+qelQ9akHpcOl/gUVRTxVIOkAJ1wR3QAvb4RsVjS8oVoFjDGTc679wJYmUmknUF5HwMLOgb5O+a3KxfWapPQ==" }, + "medium-zoom": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/medium-zoom/-/medium-zoom-1.0.8.tgz", + "integrity": "sha512-CjFVuFq/IfrdqesAXfg+hzlDKu6A2n80ZIq0Kl9kWjoHh9j1N9Uvk5X0/MmN0hOfm5F9YBswlClhcwnmtwz7gA==" + }, "merge-descriptors": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz", @@ -35390,6 +35476,11 @@ "integrity": "sha512-PV0dzCYDNfRi1jCDbJzpW7jNNDRuCOG/jI5ctQcGKt/clZD+YcPS3yIlWuTJMmESC8aevCFmWJy5wjAFgNqN6w==", "dev": true }, + "request-ip": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/request-ip/-/request-ip-3.3.0.tgz", + "integrity": "sha512-cA6Xh6e0fDBBBwH77SLJaJPBmD3nWVAcF9/XAcsrIHdjhFzFiB5aNQFytdjCGPezU3ROwrR11IddKAM08vohxA==" + }, "require-directory": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", @@ -36779,6 +36870,11 @@ "integrity": "sha512-N+8UisAXDGk8PFXP4HAzVR9nbfmVJ3zYLAWiTIoqC5v5isinhr+r5uaO8+7r3BMfuNIufIsA7RdpVgacC2cSpw==", "dev": true }, + "throttles": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/throttles/-/throttles-1.0.1.tgz", + "integrity": "sha512-fab7Xg+zELr9KOv4fkaBoe/b3L0GMGLd0IBSCn16GoE/Qx6/OfCr1eGNyEcDU2pUA79qQfZ8kPQWlRuok4YwTw==" + }, "through": { "version": "2.3.8", "resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz", @@ -37951,9 +38047,9 @@ "integrity": "sha512-Uw5ooOQxRASHgu6C7GVvUxisKXfSgW4oFlO+aa+PAkgmH89O3CXxEEzNRNtHSqtXFTl0nAC1uYj0GMSH27uwtQ==" }, "vscode-uri": { - "version": "3.0.6", - "resolved": "https://registry.npmjs.org/vscode-uri/-/vscode-uri-3.0.6.tgz", - "integrity": "sha512-fmL7V1eiDBFRRnu+gfRWTzyPpNIHJTc4mWnFkwBUmO9U3KPgJAmTx7oxi2bl/Rh6HLdU7+4C9wlj0k2E4AdKFQ==" + "version": "3.0.7", + "resolved": "https://registry.npmjs.org/vscode-uri/-/vscode-uri-3.0.7.tgz", + "integrity": "sha512-eOpPHogvorZRobNqJGhapa0JdwaxpjVvyBp0QIUMRMSf8ZAlqOdEquKuRmw9Qwu0qXtJIWqFtMkmvJjUZmMjVA==" }, "wcwidth": { "version": "1.0.1", diff --git a/website-v3/package.json b/website-v3/package.json index 0ddcb734..9cb02ec7 100644 --- a/website-v3/package.json +++ b/website-v3/package.json @@ -11,8 +11,8 @@ "astro": "astro" }, "dependencies": { - "@astrojs/tailwind": "^2.1.3", "@astrojs/prefetch": "^0.1.1", + "@astrojs/tailwind": "^2.1.3", "@docsearch/js": "^3.3.0", "@docsearch/react": "^3.3.0", "@vercel/og": "^0.0.21", @@ -22,8 +22,10 @@ "cookie": "^0.5.0", "lodash.get": "^4.4.2", "mdx-bundler": "^9.0.1", + "medium-zoom": "^1.0.8", "nanostores": "^0.7.1", "querystring": "^0.2.1", + "request-ip": "^3.3.0", "tailwindcss": "^3.2.4", "zod": "^3.19.1" }, @@ -34,6 +36,7 @@ "@tailwindcss/typography": "^0.5.8", "@types/classnames": "^2.3.1", "@types/color": "^3.0.3", + "@types/request-ip": "^0.0.37", "react": "^18.2.0", "react-dom": "^18.2.0", "typescript": "^4.9.4" diff --git a/website-v3/src/components/Markdown.tsx b/website-v3/src/components/Markdown.tsx index 50210284..fc433001 100644 --- a/website-v3/src/components/Markdown.tsx +++ b/website-v3/src/components/Markdown.tsx @@ -2,11 +2,16 @@ import { getMDXComponent } from 'mdx-bundler/client/index.js'; import context from 'src/context'; import Link from './Link'; +import CodeBlock, { CodeBlockProps } from './mdx/CodeBlock'; import Image from './mdx/Image'; import YouTube from './mdx/YouTube'; import Vimeo from './mdx/Vimeo'; import Table from './mdx/Table'; import Heading from './mdx/Heading'; +import Tweet from './mdx/Tweet'; +import Zapp from './mdx/Zapp'; +import * as callouts from './mdx/callouts'; +import Tabs, { TabItem } from './mdx/Tabs'; const Markdown: React.FC = () => { const code = context.get().code; @@ -19,6 +24,7 @@ const Markdown: React.FC = () => { a: props => , img: props => , table: props => , + pre: props => , code: props => , h1: props => , h2: props => , @@ -26,13 +32,18 @@ const Markdown: React.FC = () => { h4: props => , h5: props => , h6: props => , + Info: props => {props.children}, + Warning: props => {props.children}, + Error: props => {props.children}, + Success: props => {props.children}, Heading, - Tweet: props =>
TODO
, - Tabs: props =>
TODO
, - TabItem: props =>
TODO
, + Tweet: props => , + Tabs: props => , + TabItem: props => , Image, YouTube, Vimeo, + Zapp, }} /> diff --git a/website-v3/src/components/Scripts.astro b/website-v3/src/components/Scripts.astro index c601bc21..4e96a8fc 100644 --- a/website-v3/src/components/Scripts.astro +++ b/website-v3/src/components/Scripts.astro @@ -1,9 +1,156 @@ --- import context from 'src/context'; -const { domain, config } = context.get(); +const ctx = context.get(); +const { config, domain } = ctx; --- + + + + + + + + + { config.googleAnalytics && ( diff --git a/website-v3/src/components/Styles.astro b/website-v3/src/components/Styles.astro new file mode 100644 index 00000000..44efd502 --- /dev/null +++ b/website-v3/src/components/Styles.astro @@ -0,0 +1,14 @@ + diff --git a/website-v3/src/components/ThemeToggle.astro b/website-v3/src/components/ThemeToggle.astro index fb3c8a41..db89c1d7 100644 --- a/website-v3/src/components/ThemeToggle.astro +++ b/website-v3/src/components/ThemeToggle.astro @@ -1,21 +1,20 @@ --- -import context from 'src/context'; import { MoonIcon, SunIcon } from './icons'; - -const { owner, repository, domain } = context.get(); --- - + diff --git a/website-v3/src/plausible.ts b/website-v3/src/plausible.ts new file mode 100644 index 00000000..418d8416 --- /dev/null +++ b/website-v3/src/plausible.ts @@ -0,0 +1,22 @@ +import { getClientIp } from 'request-ip'; + +export async function trackPageRequest(request: Request): Promise { + try { + await fetch(`https://plausible.io/api/event`, { + method: 'POST', + headers: new Headers({ + 'Content-Type': 'application/json', + 'User-Agent': request.headers.get('User-Agent') || '', + // @ts-expect-error - request-ip types use none-generic Request + 'X-Forwarded-For': getClientIp(request) ?? '', + }), + body: JSON.stringify({ + name: 'pageview', + url: request.url, + domain: 'docs.page', + }), + }); + } catch (e) { + console.error('Failed to track page request', e); + } +}