summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDawid Rycerz <dawid@rycerz.xyz>2025-07-03 18:23:00 +0300
committerDawid Rycerz <dawid@rycerz.xyz>2025-07-03 18:23:00 +0300
commit78461649639dba10f9ade8b1dba9e8f2c69a4144 (patch)
treefc89a83ecc5c8500c77ebc359fd7b7b2b42f085b
parent0df973de7b554008383a23fd4fc2a0b8e1401b37 (diff)
Add husky pre-commit
-rwxr-xr-x.husky/pre-commit54
-rw-r--r--package.json5
-rw-r--r--pnpm-lock.yaml10
-rw-r--r--src/loaders/pleroma.ts29
-rw-r--r--src/plugins/remark-admonitions.ts2
-rw-r--r--src/styles/global.css1
6 files changed, 86 insertions, 15 deletions
diff --git a/.husky/pre-commit b/.husky/pre-commit
new file mode 100755
index 0000000..32f797b
--- /dev/null
+++ b/.husky/pre-commit
@@ -0,0 +1,54 @@
+echo "🔍 Running pre-commit checks..."
+
+# Run lint
+echo "📋 Running lint..."
+pnpm run lint
+if [ $? -ne 0 ]; then
+ echo "❌ Lint failed"
+ exit 1
+fi
+
+# Run format
+echo "🎨 Running format..."
+pnpm run format
+if [ $? -ne 0 ]; then
+ echo "❌ Format failed"
+ exit 1
+fi
+
+# Run format:code
+echo "🎨 Running format:code..."
+pnpm run format:code
+if [ $? -ne 0 ]; then
+ echo "❌ Format:code failed"
+ exit 1
+fi
+
+# Run format:imports
+echo "📦 Running format:imports..."
+pnpm run format:imports
+if [ $? -ne 0 ]; then
+ echo "❌ Format:imports failed"
+ exit 1
+fi
+
+# Run check
+echo "✅ Running check..."
+pnpm run check
+if [ $? -ne 0 ]; then
+ echo "❌ Check failed"
+ exit 1
+fi
+
+# Check if dist directory exists before running lychee
+if [ -d "dist" ]; then
+ echo "🔗 Running lychee check on dist directory..."
+ lychee src/content --no-progress --exclude-private --max-retries 1 --timeout 10
+ if [ $? -ne 0 ]; then
+ echo "⚠️ Lychee found broken links (this won't block the commit)"
+ fi
+else
+ echo "⚠️ Dist directory not found, skipping lychee check"
+fi
+
+echo "✅ All pre-commit checks passed!"
diff --git a/package.json b/package.json
index 6bd0020..d5f4237 100644
--- a/package.json
+++ b/package.json
@@ -12,7 +12,9 @@
"format": "pnpm run format:code && pnpm run format:imports",
"format:code": "biome format . --write && prettier -w \"**/*\" \"!**/*.{md,mdx}\" --ignore-unknown --cache",
"format:imports": "biome check --formatter-enabled=false --write",
- "check": "astro check"
+ "check": "astro check",
+ "prepare": "husky",
+ "test:pre-commit": ".husky/pre-commit"
},
"dependencies": {
"@astrojs/markdown-remark": "^6.3.2",
@@ -54,6 +56,7 @@
"@types/mdast": "^4.0.4",
"@types/turndown": "^5.0.5",
"autoprefixer": "^10.4.21",
+ "husky": "^9.1.7",
"pagefind": "^1.3.0",
"prettier": "^3.6.2",
"prettier-plugin-astro": "0.14.1",
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 90166a8..dd1aabb 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -123,6 +123,9 @@ importers:
autoprefixer:
specifier: ^10.4.21
version: 10.4.21(postcss@8.5.3)
+ husky:
+ specifier: ^9.1.7
+ version: 9.1.7
pagefind:
specifier: ^1.3.0
version: 1.3.0
@@ -1810,6 +1813,11 @@ packages:
http-cache-semantics@4.2.0:
resolution: {integrity: sha512-dTxcvPXqPvXBQpq5dUr6mEMJX4oIEFv6bwom3FDwKRDsuIjjJGANqhBuoAn9c1RQJIdAKav33ED65E2ys+87QQ==}
+ husky@9.1.7:
+ resolution: {integrity: sha512-5gs5ytaNjBrh5Ow3zrvdUUY+0VxIuWVL4i9irt6friV+BqdCfmV11CQTWMiBYWHbXhco+J1kHfTOUkePhCDvMA==}
+ engines: {node: '>=18'}
+ hasBin: true
+
iconv-lite@0.6.3:
resolution: {integrity: sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==}
engines: {node: '>=0.10.0'}
@@ -5266,6 +5274,8 @@ snapshots:
http-cache-semantics@4.2.0: {}
+ husky@9.1.7: {}
+
iconv-lite@0.6.3:
dependencies:
safer-buffer: 2.1.2
diff --git a/src/loaders/pleroma.ts b/src/loaders/pleroma.ts
index feb11c8..952e491 100644
--- a/src/loaders/pleroma.ts
+++ b/src/loaders/pleroma.ts
@@ -1,7 +1,7 @@
import type { Loader } from "astro/loaders";
import { XMLParser } from "fast-xml-parser";
-import TurndownService from "turndown";
import { marked } from "marked";
+import TurndownService from "turndown";
interface PleromaFeedConfig {
instanceUrl: string;
@@ -199,12 +199,12 @@ function markdownToHtml(markdown: string): string {
breaks: true, // Convert line breaks to <br>
gfm: true, // GitHub flavored markdown
});
-
+
// Convert markdown to HTML
const html = marked.parse(markdown);
-
+
// Return as string (marked.parse can return string or Promise<string>)
- return typeof html === 'string' ? html : '';
+ return typeof html === "string" ? html : "";
}
function extractTitle(content: string): string {
@@ -259,7 +259,7 @@ export function pleromaLoader(config: PleromaFeedConfig): Loader {
if (response.ok) {
break; // Success, exit retry loop
}
- throw new Error(`HTTP ${response.status}: ${response.statusText}`);
+ throw new Error(`HTTP ${response.status}: ${response.statusText}`);
} catch (error) {
lastError = error;
logger.warn(`Attempt ${attempt} failed: ${error}`);
@@ -312,16 +312,19 @@ export function pleromaLoader(config: PleromaFeedConfig): Loader {
const postId = entry.id.split("/").pop() || entry.id;
// Extract source URL from the entry
- const sourceUrl = entry.link?.find(link => link["@_rel"] === "alternate")?.["@_href"] || entry.id;
+ const sourceUrl =
+ entry.link?.find((link) => link["@_rel"] === "alternate")?.["@_href"] || entry.id;
// Extract image attachments
- const attachments = entry.link?.filter(link =>
- link["@_rel"] === "enclosure" &&
- link["@_type"]?.startsWith("image/")
- ).map(link => ({
- url: link["@_href"],
- type: link["@_type"]
- })) || [];
+ const attachments =
+ entry.link
+ ?.filter(
+ (link) => link["@_rel"] === "enclosure" && link["@_type"]?.startsWith("image/"),
+ )
+ .map((link) => ({
+ url: link["@_href"],
+ type: link["@_type"],
+ })) || [];
// Create note entry
store.set({
diff --git a/src/plugins/remark-admonitions.ts b/src/plugins/remark-admonitions.ts
index 1f718ca..09bb284 100644
--- a/src/plugins/remark-admonitions.ts
+++ b/src/plugins/remark-admonitions.ts
@@ -49,7 +49,7 @@ function transformUnhandledDirective(
}
/** From Astro Starlight: Function that generates an mdast HTML tree ready for conversion to HTML by rehype. */
-// biome-ignore lint/suspicious/noExplicitAny: <explanation>
+// biome-ignore lint/suspicious/noExplicitAny: mdast types require any for flexibility
function h(el: string, attrs: Properties = {}, children: any[] = []): P {
const { properties, tagName } = _h(el, attrs);
return {
diff --git a/src/styles/global.css b/src/styles/global.css
index bf46988..5f5cdb6 100644
--- a/src/styles/global.css
+++ b/src/styles/global.css
@@ -42,6 +42,7 @@
}
@view-transition {
+ /* biome-ignore lint/correctness/noUnknownProperty: View Transitions API property */
navigation: auto;
}