Xianbao QIAN
		
	commited on
		
		
					Commit 
							
							·
						
						9816072
	
1
								Parent(s):
							
							2f5ac31
								
more user friendly commit + french support
Browse files- bun.lockb +0 -0
 - content/policies.json +3 -1
 - package.json +2 -1
 - src/components/AIPoliciesTable.tsx +11 -1
 - src/pages/index.tsx +27 -12
 - src/types.ts +16 -10
 
    	
        bun.lockb
    CHANGED
    
    | 
         Binary files a/bun.lockb and b/bun.lockb differ 
     | 
| 
         | 
    	
        content/policies.json
    CHANGED
    
    | 
         @@ -102,9 +102,11 @@ 
     | 
|
| 102 | 
         
             
                {
         
     | 
| 103 | 
         
             
                  "zh": "中华人民共和国和法兰西共和国关于人工智能和全球治理的联合声明",
         
     | 
| 104 | 
         
             
                  "en": "Joint Statement of the People's Republic of China and the French Republic on Artificial Intelligence and Global Governance",
         
     | 
| 
         | 
|
| 105 | 
         
             
                  "link": {
         
     | 
| 106 | 
         
             
                    "zh": "https://www.mfa.gov.cn/zyxw/202405/t20240507_11293821.shtml",
         
     | 
| 107 | 
         
            -
                    "en": ""
         
     | 
| 
         | 
|
| 108 | 
         
             
                  },
         
     | 
| 109 | 
         
             
                  "releaseDate": "2024-05-07",
         
     | 
| 110 | 
         
             
                  "tags": ["international"]
         
     | 
| 
         | 
|
| 102 | 
         
             
                {
         
     | 
| 103 | 
         
             
                  "zh": "中华人民共和国和法兰西共和国关于人工智能和全球治理的联合声明",
         
     | 
| 104 | 
         
             
                  "en": "Joint Statement of the People's Republic of China and the French Republic on Artificial Intelligence and Global Governance",
         
     | 
| 105 | 
         
            +
                  "fr": "Déclaration conjointe entre la République française et la République populaire de Chine sur l’intelligence artificielle et la gouvernance des enjeux globaux",
         
     | 
| 106 | 
         
             
                  "link": {
         
     | 
| 107 | 
         
             
                    "zh": "https://www.mfa.gov.cn/zyxw/202405/t20240507_11293821.shtml",
         
     | 
| 108 | 
         
            +
                    "en": "",
         
     | 
| 109 | 
         
            +
                    "fr": "https://www.elysee.fr/emmanuel-macron/2024/05/06/declaration-conjointe-entre-la-republique-francaise-et-la-republique-populaire-de-chine-sur-lintelligence-artificielle-et-la-gouvernance-des-enjeux-globaux"
         
     | 
| 110 | 
         
             
                  },
         
     | 
| 111 | 
         
             
                  "releaseDate": "2024-05-07",
         
     | 
| 112 | 
         
             
                  "tags": ["international"]
         
     | 
    	
        package.json
    CHANGED
    
    | 
         @@ -26,7 +26,8 @@ 
     | 
|
| 26 | 
         
             
                "react-dom": "^18",
         
     | 
| 27 | 
         
             
                "react-markdown": "^9.0.1",
         
     | 
| 28 | 
         
             
                "tailwind-merge": "^2.4.0",
         
     | 
| 29 | 
         
            -
                "tailwindcss-animate": "^1.0.7"
         
     | 
| 
         | 
|
| 30 | 
         
             
              },
         
     | 
| 31 | 
         
             
              "devDependencies": {
         
     | 
| 32 | 
         
             
                "typescript": "^5",
         
     | 
| 
         | 
|
| 26 | 
         
             
                "react-dom": "^18",
         
     | 
| 27 | 
         
             
                "react-markdown": "^9.0.1",
         
     | 
| 28 | 
         
             
                "tailwind-merge": "^2.4.0",
         
     | 
| 29 | 
         
            +
                "tailwindcss-animate": "^1.0.7",
         
     | 
| 30 | 
         
            +
                "zod": "^3.23.8"
         
     | 
| 31 | 
         
             
              },
         
     | 
| 32 | 
         
             
              "devDependencies": {
         
     | 
| 33 | 
         
             
                "typescript": "^5",
         
     | 
    	
        src/components/AIPoliciesTable.tsx
    CHANGED
    
    | 
         @@ -116,11 +116,21 @@ const AIPoliciesTable: React.FC<AIPoliciesTableProps> = ({ policies }) => { 
     | 
|
| 116 | 
         
             
                                      href={policy.link.en}
         
     | 
| 117 | 
         
             
                                      target="_blank"
         
     | 
| 118 | 
         
             
                                      rel="noopener noreferrer"
         
     | 
| 119 | 
         
            -
                                      className="text-blue-500 hover:underline dark:text-blue-400"
         
     | 
| 120 | 
         
             
                                    >
         
     | 
| 121 | 
         
             
                                      English
         
     | 
| 122 | 
         
             
                                    </a>
         
     | 
| 123 | 
         
             
                                  )}
         
     | 
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 124 | 
         
             
                                </td>
         
     | 
| 125 | 
         
             
                              </tr>
         
     | 
| 126 | 
         
             
                            ))}
         
     | 
| 
         | 
|
| 116 | 
         
             
                                      href={policy.link.en}
         
     | 
| 117 | 
         
             
                                      target="_blank"
         
     | 
| 118 | 
         
             
                                      rel="noopener noreferrer"
         
     | 
| 119 | 
         
            +
                                      className="text-blue-500 hover:underline dark:text-blue-400 mr-4"
         
     | 
| 120 | 
         
             
                                    >
         
     | 
| 121 | 
         
             
                                      English
         
     | 
| 122 | 
         
             
                                    </a>
         
     | 
| 123 | 
         
             
                                  )}
         
     | 
| 124 | 
         
            +
                                  {policy.link.fr && (
         
     | 
| 125 | 
         
            +
                                    <a
         
     | 
| 126 | 
         
            +
                                      href={policy.link.fr}
         
     | 
| 127 | 
         
            +
                                      target="_blank"
         
     | 
| 128 | 
         
            +
                                      rel="noopener noreferrer"
         
     | 
| 129 | 
         
            +
                                      className="text-blue-500 hover:underline dark:text-blue-400"
         
     | 
| 130 | 
         
            +
                                    >
         
     | 
| 131 | 
         
            +
                                      Français
         
     | 
| 132 | 
         
            +
                                    </a>
         
     | 
| 133 | 
         
            +
                                  )}
         
     | 
| 134 | 
         
             
                                </td>
         
     | 
| 135 | 
         
             
                              </tr>
         
     | 
| 136 | 
         
             
                            ))}
         
     | 
    	
        src/pages/index.tsx
    CHANGED
    
    | 
         @@ -13,7 +13,8 @@ import AIPoliciesTable from "../components/AIPoliciesTable"; 
     | 
|
| 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"] },
         
     | 
| 
         @@ -39,27 +40,41 @@ export async function getStaticProps() { 
     | 
|
| 39 | 
         
             
                const policiesContent = fs.readFileSync(policiesFilePath, 'utf-8');
         
     | 
| 40 | 
         
             
                const policyData = JSON.parse(policiesContent);
         
     | 
| 41 | 
         | 
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 42 | 
         
             
                // Sort policyData based on releaseDate in descending order
         
     | 
| 43 | 
         
            -
                 
     | 
| 44 | 
         
            -
                  const dateA =  
     | 
| 45 | 
         
            -
                  const dateB =  
     | 
| 46 | 
         
             
                  return dateB - dateA;
         
     | 
| 47 | 
         
             
                });
         
     | 
| 48 | 
         | 
| 49 | 
         
             
                return {
         
     | 
| 50 | 
         
             
                  props: {
         
     | 
| 51 | 
         
            -
                    policyData,
         
     | 
| 52 | 
         
             
                  },
         
     | 
| 53 | 
         
             
                  revalidate: 3600,
         
     | 
| 54 | 
         
             
                };
         
     | 
| 55 | 
         
             
              } catch (error) {
         
     | 
| 56 | 
         
            -
                 
     | 
| 57 | 
         
            -
             
     | 
| 58 | 
         
            -
             
     | 
| 59 | 
         
            -
             
     | 
| 60 | 
         
            -
             
     | 
| 61 | 
         
            -
             
     | 
| 62 | 
         
            -
             
     | 
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 63 | 
         
             
              }
         
     | 
| 64 | 
         
             
            }
         
     | 
| 65 | 
         | 
| 
         | 
|
| 13 | 
         
             
            import fs from 'fs';
         
     | 
| 14 | 
         
             
            import path from 'path';
         
     | 
| 15 | 
         
             
            import matter from 'gray-matter';
         
     | 
| 16 | 
         
            +
            import { PolicyData, PolicyDataSchema } from "../types";
         
     | 
| 17 | 
         
            +
            import z from 'zod';
         
     | 
| 18 | 
         | 
| 19 | 
         
             
            // const PROVIDERS: ProviderInfo[] = [
         
     | 
| 20 | 
         
             
            //   { color: "#ff7000", authors: ["mistralai"] },
         
     | 
| 
         | 
|
| 40 | 
         
             
                const policiesContent = fs.readFileSync(policiesFilePath, 'utf-8');
         
     | 
| 41 | 
         
             
                const policyData = JSON.parse(policiesContent);
         
     | 
| 42 | 
         | 
| 43 | 
         
            +
                // Validate policyData against the schema
         
     | 
| 44 | 
         
            +
                const validatedPolicyData = PolicyDataSchema.array().parse(policyData);
         
     | 
| 45 | 
         
            +
             
     | 
| 46 | 
         
             
                // Sort policyData based on releaseDate in descending order
         
     | 
| 47 | 
         
            +
                validatedPolicyData.sort((a: PolicyData, b: PolicyData) => {
         
     | 
| 48 | 
         
            +
                  const dateA = new Date(a.releaseDate).getTime();
         
     | 
| 49 | 
         
            +
                  const dateB = new Date(b.releaseDate).getTime();
         
     | 
| 50 | 
         
             
                  return dateB - dateA;
         
     | 
| 51 | 
         
             
                });
         
     | 
| 52 | 
         | 
| 53 | 
         
             
                return {
         
     | 
| 54 | 
         
             
                  props: {
         
     | 
| 55 | 
         
            +
                    policyData: validatedPolicyData,
         
     | 
| 56 | 
         
             
                  },
         
     | 
| 57 | 
         
             
                  revalidate: 3600,
         
     | 
| 58 | 
         
             
                };
         
     | 
| 59 | 
         
             
              } catch (error) {
         
     | 
| 60 | 
         
            +
                if (error instanceof z.ZodError) {
         
     | 
| 61 | 
         
            +
                  const errorMessage = error.issues
         
     | 
| 62 | 
         
            +
                    .map((issue) => {
         
     | 
| 63 | 
         
            +
                      const path = issue.path.join('.');
         
     | 
| 64 | 
         
            +
                      const message = issue.message;
         
     | 
| 65 | 
         
            +
                      return `Invalid policy data at "${path}": ${message}`;
         
     | 
| 66 | 
         
            +
                    })
         
     | 
| 67 | 
         
            +
                    .join('\n');
         
     | 
| 68 | 
         
            +
                  console.error('Error validating policy data:', errorMessage);
         
     | 
| 69 | 
         
            +
                  throw new Error(`Failed to validate policy data:\n${errorMessage}`);
         
     | 
| 70 | 
         
            +
                } else {
         
     | 
| 71 | 
         
            +
                  console.error('Error fetching data:', error);
         
     | 
| 72 | 
         
            +
                  if (error instanceof Error) {
         
     | 
| 73 | 
         
            +
                    throw new Error(`Failed to fetch policy data: ${error.message}`);
         
     | 
| 74 | 
         
            +
                  } else {
         
     | 
| 75 | 
         
            +
                    throw new Error('Failed to fetch policy data: An unknown error occurred.');
         
     | 
| 76 | 
         
            +
                  }
         
     | 
| 77 | 
         
            +
                }
         
     | 
| 78 | 
         
             
              }
         
     | 
| 79 | 
         
             
            }
         
     | 
| 80 | 
         | 
    	
        src/types.ts
    CHANGED
    
    | 
         @@ -1,10 +1,16 @@ 
     | 
|
| 1 | 
         
            -
             
     | 
| 2 | 
         
            -
             
     | 
| 3 | 
         
            -
             
     | 
| 4 | 
         
            -
               
     | 
| 5 | 
         
            -
             
     | 
| 6 | 
         
            -
             
     | 
| 7 | 
         
            -
               
     | 
| 8 | 
         
            -
             
     | 
| 9 | 
         
            -
             
     | 
| 10 | 
         
            -
             
     | 
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
| 
         | 
|
| 1 | 
         
            +
            import { z } from 'zod';
         
     | 
| 2 | 
         
            +
             
     | 
| 3 | 
         
            +
            export const PolicyDataSchema = z.object({
         
     | 
| 4 | 
         
            +
              zh: z.string(),
         
     | 
| 5 | 
         
            +
              en: z.string(),
         
     | 
| 6 | 
         
            +
              fr: z.string().optional(),
         
     | 
| 7 | 
         
            +
              link: z.object({
         
     | 
| 8 | 
         
            +
                zh: z.string(),
         
     | 
| 9 | 
         
            +
                en: z.string().optional(),
         
     | 
| 10 | 
         
            +
                fr: z.string().optional(),
         
     | 
| 11 | 
         
            +
              }),
         
     | 
| 12 | 
         
            +
              releaseDate: z.string(),
         
     | 
| 13 | 
         
            +
              tags: z.array(z.string()),
         
     | 
| 14 | 
         
            +
            });
         
     | 
| 15 | 
         
            +
             
     | 
| 16 | 
         
            +
            export type PolicyData = z.infer<typeof PolicyDataSchema>;
         
     |