From 2b0c641c1e1d583e789fcf11f94e843619c273da Mon Sep 17 00:00:00 2001 From: Igor Kowalczyk Date: Fri, 19 Apr 2024 17:17:22 +0200 Subject: [PATCH] Update dependencies and apply code formatting changes --- .eslintrc.js | 31 ------- .vscode/settings.json | 2 +- eslint.config.mjs | 10 +++ package.json | 1 - prettier.config.mjs | 1 - src/components/Input.astro | 2 +- src/database/index.ts | 8 +- src/env.d.ts | 2 + src/layouts/Layout.astro | 3 +- src/pages/api/badge/[username].ts | 8 +- src/pages/api/json/[username].ts | 5 +- src/pages/index.astro | 132 +++++++++++++++--------------- src/styles/styles.css | 2 +- 13 files changed, 94 insertions(+), 113 deletions(-) delete mode 100644 .eslintrc.js create mode 100644 eslint.config.mjs diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index ad32efb4..00000000 --- a/.eslintrc.js +++ /dev/null @@ -1,31 +0,0 @@ -module.exports = { - extends: ["@igorkowalczyk/eslint-config/legacy", "plugin:astro/recommended"], - env: { - node: true, - es2022: true, - browser: true, - }, - parserOptions: { - ecmaVersion: "latest", - sourceType: "module", - }, - overrides: [ - { - files: ["*.astro"], - parser: "astro-eslint-parser", - parserOptions: { - parser: "@typescript-eslint/parser", - extraFileExtensions: [".astro"], - }, - }, - { - files: ["*.ts"], - parser: "@typescript-eslint/parser", - extends: ["plugin:@typescript-eslint/recommended"], - }, - { - files: ["**/*.astro/*.js", "*.astro/*.js"], - parser: "@typescript-eslint/parser", - }, - ], -}; diff --git a/.vscode/settings.json b/.vscode/settings.json index 53eca5e2..e5f2aea9 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,7 +2,7 @@ "markdown.validate.referenceLinks.enabled": "ignore", "eslint.validate": ["javascript", "javascriptreact", "typescript", "typescriptreact"], "editor.codeActionsOnSave": { - "source.fixAll.eslint": true + "source.fixAll.eslint": "explicit" }, "deno.enable": true } diff --git a/eslint.config.mjs b/eslint.config.mjs new file mode 100644 index 00000000..a233f372 --- /dev/null +++ b/eslint.config.mjs @@ -0,0 +1,10 @@ +import eslintConfig from "@igorkowalczyk/eslint-config/flat"; +import eslintPluginAstro from "eslint-plugin-astro"; + +export default [ + { + ignores: ["dist/"], + }, + ...eslintConfig, + ...eslintPluginAstro.configs["flat/recommended"], +]; diff --git a/package.json b/package.json index 6f7b7d59..a41956d3 100644 --- a/package.json +++ b/package.json @@ -51,7 +51,6 @@ "@typescript-eslint/parser": "7.7.0", "autoprefixer": "10.4.19", "eslint": "9.0.0", - "eslint-plugin": "^1.0.1", "eslint-plugin-astro": "0.34.0", "postcss": "8.4.38", "prettier": "3.2.5", diff --git a/prettier.config.mjs b/prettier.config.mjs index 1a756225..b75572d5 100644 --- a/prettier.config.mjs +++ b/prettier.config.mjs @@ -1,4 +1,3 @@ -/* eslint-disable global-require */ import config from "@igorkowalczyk/prettier-config"; export default { diff --git a/src/components/Input.astro b/src/components/Input.astro index 1d3e381c..7c067ad1 100644 --- a/src/components/Input.astro +++ b/src/components/Input.astro @@ -1,5 +1,5 @@ --- -const props = Astro.props; +const { props } = Astro; --- diff --git a/src/database/index.ts b/src/database/index.ts index a68669f2..ee26f41f 100644 --- a/src/database/index.ts +++ b/src/database/index.ts @@ -1,6 +1,6 @@ -import "./patch"; +import "./patch.ts"; -export async function IncreaseViews(username: string) { +export async function IncreaseViews(username: string): Promise { if (username === "example") return 0; const kv = await Deno.openKv(); await kv.atomic().sum([username], 1n).commit(); @@ -8,9 +8,9 @@ export async function IncreaseViews(username: string) { return Number(view.value || 0); } -export async function GetViews(username: string) { +export async function GetViews(username: string): Promise { if (username === "example") return 0; const kv = await Deno.openKv(); const view = await kv.get([username]); - return view.value || 0; + return (view.value as number) || 0; } diff --git a/src/env.d.ts b/src/env.d.ts index f964fe0c..3a96c993 100644 --- a/src/env.d.ts +++ b/src/env.d.ts @@ -1 +1,3 @@ /// +/// +/// diff --git a/src/layouts/Layout.astro b/src/layouts/Layout.astro index 26252315..695eab6f 100644 --- a/src/layouts/Layout.astro +++ b/src/layouts/Layout.astro @@ -4,6 +4,7 @@ export interface Props { } const { title } = Astro.props; +import { Image } from "astro:assets"; import "../styles/main.css"; --- @@ -44,7 +45,7 @@ import "../styles/main.css";
- Profile Views + Profile Views
diff --git a/src/pages/api/badge/[username].ts b/src/pages/api/badge/[username].ts index 152956c7..3e77f986 100644 --- a/src/pages/api/badge/[username].ts +++ b/src/pages/api/badge/[username].ts @@ -1,7 +1,7 @@ import { badgen } from "badgen"; import type { StyleOption } from "badgen"; -import { FormatNumber } from "../../../utils/FormatNumber"; -import { IncreaseViews, GetViews } from "@/database/index"; +import { FormatNumber } from "../../../utils/FormatNumber.ts"; +import { IncreaseViews, GetViews } from "../../../database/index.ts"; interface QueryParams { label?: string; @@ -17,7 +17,7 @@ export const GET = async function GET({ params, request }: { params: { username: const query = new URL(request.url).searchParams; const { label, labelColor, color, style, format, display }: QueryParams = Object.fromEntries(query); const { username } = params; - const number: number = display ? await GetViews(username) : await IncreaseViews(username); + const views: number = display ? await GetViews(username) : await IncreaseViews(username); // Validate the format to ensure it's "short" or "long" const isValidFormat = format === "short" || format === "long"; @@ -25,7 +25,7 @@ export const GET = async function GET({ params, request }: { params: { username: const badge = badgen({ label: label || "Views", labelColor: labelColor, - status: FormatNumber(number, isValidFormat ? format! : "short"), + status: FormatNumber(views, isValidFormat ? format! : "short"), color: color, style: style || "flat", }); diff --git a/src/pages/api/json/[username].ts b/src/pages/api/json/[username].ts index 5ca2ac68..3cc02c0e 100644 --- a/src/pages/api/json/[username].ts +++ b/src/pages/api/json/[username].ts @@ -1,7 +1,6 @@ -import type { APIRoute } from "astro"; -import { GetViews } from "@/database/index"; +import { GetViews } from "../../../database/index.ts"; -export const GET: APIRoute = async function GET({ params }: { params: { username: string } }): Promise { +export const GET = async function GET({ params }: { params: { username: string } }): Promise { try { const { username } = params; diff --git a/src/pages/index.astro b/src/pages/index.astro index 52a87f0a..a28b3838 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -4,7 +4,7 @@ import Header from "../components/Header.astro"; import Image from "../components/Image.astro"; import Input from "../components/Input.astro"; import Layout from "../layouts/Layout.astro"; -let url = "/api/badge/example"; +const url = "/api/badge/example"; --- @@ -22,71 +22,73 @@ let url = "/api/badge/example";
- - - - - - - - - - - - - - - - +
+
StyleDefault badgeColorCustom text & color
-
flat
-
- - - - - -
+ + + + + + + + + + + + + + + - - - - - - - -
StyleDefault badgeColorCustom text & color
+
flat
+
+ + + + + +
-
classic
-
- - - - - -
+ + +
classic
+ + + + + + + + + + + + + - - - - - - - - - - - - -

Looking for more customizations? @@ -118,7 +120,7 @@ let url = "/api/badge/example"; }); -