@farming-labs/next 0.0.2-beta.3 → 0.0.2-beta.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/config.mjs +24 -15
- package/dist/mdx-plugins/remark-og.d.mts +19 -0
- package/dist/mdx-plugins/remark-og.mjs +25 -0
- package/package.json +17 -12
package/dist/config.mjs
CHANGED
|
@@ -23,7 +23,7 @@ import createMDX from "@next/mdx";
|
|
|
23
23
|
const GENERATED_BANNER = "// Auto-generated by @farming-labs/next — do not edit manually.\n";
|
|
24
24
|
const MDX_COMPONENTS_TEMPLATE = `\
|
|
25
25
|
${GENERATED_BANNER}
|
|
26
|
-
import { getMDXComponents } from "@farming-labs/
|
|
26
|
+
import { getMDXComponents } from "@farming-labs/theme/mdx";
|
|
27
27
|
import type { MDXComponents } from "mdx/types";
|
|
28
28
|
import docsConfig from "@/docs.config";
|
|
29
29
|
|
|
@@ -37,16 +37,16 @@ export function useMDXComponents(components?: MDXComponents): MDXComponents {
|
|
|
37
37
|
const DOCS_LAYOUT_TEMPLATE = `\
|
|
38
38
|
${GENERATED_BANNER}
|
|
39
39
|
import docsConfig from "@/docs.config";
|
|
40
|
-
import { createDocsLayout, createDocsMetadata } from "@farming-labs/
|
|
40
|
+
import { createDocsLayout, createDocsMetadata } from "@farming-labs/theme";
|
|
41
41
|
|
|
42
42
|
export const metadata = createDocsMetadata(docsConfig);
|
|
43
43
|
export default createDocsLayout(docsConfig);
|
|
44
44
|
`;
|
|
45
|
-
const
|
|
45
|
+
const DOCS_API_ROUTE_TEMPLATE = `\
|
|
46
46
|
${GENERATED_BANNER}
|
|
47
|
-
import {
|
|
47
|
+
import { createDocsAPI } from "@farming-labs/theme/api";
|
|
48
48
|
|
|
49
|
-
export const { GET } =
|
|
49
|
+
export const { GET, POST } = createDocsAPI();
|
|
50
50
|
|
|
51
51
|
export const revalidate = false;
|
|
52
52
|
`;
|
|
@@ -70,6 +70,16 @@ function readDocsEntry(root) {
|
|
|
70
70
|
}
|
|
71
71
|
return "docs";
|
|
72
72
|
}
|
|
73
|
+
/** Read the OG endpoint from docs.config.ts[x] (returns undefined if not set). */
|
|
74
|
+
function readOgEndpoint(root) {
|
|
75
|
+
for (const ext of FILE_EXTS) {
|
|
76
|
+
const configPath = join(root, `docs.config.${ext}`);
|
|
77
|
+
if (existsSync(configPath)) try {
|
|
78
|
+
const match = readFileSync(configPath, "utf-8").match(/endpoint\s*:\s*["']([^"']+)["']/);
|
|
79
|
+
if (match && match[1]) return match[1];
|
|
80
|
+
} catch {}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
73
83
|
function withDocs(nextConfig = {}) {
|
|
74
84
|
const root = process.cwd();
|
|
75
85
|
if (!hasFile(root, "mdx-components")) writeFileSync(join(root, "mdx-components.tsx"), MDX_COMPONENTS_TEMPLATE);
|
|
@@ -79,20 +89,19 @@ function withDocs(nextConfig = {}) {
|
|
|
79
89
|
mkdirSync(layoutDir, { recursive: true });
|
|
80
90
|
writeFileSync(join(layoutDir, "layout.tsx"), DOCS_LAYOUT_TEMPLATE);
|
|
81
91
|
}
|
|
82
|
-
const
|
|
83
|
-
if (!hasFile(
|
|
84
|
-
mkdirSync(
|
|
85
|
-
writeFileSync(join(
|
|
92
|
+
const docsApiRouteDir = join(root, "app", "api", "docs");
|
|
93
|
+
if (!hasFile(docsApiRouteDir, "route")) {
|
|
94
|
+
mkdirSync(docsApiRouteDir, { recursive: true });
|
|
95
|
+
writeFileSync(join(docsApiRouteDir, "route.ts"), DOCS_API_ROUTE_TEMPLATE);
|
|
86
96
|
}
|
|
97
|
+
const ogEndpoint = readOgEndpoint(root);
|
|
98
|
+
const remarkPlugins = ["remark-gfm", "remark-frontmatter"];
|
|
99
|
+
if (ogEndpoint) remarkPlugins.push(["@farming-labs/next/mdx-plugins/remark-og", { endpoint: ogEndpoint }]);
|
|
100
|
+
remarkPlugins.push(["remark-mdx-frontmatter", { name: "metadata" }], "@farming-labs/next/mdx-plugins/remark-heading");
|
|
87
101
|
const withMDX = createMDX({
|
|
88
102
|
extension: /\.mdx?$/,
|
|
89
103
|
options: {
|
|
90
|
-
remarkPlugins
|
|
91
|
-
"remark-gfm",
|
|
92
|
-
"remark-frontmatter",
|
|
93
|
-
["remark-mdx-frontmatter", { name: "metadata" }],
|
|
94
|
-
"@farming-labs/next/mdx-plugins/remark-heading"
|
|
95
|
-
],
|
|
104
|
+
remarkPlugins,
|
|
96
105
|
rehypePlugins: ["@farming-labs/next/mdx-plugins/rehype-toc", ["@farming-labs/next/mdx-plugins/rehype-code", { themes: {
|
|
97
106
|
dark: "github-dark",
|
|
98
107
|
light: "github-light"
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
//#region src/mdx-plugins/remark-og.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Remark plugin that augments frontmatter with Open Graph metadata.
|
|
4
|
+
*
|
|
5
|
+
* Runs between remark-frontmatter and remark-mdx-frontmatter.
|
|
6
|
+
* Reads title/description from the YAML node and appends openGraph + twitter
|
|
7
|
+
* fields so that remark-mdx-frontmatter exports them as part of `metadata`.
|
|
8
|
+
*/
|
|
9
|
+
interface RemarkOgOptions {
|
|
10
|
+
endpoint?: string;
|
|
11
|
+
}
|
|
12
|
+
declare function remarkOg(options?: RemarkOgOptions): (tree: {
|
|
13
|
+
children: Array<{
|
|
14
|
+
type: string;
|
|
15
|
+
value: string;
|
|
16
|
+
}>;
|
|
17
|
+
}) => void;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { remarkOg as default };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
//#region src/mdx-plugins/remark-og.ts
|
|
2
|
+
function extractField(yaml, key) {
|
|
3
|
+
const re = new RegExp(`^${key}:\\s*(?:"([^"]*?)"|'([^']*?)'|(.+?))\\s*$`, "m");
|
|
4
|
+
const m = yaml.match(re);
|
|
5
|
+
return m?.[1] ?? m?.[2] ?? m?.[3];
|
|
6
|
+
}
|
|
7
|
+
function remarkOg(options = {}) {
|
|
8
|
+
const { endpoint = "/api/og" } = options;
|
|
9
|
+
return (tree) => {
|
|
10
|
+
const yamlNode = tree.children.find((n) => n.type === "yaml");
|
|
11
|
+
if (!yamlNode) return;
|
|
12
|
+
const title = extractField(yamlNode.value, "title");
|
|
13
|
+
if (!title) return;
|
|
14
|
+
const description = extractField(yamlNode.value, "description");
|
|
15
|
+
const params = new URLSearchParams({ title });
|
|
16
|
+
if (description) params.set("description", description);
|
|
17
|
+
const ogUrl = `${endpoint}?${params.toString()}`;
|
|
18
|
+
yamlNode.value += `
|
|
19
|
+
openGraph:
|
|
20
|
+
images:\n - url: "${ogUrl}"\n width: 1200\n height: 630\ntwitter:\n card: "summary_large_image"\n images:\n - "${ogUrl}"`;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
//#endregion
|
|
25
|
+
export { remarkOg as default };
|
package/package.json
CHANGED
|
@@ -1,7 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@farming-labs/next",
|
|
3
|
-
"version": "0.0.2-beta.
|
|
3
|
+
"version": "0.0.2-beta.30",
|
|
4
4
|
"description": "Next.js adapter for @farming-labs/docs — MDX config wrapper",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"docs",
|
|
7
|
+
"documentation",
|
|
8
|
+
"mdx",
|
|
9
|
+
"next"
|
|
10
|
+
],
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"author": "Farming Labs",
|
|
13
|
+
"files": [
|
|
14
|
+
"dist"
|
|
15
|
+
],
|
|
5
16
|
"type": "module",
|
|
6
17
|
"main": "./dist/index.mjs",
|
|
7
18
|
"types": "./dist/index.d.mts",
|
|
@@ -30,19 +41,13 @@
|
|
|
30
41
|
"types": "./dist/mdx-plugins/rehype-code.d.mts",
|
|
31
42
|
"import": "./dist/mdx-plugins/rehype-code.mjs",
|
|
32
43
|
"default": "./dist/mdx-plugins/rehype-code.mjs"
|
|
44
|
+
},
|
|
45
|
+
"./mdx-plugins/remark-og": {
|
|
46
|
+
"types": "./dist/mdx-plugins/remark-og.d.mts",
|
|
47
|
+
"import": "./dist/mdx-plugins/remark-og.mjs",
|
|
48
|
+
"default": "./dist/mdx-plugins/remark-og.mjs"
|
|
33
49
|
}
|
|
34
50
|
},
|
|
35
|
-
"files": [
|
|
36
|
-
"dist"
|
|
37
|
-
],
|
|
38
|
-
"keywords": [
|
|
39
|
-
"docs",
|
|
40
|
-
"next",
|
|
41
|
-
"mdx",
|
|
42
|
-
"documentation"
|
|
43
|
-
],
|
|
44
|
-
"author": "Farming Labs",
|
|
45
|
-
"license": "MIT",
|
|
46
51
|
"dependencies": {
|
|
47
52
|
"@mdx-js/loader": "^3.1.0",
|
|
48
53
|
"@mdx-js/react": "^3.1.0",
|