Skip to content

Commit 1b77294

Browse files
committed
feat: sitemap and tests
Signed-off-by: ivelin <[email protected]>
1 parent e055d8a commit 1b77294

File tree

6 files changed

+348
-25
lines changed

6 files changed

+348
-25
lines changed

next-sitemap.config.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// next-sitemap.config.js
2+
// File path: next-sitemap.config.js
3+
// Configures sitemap for K12Beast, including home, public, and documentation pages
4+
// Scans directories for page.tsx and page.mdx files, excluding dynamic routes
5+
6+
const fs = require('fs');
7+
const path = require('path');
8+
9+
const PUBLIC_DIR = path.join(process.cwd(), 'src/app/public');
10+
const DOCS_DIR = path.join(process.cwd(), 'src/content/docs');
11+
12+
function addPaths(dir, prefix, fileName) {
13+
const paths = [];
14+
fs.readdirSync(dir).forEach(file => {
15+
const filePath = path.join(dir, file);
16+
if (fs.statSync(filePath).isDirectory()) {
17+
paths.push(...addPaths(filePath, `${prefix}/${file}`, fileName));
18+
} else if (file === fileName) {
19+
const relativePath = prefix.endsWith('/public') ? '/public' : prefix;
20+
if (!relativePath.includes('[')) {
21+
paths.push({
22+
loc: relativePath,
23+
lastmod: new Date().toISOString(),
24+
});
25+
}
26+
}
27+
});
28+
return paths;
29+
}
30+
31+
module.exports = {
32+
siteUrl: 'https://k12beast.com',
33+
generateRobotsTxt: true,
34+
generateIndexSitemap: false,
35+
additionalPaths: async () => {
36+
const paths = [
37+
{
38+
loc: '/',
39+
lastmod: new Date().toISOString(),
40+
},
41+
];
42+
paths.push(...addPaths(PUBLIC_DIR, '/public', 'page.tsx'));
43+
paths.push(...addPaths(DOCS_DIR, '/public/docs', 'page.mdx'));
44+
return paths;
45+
},
46+
};

next.config.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,45 @@
1+
// next.config.ts
12
// File path: next.config.ts
23
// Configures Next.js for K12Beast, including MDX support for documentation pages
34
// Allows external image domains for testing and Supabase storage URLs
45
// Disables TypeScript build errors and source maps in development
56
// Sets cache control headers for source maps
6-
// Configures MDX to strip comments and frontmatter from rendering, with GFM support for tables
7+
// Configures MDX to strip comments and frontmatter, with GFM support for tables
78

89
import type { NextConfig } from 'next';
910
import createMDX from '@next/mdx';
1011
import remarkFrontmatter from 'remark-frontmatter';
11-
import remarkGfm from 'remark-gfm'; // Added for GFM table support
12+
import remarkGfm from 'remark-gfm';
1213
import remarkRemoveComments from 'remark-remove-comments';
1314
import { remove } from 'unist-util-remove';
1415

1516
// Custom remark plugin to remove frontmatter node from the MDX AST
1617
function remarkRemoveFrontmatter() {
1718
return (tree: any) => {
18-
remove(tree, { type: 'yaml' }); // Remove frontmatter (yaml node)
19+
remove(tree, { type: 'yaml' });
1920
return tree;
2021
};
2122
}
2223

2324
const nextConfig: NextConfig = {
2425
productionBrowserSourceMaps: false,
2526
typescript: {
26-
ignoreBuildErrors: true, // Disable TypeScript errors during build
27+
ignoreBuildErrors: true,
2728
},
2829
images: {
29-
domains: ['mockurl.com'], // For tests
30+
domains: ['mockurl.com'],
3031
remotePatterns: [
3132
{
3233
protocol: 'https',
33-
hostname: '*.supabase.co', // Allow any subdomain of supabase.co
34-
port: '', // Leave empty for default ports (80, 443)
35-
pathname: '/storage/v1/object/public/**', // Match Supabase storage paths
34+
hostname: '*.supabase.co',
35+
port: '',
36+
pathname: '/storage/v1/object/public/**',
3637
},
3738
],
3839
},
3940
webpack: (config, { dev }) => {
4041
if (dev) {
41-
config.devtool = false; // Disable source maps in dev mode
42+
config.devtool = false;
4243
}
4344
return config;
4445
},
@@ -55,18 +56,17 @@ const nextConfig: NextConfig = {
5556
},
5657
];
5758
},
58-
pageExtensions: ['js', 'jsx', 'ts', 'tsx', 'md', 'mdx'], // Enable MDX pages
59+
pageExtensions: ['js', 'jsx', 'ts', 'tsx', 'md', 'mdx'],
5960
};
6061

6162
const withMDX = createMDX({
6263
options: {
6364
remarkPlugins: [
64-
remarkFrontmatter, // Parse frontmatter
65-
remarkRemoveFrontmatter, // Remove frontmatter from rendering
66-
remarkRemoveComments, // Remove comments (e.g., lines starting with //)
67-
remarkGfm, // Enable GitHub Flavored Markdown for table support,
65+
remarkFrontmatter,
66+
remarkRemoveFrontmatter,
67+
remarkRemoveComments,
68+
remarkGfm,
6869
],
69-
// Add rehype plugins here if needed in the future
7070
rehypePlugins: [],
7171
},
7272
});

0 commit comments

Comments
 (0)