Xianbao QIAN commited on
Commit
b92b41e
·
1 Parent(s): 675c4b1

add citation block and filters.

Browse files
src/components/AIPoliciesTable.tsx CHANGED
@@ -18,7 +18,23 @@ const AIPoliciesTable: React.FC<AIPoliciesTableProps> = ({ policies }) => {
18
  setOpenYears((prev) => ({ ...prev, [year]: !prev[year] }));
19
  };
20
 
21
- const groupedPolicies = policies.reduce((acc, policy) => {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  const year = new Date(policy.releaseDate).getFullYear();
23
  if (!acc[year]) {
24
  acc[year] = [];
@@ -39,6 +55,19 @@ const AIPoliciesTable: React.FC<AIPoliciesTableProps> = ({ policies }) => {
39
 
40
  return (
41
  <div className="container mx-auto p-6">
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  {sortedYears.map((year) => (
43
  <div key={year} className="mb-12">
44
  <button
@@ -67,6 +96,9 @@ const AIPoliciesTable: React.FC<AIPoliciesTableProps> = ({ policies }) => {
67
  <div className="text-xs text-gray-400 dark:text-gray-500 mt-2">
68
  {formatDate(policy.releaseDate)}
69
  </div>
 
 
 
70
  </td>
71
  <td className="py-6 px-6 text-right">
72
  {policy.link.zh && (
 
18
  setOpenYears((prev) => ({ ...prev, [year]: !prev[year] }));
19
  };
20
 
21
+ const uniqueTags = Array.from(new Set(policies.flatMap(policy => policy.tags.map(tag => tag.toLowerCase())))).map(tag => tag.charAt(0).toUpperCase() + tag.slice(1));
22
+
23
+ const [selectedTags, setSelectedTags] = useState<string[]>(uniqueTags);
24
+
25
+ const handleTagChange = (tag: string) => {
26
+ if (selectedTags.includes(tag)) {
27
+ setSelectedTags(selectedTags.filter(t => t !== tag));
28
+ } else {
29
+ setSelectedTags([...selectedTags, tag]);
30
+ }
31
+ };
32
+
33
+ const filteredPolicies = selectedTags.length === 0
34
+ ? policies
35
+ : policies.filter(policy => policy.tags.some(tag => selectedTags.includes(tag.charAt(0).toUpperCase() + tag.slice(1))));
36
+
37
+ const groupedPolicies = filteredPolicies.reduce((acc, policy) => {
38
  const year = new Date(policy.releaseDate).getFullYear();
39
  if (!acc[year]) {
40
  acc[year] = [];
 
55
 
56
  return (
57
  <div className="container mx-auto p-6">
58
+ <div className="mb-6 flex justify-center">
59
+ {uniqueTags.map(tag => (
60
+ <label key={tag} className="inline-flex items-center mr-4">
61
+ <input
62
+ type="checkbox"
63
+ className="form-checkbox h-5 w-5 text-blue-600"
64
+ checked={selectedTags.includes(tag)}
65
+ onChange={() => handleTagChange(tag)}
66
+ />
67
+ <span className="ml-2 text-gray-700 dark:text-gray-400">{tag}</span>
68
+ </label>
69
+ ))}
70
+ </div>
71
  {sortedYears.map((year) => (
72
  <div key={year} className="mb-12">
73
  <button
 
96
  <div className="text-xs text-gray-400 dark:text-gray-500 mt-2">
97
  {formatDate(policy.releaseDate)}
98
  </div>
99
+ <div className="text-xs text-gray-400 dark:text-gray-500 mt-2">
100
+ {policy.tags.map(tag => tag.charAt(0).toUpperCase() + tag.slice(1)).join(', ')}
101
+ </div>
102
  </td>
103
  <td className="py-6 px-6 text-right">
104
  {policy.link.zh && (
src/pages/index.tsx CHANGED
@@ -37,18 +37,7 @@ export async function getStaticProps() {
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.zh || null, // Only include link if provided
48
- en: policy.link.en || null, // Only include link if provided
49
- },
50
- releaseDate: policy.releaseDate,
51
- }));
52
 
53
  // Sort policyData based on releaseDate in descending order
54
  policyData.sort((a: PolicyData, b: PolicyData) => {
@@ -100,8 +89,23 @@ const OpenSourceHeatmap: React.FC<{ policyData: PolicyData[] }> = ({
100
  </h1>
101
 
102
  <AIPoliciesTable policies={policyData} />
103
- </div>
104
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
105
  {/* <div className="text-center text-sm my-8 space-y-4">
106
  <p>
107
  Models, Datasets, and Spaces from the top AI labs.
 
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 policyData = JSON.parse(policiesContent);
 
 
 
 
 
 
 
 
 
 
 
41
 
42
  // Sort policyData based on releaseDate in descending order
43
  policyData.sort((a: PolicyData, b: PolicyData) => {
 
89
  </h1>
90
 
91
  <AIPoliciesTable policies={policyData} />
 
92
 
93
+ {/* Add citation section */}
94
+ <div className="mt-16">
95
+ <h2 className="text-2xl font-bold mb-4">Citation</h2>
96
+ <p className="text-gray-700 dark:text-gray-400">
97
+ If you use this resource in your research, please cite it as follows:
98
+ </p>
99
+ <pre className="bg-gray-100 dark:bg-gray-800 p-4 rounded mt-2">
100
+ {`@misc{china_ai_policy_${new Date().getFullYear()},
101
+ title={China AI Policy Research},
102
+ author={Tiezhen Wang, Adina Yakefu, Lu Cheng},
103
+ year={2024},
104
+ }`}
105
+ </pre>
106
+ </div>
107
+ </div>
108
+
109
  {/* <div className="text-center text-sm my-8 space-y-4">
110
  <p>
111
  Models, Datasets, and Spaces from the top AI labs.
src/types.ts CHANGED
@@ -6,4 +6,5 @@ export interface PolicyData {
6
  en: string;
7
  };
8
  releaseDate: string;
 
9
  }
 
6
  en: string;
7
  };
8
  releaseDate: string;
9
+ tags: string[]; // Add this line
10
  }