2 Komitmen ae7fe72109 ... 2dae2feb67

Pembuat SHA1 Pesan Tanggal
  Vladislav Atakhanov 2dae2feb67 feat: projects sorting 9 bulan lalu
  Vladislav Atakhanov b4ecf843ce content: finance-telegram-bot 9 bulan lalu

+ 25 - 16
src/api/projects.ts

@@ -1,5 +1,9 @@
 import type { MarkdownInstance } from "astro"
-import { compareByHas } from "src/utils/compare-by-has"
+import { readFileSync } from "node:fs"
+import { dirname, join } from "node:path"
+import { fileURLToPath } from "node:url"
+
+const __dirname = dirname(fileURLToPath(import.meta.url))
 
 interface Image {
 	src: string
@@ -29,22 +33,27 @@ export type PageProject = MarkdownInstance<
 
 export type Project = BaseProject | PageProject
 
-export const sortProjects = (files: any[]): Project[] =>
-	files.sort(({ frontmatter: a }, { frontmatter: b }) => {
-		if (compareByHas(a, b, "index") !== 0)
-			return compareByHas(a, b, "index")
-
-		if (compareByHas(a, b, "date") !== 0) return compareByHas(a, b, "date")
-		if (compareByHas(a, b, "time") !== 0) return compareByHas(a, b, "time")
-
-		if (a.date && b.date) {
-			const aDate = new Date(a.date)
-			const bDate = new Date(b.date)
-			return bDate.getMilliseconds() - aDate.getMilliseconds()
-		}
-
-		return 0
+const getId = ({ file }: MarkdownInstance<any>) =>
+	file.split("/").pop()?.slice(0, -3)
+
+export const sortProjects = (files: any[]): Project[] => {
+	const result = new Array(files.length)
+	const sorting = readFileSync(
+		join(dirname(__dirname), "content", "projects", "projects.txt"),
+		{ encoding: "utf-8" }
+	)
+		.split("\n")
+		.map((line) => line.trim())
+
+	files.forEach((file) => {
+		const id = getId(file)
+		if (!id) return
+		const index = sorting.indexOf(id)
+		if (index < 0) return result.push(file)
+		result[index] = file
 	})
+	return result
+}
 
 export const isProjectLink = (href: string) => href.startsWith("/")
 

+ 5 - 0
src/assets/icons.svg

@@ -154,5 +154,10 @@
 			stroke-linejoin="round" />
 	</symbol>
 
+	<symbol id="bot" viewBox="0 0 24 24">
+		<path fill="#5478b6" fill-rule="nonzero"
+			d="M17.8 14c1.2 0 2.2 1 2.2 2.2v1c0 1-.5 2-1.3 2.8a10 10 0 0 1-6.7 2c-2.9 0-5.1-.7-6.7-2A3.7 3.7 0 0 1 4 17.2v-1C4 15 5 14 6.3 14h11.5ZM11.9 2h.1c.4 0 .7.3.7.6V3.5h3.6c1.2 0 2.2 1 2.2 2.3v4.5c0 1.2-1 2.2-2.3 2.2H7.8c-1.3 0-2.3-1-2.3-2.2V5.7c0-1.2 1-2.2 2.3-2.2h3.4v-.7c0-.4.3-.7.7-.8h.1-.1ZM9.7 6.5a1.2 1.2 0 1 0 0 2.5 1.2 1.2 0 0 0 0-2.5Zm4.5 0a1.2 1.2 0 1 0 0 2.5 1.2 1.2 0 0 0 0-2.5Z" />
+	</symbol>
+
 
 </svg>

+ 21 - 0
src/content/projects/finance-telegram-bot.md

@@ -0,0 +1,21 @@
+---
+link: https://t.me/qpuHaHcbI_bot
+title: Finance Telegram Bot
+color: "#00b93a"
+
+links:
+  - icon: code
+    href: https://github.com/vladislav-atakhanov/finance-telegram-bot/
+    title: Исходный код
+  - icon: bot
+    href: https://t.me/qpuHaHcbI_bot
+    title: Перейти в бота
+---
+
+Телеграм-бот для учёта расходов. Он может вести учёт всех покупок,
+присваивать им категории, выдавать отчёт о тратах за последний месяц.
+Есть возможность вести общий бюджет, добавив бота в группу.
+
+- node-telegram-bot-api
+- JavaScript
+- SQLite3

+ 0 - 1
src/content/projects/inshot24.md

@@ -3,7 +3,6 @@ link: https://whimsical-fairy-ef18fe.netlify.app/
 title: INSHOT24
 color: "#101010"
 time: 18 часов
-date: 2023-11-24
 
 links:
   - icon: site

+ 7 - 0
src/content/projects/projects.txt

@@ -0,0 +1,7 @@
+univer
+smart-hotels
+inshot24
+finance-telegram-bot
+demonster
+green-karaganda
+reader

+ 0 - 1
src/content/projects/smart-hotels.md

@@ -3,7 +3,6 @@ link: https://smarthotels.co.il/
 title: Smart Hotels
 time: 80 часов
 color: "#0e86d4"
-date: 2023-10-01
 
 links:
   - icon: site

+ 0 - 1
src/content/projects/univer.md

@@ -2,7 +2,6 @@
 link: https://univer.eloh1m.com/
 title: Univer
 color: "#7f67be"
-index: 0
 
 links:
   - icon: more

+ 0 - 13
src/utils/compare-by-has.ts

@@ -1,13 +0,0 @@
-type Object = Record<string, unknown>
-const objectHasKey = <T extends Object>(object: T, key: keyof T): boolean =>
-	key in object
-const objectHasntKey = <T extends Object>(object: T, key: keyof T): boolean =>
-	key in object === false
-
-export const compareByHas = <T extends Object>(a: T, b: T, key: keyof T) => {
-	const has = (obj: T) => objectHasKey(obj, key)
-	const hasnot = (obj: T) => objectHasntKey(obj, key)
-	if (has(a) && hasnot(b)) return -1
-	if (has(b) && hasnot(a)) return 1
-	return 0
-}