Skip to content

Commit 7ee038f

Browse files
authored
Merge pull request #1 from pheralb/next
Preview
2 parents df631bf + 54397ac commit 7ee038f

144 files changed

Lines changed: 10264 additions & 3689 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
13
# dependencies
24
/node_modules
35
/.pnp

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
save-exact=true

.vscode/extensions.json

Lines changed: 0 additions & 9 deletions
This file was deleted.

.vscode/settings.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
11
{
2-
"tailwindCSS.experimental.classRegex": [
3-
["cva\\(((?:[^()]|\\([^()]*\\))*)\\)", "[\"'`]([^\"'`]*).*?[\"'`]"],
4-
["cn\\(((?:[^()]|\\([^()]*\\))*)\\)", "(?:'|\"|`)([^']*)(?:'|\"|`)"]
5-
]
2+
"tailwindCSS.classFunctions": ["cva", "cx"]
63
}

components.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,24 @@
33
"style": "new-york",
44
"rsc": true,
55
"tsx": true,
6-
"iconLibrary": "lucide",
76
"tailwind": {
8-
"config": "tailwind.config.ts",
9-
"css": "styles/globals.css",
7+
"config": "",
8+
"css": "src/styles/globals.css",
109
"baseColor": "neutral",
1110
"cssVariables": false,
1211
"prefix": ""
1312
},
13+
"iconLibrary": "lucide",
1414
"aliases": {
1515
"components": "@/components",
1616
"utils": "@/utils",
1717
"ui": "@/components/ui",
1818
"lib": "@/lib",
1919
"hooks": "@/hooks"
20+
},
21+
"registries": {
22+
"@magicui": "https://magicui.design/r/{name}.json",
23+
"@tailark": "https://tailark.com/r/{name}.json",
24+
"@svgl": "https://svgl.app/r/{name}.json"
2025
}
2126
}

content-collections.ts

Lines changed: 94 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1,110 +1,107 @@
1-
import { defineCollection, defineConfig } from "@content-collections/core";
2-
import { compileMDX } from "@content-collections/mdx";
3-
import path from "node:path";
4-
import fs from "node:fs/promises";
1+
import { z } from "zod";
52

6-
// MDX Plugins:
73
import {
8-
remarkGfm,
9-
remarkHeading,
10-
remarkStructure,
11-
} from "fumadocs-core/mdx-plugins";
12-
import GithubSlugger from "github-slugger";
4+
defineCollection,
5+
defineConfig,
6+
type Context,
7+
type Document,
8+
} from "@content-collections/core";
9+
10+
// Plugins:
11+
import remarkGfm from "remark-gfm";
12+
import rehypeSlug from "rehype-slug";
13+
import rehypeShiki from "@shikijs/rehype/core";
14+
15+
import { compileMDX } from "@content-collections/mdx";
1316
import rehypeAutolinkHeadings from "rehype-autolink-headings";
14-
import { visit } from "unist-util-visit";
15-
import rehypeShiki, { type RehypeShikiOptions } from "@shikijs/rehype";
16-
import { rehypeComponent } from "./src/mdx/rehypeComponent";
1717

18-
// Domain:
19-
const domain = "codeblocks.pheralb.dev";
18+
import { highlight } from "./src/utils/shiki";
19+
import { rehypeShikiOptions } from "./src/mdx/plugins/rehypeShiki";
20+
import { getTableOfContents } from "./src/mdx/plugins/generateToC";
21+
import { rehypeComponent } from "./src/mdx/plugins/rehypeComponent";
22+
import { rehypeReactDoc } from "./src/mdx/plugins/rehypeReactDoc";
23+
import { HEADING_LINK_ANCHOR } from "./src/components/ui/headings";
24+
25+
// Schema:
26+
const docSchema = z.object({
27+
title: z.string(),
28+
description: z.string(),
29+
category: z.string(),
30+
content: z.string(),
31+
});
32+
33+
type DocSchema = z.infer<typeof docSchema>;
34+
type DocsDocument = Document & DocSchema;
2035

21-
// Shiki Options:
22-
const shikiOptions: RehypeShikiOptions = {
23-
themes: {
24-
light: "github-light",
25-
dark: "github-dark",
26-
},
27-
transformers: [
28-
{
29-
name: "AddPreProperties",
30-
pre(node) {
31-
node.properties["data-language"] = this.options.lang || "plaintext";
32-
node.properties["data-code"] = this.source;
33-
},
34-
},
35-
{
36-
name: "WordWrap",
37-
pre(node) {
38-
node.properties["style"] = "white-space: pre-wrap;";
39-
},
40-
},
41-
],
36+
// Transform:
37+
const docTransform = async (
38+
folder: string,
39+
document: DocsDocument,
40+
context: Context,
41+
) => {
42+
const highlighter = await highlight();
43+
const tableOfContents = getTableOfContents(document.content);
44+
const mdx = await compileMDX(context, document, {
45+
remarkPlugins: [remarkGfm],
46+
rehypePlugins: [
47+
rehypeComponent,
48+
rehypeSlug,
49+
[
50+
rehypeAutolinkHeadings,
51+
{
52+
behavior: "wrap",
53+
properties: {
54+
className: [HEADING_LINK_ANCHOR],
55+
},
56+
},
57+
],
58+
rehypeReactDoc,
59+
[rehypeShiki, highlighter, rehypeShikiOptions],
60+
],
61+
});
62+
return {
63+
...document,
64+
folder,
65+
tableOfContents,
66+
mdx,
67+
};
4268
};
4369

44-
// Docs Collection:
45-
const docs = defineCollection({
46-
name: "docs",
70+
// Collections:
71+
const generalDocs = defineCollection({
72+
name: "general",
4773
directory: "src/docs",
4874
include: "**/*.mdx",
49-
schema: (z) => ({
50-
title: z.string(),
51-
description: z.string(),
52-
category: z.string(),
53-
}),
54-
transform: async (document, context) => {
55-
const filePath = path.join(
56-
context.collection.directory,
57-
document._meta.filePath,
58-
);
59-
const { mtimeMs, birthtimeMs } = await fs.stat(filePath);
60-
const mdx = await compileMDX(context, document, {
61-
remarkPlugins: [remarkGfm, remarkHeading, remarkStructure],
62-
rehypePlugins: [
63-
// Rehype Component:
64-
rehypeComponent,
65-
// Shiki Syntax Highlighting:
66-
[rehypeShiki, shikiOptions],
67-
// Open External Links in New Tab:
68-
() => (tree) => {
69-
visit(tree, "element", (e) => {
70-
if (
71-
e.tagName === "a" &&
72-
e.properties?.href &&
73-
e.properties.href.toString().startsWith("http") &&
74-
!e.properties.href.toString().includes(domain)
75-
) {
76-
e.properties!["target"] = "_blank";
77-
}
78-
});
79-
},
80-
[rehypeAutolinkHeadings],
81-
],
82-
});
83-
const slugger = new GithubSlugger();
84-
const regXHeader = /(?:^|\n)(?<flag>##+)\s+(?<content>.+)/g;
85-
const tableOfContents = Array.from(
86-
document.content.matchAll(regXHeader),
87-
).map(({ groups }) => {
88-
const flag = groups?.flag;
89-
const content = groups?.content;
90-
return {
91-
level: flag?.length,
92-
text: content,
93-
slug: content ? slugger.slug(content) : undefined,
94-
};
95-
});
96-
return {
97-
...document,
98-
mdx,
99-
slug: document._meta.path,
100-
url: `/${document._meta.path}`,
101-
toc: tableOfContents,
102-
createdAt: new Date(birthtimeMs),
103-
updatedAt: new Date(mtimeMs),
104-
};
105-
},
75+
schema: docSchema,
76+
transform: (document, context) => docTransform("general", document, context),
77+
});
78+
79+
const gstartedDocs = defineCollection({
80+
name: "gstarted",
81+
directory: "src/docs/getting-started",
82+
include: "**/*.mdx",
83+
schema: docSchema,
84+
transform: (document, context) =>
85+
docTransform("getting-started", document, context),
86+
});
87+
88+
const componentsDocs = defineCollection({
89+
name: "components",
90+
directory: "src/docs/components",
91+
include: "**/*.mdx",
92+
schema: docSchema,
93+
transform: (document, context) =>
94+
docTransform("components", document, context),
95+
});
96+
97+
const shikiDocs = defineCollection({
98+
name: "shiki",
99+
directory: "src/docs/shiki",
100+
include: "**/*.mdx",
101+
schema: docSchema,
102+
transform: (document, context) => docTransform("shiki", document, context),
106103
});
107104

108105
export default defineConfig({
109-
collections: [docs],
106+
collections: [generalDocs, gstartedDocs, componentsDocs, shikiDocs],
110107
});

eslint.config.mjs

Lines changed: 0 additions & 28 deletions
This file was deleted.

eslint.config.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { fileURLToPath } from "node:url";
2+
import { includeIgnoreFile } from "@eslint/compat";
3+
import { defineConfig, globalIgnores } from "eslint/config";
4+
5+
// Plugins:
6+
import nextTs from "eslint-config-next/typescript";
7+
import prettier from "eslint-config-prettier/flat";
8+
import nextVitals from "eslint-config-next/core-web-vitals";
9+
10+
// Gitignore:
11+
const gitignorePath = fileURLToPath(new URL(".gitignore", import.meta.url));
12+
13+
const eslintConfig = defineConfig([
14+
includeIgnoreFile(gitignorePath),
15+
globalIgnores([".next/**", "out/**", "build/**", "next-env.d.ts"]),
16+
...nextVitals,
17+
...nextTs,
18+
prettier,
19+
{
20+
rules: {
21+
"@typescript-eslint/no-unused-vars": [
22+
"warn",
23+
{
24+
argsIgnorePattern: "^_",
25+
varsIgnorePattern: "^_",
26+
},
27+
],
28+
},
29+
linterOptions: {
30+
reportUnusedDisableDirectives: "warn",
31+
},
32+
},
33+
]);
34+
35+
export default eslintConfig;

next.config.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,15 @@ import type { NextConfig } from "next";
22
import { withContentCollections } from "@content-collections/next";
33

44
const nextConfig: NextConfig = {
5-
/* config options here */
5+
async redirects() {
6+
return [
7+
{
8+
source: "/docs",
9+
destination: "/docs/getting-started/prerequisites",
10+
permanent: true,
11+
},
12+
];
13+
},
614
};
715

816
export default withContentCollections(nextConfig);

0 commit comments

Comments
 (0)