Xianbao QIAN commited on
Commit
a2242ea
1 Parent(s): 4646723

use common policy data type

Browse files
src/components/AIPoliciesTable.tsx CHANGED
@@ -1,14 +1,5 @@
1
  import React from "react";
2
-
3
- interface PolicyData {
4
- zh: string;
5
- en: string;
6
- link: {
7
- zh: string;
8
- en: string;
9
- };
10
- releaseDate: string;
11
- }
12
 
13
  interface AIPoliciesTableProps {
14
  policies: PolicyData[];
 
1
  import React from "react";
2
+ import { PolicyData } from "../types";
 
 
 
 
 
 
 
 
 
3
 
4
  interface AIPoliciesTableProps {
5
  policies: PolicyData[];
src/pages/index.tsx CHANGED
@@ -13,6 +13,7 @@ import AIPoliciesTable from "../components/AIPoliciesTable";
13
  import fs from 'fs';
14
  import path from 'path';
15
  import matter from 'gray-matter';
 
16
 
17
  // const PROVIDERS: ProviderInfo[] = [
18
  // { color: "#ff7000", authors: ["mistralai"] },
@@ -31,24 +32,26 @@ import matter from 'gray-matter';
31
  // { color: "#A020F0", authors: ["stabilityai"] },
32
  // ];
33
 
34
- interface PolicyData {
35
- title: string;
36
- language: string;
37
- originalLink: string;
38
- slug: string;
39
- fileName: string;
40
- releaseDate: string;
41
- }
42
-
43
  export async function getStaticProps() {
44
  try {
45
  // Read policy data from policies.json
46
  const policiesFilePath = path.join(process.cwd(), 'content', 'policies.json');
47
  const policiesContent = fs.readFileSync(policiesFilePath, 'utf-8');
48
- const policyData: PolicyData[] = JSON.parse(policiesContent);
 
 
 
 
 
 
 
 
 
 
 
49
 
50
  // Sort policyData based on releaseDate in descending order
51
- policyData.sort((a, b) => {
52
  const dateA = a.releaseDate ? new Date(a.releaseDate).getTime() : 0;
53
  const dateB = b.releaseDate ? new Date(b.releaseDate).getTime() : 0;
54
  return dateB - dateA;
 
13
  import fs from 'fs';
14
  import path from 'path';
15
  import matter from 'gray-matter';
16
+ import { PolicyData } from "../types";
17
 
18
  // const PROVIDERS: ProviderInfo[] = [
19
  // { color: "#ff7000", authors: ["mistralai"] },
 
32
  // { color: "#A020F0", authors: ["stabilityai"] },
33
  // ];
34
 
 
 
 
 
 
 
 
 
 
35
  export async function getStaticProps() {
36
  try {
37
  // Read policy data from policies.json
38
  const policiesFilePath = path.join(process.cwd(), 'content', 'policies.json');
39
  const policiesContent = fs.readFileSync(policiesFilePath, 'utf-8');
40
+ const rawPolicyData = JSON.parse(policiesContent);
41
+
42
+ // Transform the policy data into the expected format
43
+ const policyData = rawPolicyData.map((policy: any) => ({
44
+ zh: policy.zh,
45
+ en: policy.en,
46
+ link: {
47
+ zh: policy.link,
48
+ en: policy.link,
49
+ },
50
+ releaseDate: policy.releaseDate,
51
+ }));
52
 
53
  // Sort policyData based on releaseDate in descending order
54
+ policyData.sort((a: PolicyData, b: PolicyData) => {
55
  const dateA = a.releaseDate ? new Date(a.releaseDate).getTime() : 0;
56
  const dateB = b.releaseDate ? new Date(b.releaseDate).getTime() : 0;
57
  return dateB - dateA;
src/types.ts ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ export interface PolicyData {
2
+ zh: string;
3
+ en: string;
4
+ link: {
5
+ zh: string;
6
+ en: string;
7
+ };
8
+ releaseDate: string;
9
+ }