File size: 1,341 Bytes
31767a7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import React from 'react';
import { GetStaticProps, GetStaticPaths } from 'next';
import fs from 'fs';
import path from 'path';
import matter from 'gray-matter';
import ReactMarkdown from 'react-markdown';

interface PolicyProps {
  content: string;
}

const PolicyPage: React.FC<PolicyProps> = ({ content }) => {
  return (
    <div className="container mx-auto py-8">
      <ReactMarkdown>{content}</ReactMarkdown>
    </div>
  );
};

export const getStaticPaths: GetStaticPaths = async () => {
  const policiesDir = path.join(process.cwd(), 'content', 'policies');
  const policyFolders = fs.readdirSync(policiesDir);

  const paths = policyFolders.flatMap((folder) => {
    const languageFiles = fs.readdirSync(path.join(policiesDir, folder));
    return languageFiles.map((file) => {
      return { params: { slug: folder, fileName: file } };
    });
  });

  return {
    paths,
    fallback: false,
  };
};

export const getStaticProps: GetStaticProps<PolicyProps> = async ({ params }) => {
  const { slug, fileName } = params as { slug: string; fileName: string };
  const filePath = path.join(process.cwd(), 'content', 'policies', slug, fileName);
  const fileContent = fs.readFileSync(filePath, 'utf-8');
  const { content } = matter(fileContent);

  return {
    props: {
      content,
    },
  };
};

export default PolicyPage;