diff --git a/.gitignore b/.gitignore index 4d29575de80..ff1cf69e3dd 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,6 @@ npm-debug.log* yarn-debug.log* yarn-error.log* + +# app +public/list.json diff --git a/README.md b/README.md index 00def4f1989..4f0e8046cfe 100644 --- a/README.md +++ b/README.md @@ -42,10 +42,6 @@ Your url will be `http://linkfree.eddiehub.org/`, for example http Your `avatar` URL should take the format of `https://github.com/.png`. -### Add your profile to the home page +### Home page profiles -Update the file `public/data/_list.json` with the following object to the collection: - -```json -{ "username": "eddiejaoude", "avatar": "https://github.com/eddiejaoude.png" }, -``` +Your profile will automatically appear on the home page. diff --git a/generate.js b/generate.js new file mode 100644 index 00000000000..d31b9da0df3 --- /dev/null +++ b/generate.js @@ -0,0 +1,24 @@ +const path = require('path') +const fs = require('fs') + +// load json files +const readDirectoryPath = path.join(__dirname, 'public', 'data') +const files = fs.readdirSync(readDirectoryPath) +const profiles = files.map((file) => { + const data = JSON.parse( + fs.readFileSync(`${path.join(__dirname, 'public', 'data', file)}`, 'utf8'), + ) + return { + username: file.split('.')[0], + ...data, + } +}) + +// generate list file +const writeDirectoryPath = path.join(__dirname, 'public', 'list.json') +const output = profiles.map((profile) => ({ + username: profile.username, + avatar: profile.avatar, +})) + +fs.writeFileSync(writeDirectoryPath, JSON.stringify(output)) diff --git a/package.json b/package.json index f985a21cd90..c9d23b4de74 100644 --- a/package.json +++ b/package.json @@ -20,11 +20,13 @@ }, "scripts": { "lint": "eslint public/data --ext .json", + "prestart": "npm run generate", "start": "react-scripts start", "start:prod": "serve -s build", "build": "react-scripts build", "test": "react-scripts test", - "eject": "react-scripts eject" + "eject": "react-scripts eject", + "generate": "node generate.js" }, "eslintConfig": { "extends": [ @@ -54,4 +56,4 @@ "eslint-plugin-react": "^7.25.1", "prettier": "2.4.0" } -} \ No newline at end of file +} diff --git a/public/data/_list.json b/public/data/_list.json deleted file mode 100644 index bae33ea81b2..00000000000 --- a/public/data/_list.json +++ /dev/null @@ -1,36 +0,0 @@ -[ - { "username": "eddiejaoude", "avatar": "https://github.com/eddiejaoude.png" }, - { - "username": "nhcarrigan", - "avatar": "https://avatars.githubusercontent.com/u/63889819?v=4" - }, - { "username": "stemount", "avatar": "https://github.com/stemount.png" }, - { - "username": "iasonathanasiosgiatsios", - "avatar": "https://github.com/iason9.png" - }, - { "username": "FayasNoushad", "avatar": "https://github.com/FayasNoushad.png" }, - { "username": "mohammad", "avatar": "https://github.com/mohammad4kh.png" }, - { - "username": "verma-kunal", - "avatar": "https://github.com/verma-kunal.png" - }, - { - "username": "Skyhero-admin", - "avatar": "https://github.com/Skyhero-admin.png" - }, - { "username": "krishdevdb", "avatar": "https://github.com/krishdevdb.png" - }, - { "username": "Nikhil-1503", "avatar": "https://github.com/Nikhil-1503.png" }, - { "username": "vinzvinci", "avatar": "https://github.com/vinzvinci.png" }, - { "username": "orama254", "avatar": "https://github.com/orama254.png" }, - { "username": "voidz", "avatar": "https://github.com/voidz7.png" }, - { "username": "suhail34", "avatar": "https://github.com/suhail34.png" }, - { "username": "vikasganiga05", "avatar": "https://github.com/vikasganiga05.png" }, - { "username": "roshanmhatre", "avatar": "https://github.com/RoshanMhatre.png" }, - { "username": "arnav1776", "avatar": "https://github.com/arnav1776.png" }, - { - "username": "SriSatyaT", - "avatar": "https://github.com/SriSatyaT.png" - } -] diff --git a/src/Components/Home.js b/src/Components/Home.js index acccaa1251a..c8e74d05f18 100644 --- a/src/Components/Home.js +++ b/src/Components/Home.js @@ -18,7 +18,7 @@ function Home() { } useEffect(() => { - fetch('/data/_list.json') + fetch('/list.json') .then((response) => response.json()) .then((data) => setList(data)) }, [])