Skip to content

Commit

Permalink
wip: MDX extension
Browse files Browse the repository at this point in the history
  • Loading branch information
areknawo committed Oct 8, 2023
1 parent e71963d commit 4fe65cd
Show file tree
Hide file tree
Showing 9 changed files with 5,266 additions and 5,296 deletions.
9 changes: 9 additions & 0 deletions apps/backend/extensions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@
"@vrite/backend": "workspace:*",
"@vrite/sdk": "workspace:*",
"fastify": "^4.20.0",
"hast-util-to-html": "^9.0.0",
"mdast-util-from-markdown": "^2.0.0",
"mdast-util-frontmatter": "^2.0.1",
"mdast-util-gfm": "^3.0.0",
"mdast-util-mdx": "^3.0.0",
"mdast-util-to-hast": "^13.0.2",
"micromark-extension-frontmatter": "^2.0.0",
"micromark-extension-gfm": "^3.0.0",
"micromark-extension-mdxjs": "^2.0.0",
"openai": "^4.0.0",
"remark": "^15.0.1",
"remark-mdx": "^2.3.0",
Expand Down
23 changes: 0 additions & 23 deletions apps/backend/extensions/src/routes/docusaurus/input-transformer.ts

This file was deleted.

4 changes: 2 additions & 2 deletions apps/backend/extensions/src/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import { devRouter } from "./dev";
import { hashnodeRouter } from "./hashnode";
import { gptRouter } from "./gpt";
import { mediumRouter } from "./medium";
import { docusaurusRouter } from "./docusaurus";
import { mdxRouter } from "./mdx";
import { router } from "@vrite/backend";

const extensionsRouter = router({
dev: devRouter,
hashnode: hashnodeRouter,
medium: mediumRouter,
gpt: gptRouter,
docusaurus: docusaurusRouter
mdx: mdxRouter
});

type Router = typeof extensionsRouter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { docusaurusInputTransformer } from "./input-transformer";
import { mdxInputTransformer } from "./input-transformer";
import { procedure, router, z } from "@vrite/backend";
import { OpenAI } from "openai";

// test
docusaurusInputTransformer("");
mdxInputTransformer("");

const basePath = "/docusaurus";
const docusaurusRouter = router({
const mdxRouter = router({
prompt: procedure
.meta({
openapi: {
Expand Down Expand Up @@ -47,4 +47,4 @@ const docusaurusRouter = router({
})
});

export { docusaurusRouter };
export { mdxRouter };
31 changes: 31 additions & 0 deletions apps/backend/extensions/src/routes/mdx/input-transformer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { createInputTransformer } from "@vrite/sdk/transformers";
import { mdxjs } from "micromark-extension-mdxjs";
import { fromMarkdown } from "mdast-util-from-markdown";
import { mdxFromMarkdown } from "mdast-util-mdx";
import { frontmatter } from "micromark-extension-frontmatter";
import { frontmatterFromMarkdown } from "mdast-util-frontmatter";
import { gfmFromMarkdown } from "mdast-util-gfm";
import { gfm } from "micromark-extension-gfm";
import { toHtml } from "hast-util-to-html";
import { toHast } from "mdast-util-to-hast";

import fs from "node:fs";
import path from "node:path";

const mdxInputTransformer = createInputTransformer(() => {
const doc = fs.readFileSync(path.join(__dirname, "test.mdx"), "utf8");
const tree = fromMarkdown(doc, {
extensions: [gfm(), frontmatter(), mdxjs()],
mdastExtensions: [gfmFromMarkdown(), frontmatterFromMarkdown(), mdxFromMarkdown()]
});
const hast = toHast(tree, { handlers: {} });
const html = toHtml(hast);

console.log(tree, html);

return {
content: ""
};
});

export { mdxInputTransformer };
1 change: 1 addition & 0 deletions apps/docs/.astro/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ declare module 'astro:content' {
import('astro/zod').ZodLiteral<'webp'>,
import('astro/zod').ZodLiteral<'gif'>,
import('astro/zod').ZodLiteral<'svg'>,
import('astro/zod').ZodLiteral<'avif'>,
]
>;
}>;
Expand Down
5 changes: 3 additions & 2 deletions apps/web/public/sandbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -945,9 +945,9 @@
}
});

// ../../node_modules/.pnpm/@[email protected].0/node_modules/@sanity/eventsource/browser.js
// ../../node_modules/.pnpm/@[email protected].1/node_modules/@sanity/eventsource/browser.js
var require_browser = __commonJS({
"../../node_modules/.pnpm/@[email protected].0/node_modules/@sanity/eventsource/browser.js"(exports, module) {
"../../node_modules/.pnpm/@[email protected].1/node_modules/@sanity/eventsource/browser.js"(exports, module) {
module.exports = require_eventsource().EventSourcePolyfill;
}
});
Expand Down Expand Up @@ -1001,6 +1001,7 @@
var import_eventsource, i, w, $, U, f, g, L, d, S, D, O, E, R, C, x, m, I, h, j, v, k, q, l, A, u, z, B;
var init_api = __esm({
"../../packages/sdk/javascript/dist/api.mjs"() {
"use strict";
import_eventsource = __toESM(require_browser(), 1);
i = "/content-groups";
w = (t) => ({ get: (e) => t("GET", `${i}`, { params: e }), list: (e) => t("GET", `${i}/list`, { params: e }), create: (e) => t("POST", `${i}`, { body: e }), update: (e) => t("PUT", `${i}`, { body: e }), delete: (e) => t("DELETE", `${i}`, { params: e }) });
Expand Down
1 change: 1 addition & 0 deletions packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"@vrite/sdk": "workspace:*",
"axios": "^1.4.0",
"fastify": "^4.20.0",
"graphql": "^16.8.1",
"html-to-text": "^9.0.5",
"lexorank": "^1.0.5",
"marked": "^5.1.2",
Expand Down
Loading

0 comments on commit 4fe65cd

Please sign in to comment.