Browse Source

Refactor data structure by converting YAML files to JSON (#2069)

Paweł Kuna 1 month ago
parent
commit
0e4bf5fc73

+ 28 - 29
.build/download-images.js

@@ -2,56 +2,55 @@
 
 'use strict'
 
-const YAML = require('yaml')
 const fs = require('node:fs')
 const path = require('node:path')
 const request = require('request')
-const filePath = path.join(__dirname, '../src/pages/_data/photos.yml')
+const filePath = path.join(__dirname, '../src/pages/_data/photos.json')
 
-const photos = YAML.parse(fs.readFileSync(filePath, 'utf8'))
+const photos = JSON.parse(fs.readFileSync(filePath, 'utf8'))
 
 const urlTitle = (str) => {
-  str = str
+	str = str
 		.toLowerCase()
 		.replaceAll('&', 'and')
 		.replace(/[^[a-z0-9-]/g, '-')
 		.replace(/-+/g, '-')
 
-  return str
+	return str
 }
 
-const download = function(uri, filename, callback, error) {
-  request.head(uri, function(err, res, body) {
-	 request(uri).pipe(fs.createWriteStream(filename))
-		  .on('close', callback)
-		  .on('error', error)
-  })
+const download = function (uri, filename, callback, error) {
+	request.head(uri, function (err, res, body) {
+		request(uri).pipe(fs.createWriteStream(filename))
+			.on('close', callback)
+			.on('error', error)
+	})
 }
 
 async function downloadPhotos() {
-  for (const key in photos) {
-	 const photo = photos[key]
+	for (const key in photos) {
+		const photo = photos[key]
 
-	 let filename, i = 1;
+		let filename, i = 1;
 
-	 do {
-		filename = `${urlTitle(photo['title'])}${i > 1 ? `-${i}` : ''}.jpg`
-		i++
-	 } while (fs.existsSync(path.join(__dirname, `../src/static/photos/${filename}`)))
+		do {
+			filename = `${urlTitle(photo['title'])}${i > 1 ? `-${i}` : ''}.jpg`
+			i++
+		} while (fs.existsSync(path.join(__dirname, `../src/static/photos/${filename}`)))
 
-	 await new Promise((resolve, reject) => {
-		download(photo['path'], path.join(__dirname, `../src/static/photos/${filename}`), function(){
-		  resolve()
-		}, function() {
-		  reject()
-		});
-	 })
+		await new Promise((resolve, reject) => {
+			download(photo['path'], path.join(__dirname, `../src/static/photos/${filename}`), function () {
+				resolve()
+			}, function () {
+				reject()
+			});
+		})
 
-	 photos[key]['file'] = filename
-	 photos[key]['horizontal'] = photo['width'] > photo['height']
-  }
+		photos[key]['file'] = filename
+		photos[key]['horizontal'] = photo['width'] > photo['height']
+	}
 
-  fs.writeFileSync(filePath, YAML.stringify(photos))
+	fs.writeFileSync(filePath, JSON.stringify(photos))
 }
 
 downloadPhotos();

+ 5 - 0
.changeset/nice-fireants-itch.md

@@ -0,0 +1,5 @@
+---
+"@tabler/core": patch
+---
+
+Refactor data structure by converting YAML files to JSON

+ 1 - 3
package.json

@@ -186,9 +186,7 @@
     "typed.js": "^2.1.0",
     "vinyl-buffer": "^1.0.1",
     "vinyl-source-stream": "^2.0.0",
-    "yaml": "^2.7.0",
-    "yargs": "^17.7.2",
-    "zod": "^3.24.1"
+    "yargs": "^17.7.2"
   },
   "dependencies": {
     "@popperjs/core": "^2.11.8",

+ 0 - 10
pnpm-lock.yaml

@@ -184,15 +184,9 @@ devDependencies:
   vinyl-source-stream:
     specifier: ^2.0.0
     version: 2.0.0
-  yaml:
-    specifier: ^2.7.0
-    version: 2.7.0
   yargs:
     specifier: ^17.7.2
     version: 17.7.2
-  zod:
-    specifier: ^3.24.1
-    version: 3.24.1
 
 packages:
 
@@ -9228,7 +9222,3 @@ packages:
     resolution: {integrity: sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==}
     engines: {node: '>=10'}
     dev: true
-
-  /zod@3.24.1:
-    resolution: {integrity: sha512-muH7gBL9sI1nciMZV67X5fTKKBLtwpZ5VBp1vsOQzj1MhrBZ4wlVCm3gedKZWLp0Oyel8sIGfeiz54Su+OVT+A==}
-    dev: true

+ 56 - 0
src/pages/_data/activity.json

@@ -0,0 +1,56 @@
+[
+  {
+    "text": "<strong>%p</strong> commented on your <strong>\"I'm not a witch.\"</strong> post."
+  },
+  {
+    "text": "It's <strong>%p</strong>'s birthday. Wish him well!"
+  },
+  {
+    "text": "<strong>%p</strong> posted <strong>\"Well, what do you want?\"</strong>."
+  },
+  {
+    "text": "<strong>%p</strong> created a new project <strong>Morning alarm clock</strong>."
+  },
+  {
+    "text": "<strong>%p</strong> liked your photo."
+  },
+  {
+    "text": "<strong>%p</strong> registered new client as <strong>%c</strong>."
+  },
+  {
+    "text": "<strong>%p</strong> closed a new deal on project <strong>Pen Pineapple Apple Pen</strong>."
+  },
+  {
+    "text": "<strong>%p</strong> created a new project for <strong>%c</strong>."
+  },
+  {
+    "text": "<strong>%p</strong> change status of <strong>Tabler Icons</strong> from <strong>open</strong> to <strong>closed</strong>."
+  },
+  {
+    "text": "<strong>%p</strong> liked <strong>Tabler UI Kit</strong>."
+  },
+  {
+    "text": "<strong>%p</strong> posted new video."
+  },
+  {
+    "text": "<strong>%p</strong> and 3 others followed you."
+  },
+  {
+    "text": "<strong>%p</strong> upload 3 new photos to category <strong>Inspirations</strong>."
+  },
+  {
+    "text": "<strong>%p</strong> made a <strong>$10</strong> donation."
+  },
+  {
+    "text": "<strong>%p</strong> created a profile."
+  },
+  {
+    "text": "<strong>%p</strong> hosted the event <strong>Tabler UI Birthday</strong>."
+  },
+  {
+    "text": "<strong>%p</strong> mentioned you on <strong>Best of 2020</strong>."
+  },
+  {
+    "text": "<strong>%p</strong> sent a Review Request to <strong>Amanda Blake</strong>."
+  }
+]

+ 0 - 18
src/pages/_data/activity.yml

@@ -1,18 +0,0 @@
-- text: "<strong>%p</strong> commented on your <strong>\"I'm not a witch.\"</strong> post."
-- text: "It's <strong>%p</strong>'s birthday. Wish him well!"
-- text: "<strong>%p</strong> posted <strong>\"Well, what do you want?\"</strong>."
-- text: "<strong>%p</strong> created a new project <strong>Morning alarm clock</strong>."
-- text: "<strong>%p</strong> liked your photo."
-- text: "<strong>%p</strong> registered new client as <strong>%c</strong>."
-- text: "<strong>%p</strong> closed a new deal on project <strong>Pen Pineapple Apple Pen</strong>."
-- text: "<strong>%p</strong> created a new project for <strong>%c</strong>."
-- text: "<strong>%p</strong> change status of <strong>Tabler Icons</strong> from <strong>open</strong> to <strong>closed</strong>."
-- text: "<strong>%p</strong> liked <strong>Tabler UI Kit</strong>."
-- text: "<strong>%p</strong> posted new video."
-- text: "<strong>%p</strong> and 3 others followed you."
-- text: "<strong>%p</strong> upload 3 new photos to category <strong>Inspirations</strong>."
-- text: "<strong>%p</strong> made a <strong>$10</strong> donation."
-- text: "<strong>%p</strong> created a profile."
-- text: "<strong>%p</strong> hosted the event <strong>Tabler UI Birthday</strong>."
-- text: "<strong>%p</strong> mentioned you on <strong>Best of 2020</strong>."
-- text: "<strong>%p</strong> sent a Review Request to <strong>Amanda Blake</strong>."

+ 26 - 0
src/pages/_data/alerts.json

@@ -0,0 +1,26 @@
+[
+  {
+    "color": "success",
+    "icon": "check",
+    "text": "Wow! Everything worked!",
+    "description": "Your account has been saved!"
+  },
+  {
+    "color": "info",
+    "icon": "info-circle",
+    "text": "Did you know?",
+    "description": "Here is something that you might like to know."
+  },
+  {
+    "color": "warning",
+    "icon": "alert-triangle",
+    "text": "Uh oh, something went wrong",
+    "description": "Sorry! There was a problem with your request."
+  },
+  {
+    "color": "danger",
+    "icon": "alert-circle",
+    "text": "I'm so sorry&hellip;",
+    "description": "Your account has been deleted and can't be restored."
+  }
+]

+ 0 - 16
src/pages/_data/alerts.yml

@@ -1,16 +0,0 @@
-- color: success
-  icon: check
-  text: Wow! Everything worked!
-  description: Your account has been saved!
-- color: info
-  icon: info-circle
-  text: Did you know?
-  description: Here is something that you might like to know.
-- color: warning
-  icon: alert-triangle
-  text: Uh oh, something went wrong
-  description: Sorry! There was a problem with your request.
-- color: danger
-  icon: alert-circle
-  text: I'm so sorry&hellip;
-  description: Your account has been deleted and can't be restored.

+ 44 - 0
src/pages/_data/articles.json

@@ -0,0 +1,44 @@
+[
+  {
+    "title": "And this isn't my nose. This is a false one.",
+    "description": "Look, my liege! The Knights Who Say Ni demand a sacrifice! …Are you suggesting that coconuts migrate? Well, I got better.",
+    "image": 14,
+    "author": 3
+  },
+  {
+    "title": "Well, I didn't vote for you.",
+    "description": "Well, we did do the nose. Why? Shut up! Will you shut up?! You don't frighten us, English pig-dogs! Go and boil your bottoms, sons of a silly person! I blow my nose at you, so-called Ah-thoor Keeng, you and all your silly English K-n-n-n-n-n-n-n-niggits!",
+    "image": 15,
+    "author": 4
+  },
+  {
+    "title": "How do you know she is a witch?",
+    "description": "Are you suggesting that coconuts migrate? No, no, no! Yes, yes. A bit. But she's got a wart. You don't vote for kings. Ah, now we see the violence inherent in the system!",
+    "image": 16,
+    "author": 5
+  },
+  {
+    "title": "Shut up!",
+    "description": "Burn her! How do you know she is a witch? You don't frighten us, English pig-dogs! Go and boil your bottoms, sons of a silly person! I blow my nose at you, so-called Ah-thoor Keeng, you and all your silly English K-n-n-n-n-n-n-n-niggits!",
+    "image": 17,
+    "author": 6
+  },
+  {
+    "title": "Weaseling out of things is important to learn.",
+    "description": "Please do not offer my god a peanut. That's why I love elementary school, Edna. The children believe anything you tell them. Brace yourselves gentlemen. According to the gas chromatograph, the secret ingredient is… Love!? Who's been screwing with this thing?",
+    "image": 20,
+    "author": 12
+  },
+  {
+    "title": "You don't like your job, you don't strike.",
+    "description": "But, Aquaman, you cannot marry a woman without gills. You're from two different worlds… Oh, I've wasted my life. Son, when you participate in sporting events, it's not whether you win or lose: it's how drunk you get.",
+    "image": 21,
+    "author": 13
+  },
+  {
+    "title": "I hope I didn't brain my damage.",
+    "description": "I don't like being outdoors, Smithers. For one thing, there's too many fat children. Oh, loneliness and cheeseburgers are a dangerous mix. Jesus must be spinning in his grave! I hope this has taught you kids a lesson: kids never learn.",
+    "image": 22,
+    "author": 14
+  }
+]

+ 0 - 34
src/pages/_data/articles.yml

@@ -1,34 +0,0 @@
-- title: And this isn't my nose. This is a false one.
-  description: Look, my liege! The Knights Who Say Ni demand a sacrifice! …Are you suggesting that coconuts migrate? Well, I got better.
-  image: 14
-  author: 3
-
-- title: Well, I didn't vote for you.
-  description: Well, we did do the nose. Why? Shut up! Will you shut up?! You don't frighten us, English pig-dogs! Go and boil your bottoms, sons of a silly person! I blow my nose at you, so-called Ah-thoor Keeng, you and all your silly English K-n-n-n-n-n-n-n-niggits!
-  image: 15
-  author: 4
-
-- title: How do you know she is a witch?
-  description: Are you suggesting that coconuts migrate? No, no, no! Yes, yes. A bit. But she's got a wart. You don't vote for kings. Ah, now we see the violence inherent in the system!
-  image: 16
-  author: 5
-
-- title: Shut up!
-  description: Burn her! How do you know she is a witch? You don't frighten us, English pig-dogs! Go and boil your bottoms, sons of a silly person! I blow my nose at you, so-called Ah-thoor Keeng, you and all your silly English K-n-n-n-n-n-n-n-niggits!
-  image: 17
-  author: 6
-
-- title: Weaseling out of things is important to learn.
-  description: Please do not offer my god a peanut. That's why I love elementary school, Edna. The children believe anything you tell them. Brace yourselves gentlemen. According to the gas chromatograph, the secret ingredient is… Love!? Who's been screwing with this thing?
-  image: 20
-  author: 12
-
-- title: You don't like your job, you don't strike.
-  description: "But, Aquaman, you cannot marry a woman without gills. You're from two different worlds… Oh, I've wasted my life. Son, when you participate in sporting events, it's not whether you win or lose: it's how drunk you get."
-  image: 21
-  author: 13
-
-- title: I hope I didn't brain my damage.
-  description: "I don't like being outdoors, Smithers. For one thing, there's too many fat children. Oh, loneliness and cheeseburgers are a dangerous mix. Jesus must be spinning in his grave! I hope this has taught you kids a lesson: kids never learn."
-  image: 22
-  author: 14

Some files were not shown because too many files changed in this diff