diff --git a/package.json b/package.json
index c7c7137..10acbc7 100644
--- a/package.json
+++ b/package.json
@@ -10,7 +10,7 @@
"preview": "astro preview",
"astro": "astro",
"format": "prettier -w .",
- "lint:eslint": "eslint .",
+ "lint": "eslint .",
"subfont": "subfont -ir --no-fallbacks --silent --root dist"
},
"devDependencies": {
diff --git a/src/components/common/MetaTags.astro b/src/components/common/MetaTags.astro
index c5fcdd1..7fd261a 100644
--- a/src/components/common/MetaTags.astro
+++ b/src/components/common/MetaTags.astro
@@ -44,7 +44,7 @@ const image =
typeof _image === 'string'
? new URL(_image, Astro.site)
: _image && typeof _image['src'] !== 'undefined'
- ? // @ts-ignore
+ ? // @ts-expect-error - TODO: Need to improve default image handling and types
new URL(getRelativeUrlByFilePath(_image.src), Astro.site)
: null;
---
diff --git a/src/env.d.ts b/src/env.d.ts
index acef35f..45786fb 100644
--- a/src/env.d.ts
+++ b/src/env.d.ts
@@ -1,2 +1,5 @@
+// eslint-disable-next-line @typescript-eslint/triple-slash-reference
///
///
+///
+///
diff --git a/src/utils/blog.ts b/src/utils/blog.ts
index f82b5a5..7e0a460 100644
--- a/src/utils/blog.ts
+++ b/src/utils/blog.ts
@@ -110,7 +110,6 @@ const load = async function (): Promise> {
let _posts: Array;
-/** */
export const isBlogEnabled = true;
export const isBlogListRouteEnabled = true;
export const isBlogPostRouteEnabled = true;
@@ -119,7 +118,6 @@ export const isBlogTagRouteEnabled = true;
export const blogPostsPerPage = 6;
-/** */
export const fetchPosts = async (): Promise> => {
if (!_posts) {
_posts = await load();
@@ -128,7 +126,6 @@ export const fetchPosts = async (): Promise> => {
return _posts;
};
-/** */
export const findPostsBySlugs = async (slugs: Array): Promise> => {
if (!Array.isArray(slugs)) return [];
@@ -142,7 +139,6 @@ export const findPostsBySlugs = async (slugs: Array): Promise): Promise> => {
if (!Array.isArray(ids)) return [];
@@ -156,7 +152,6 @@ export const findPostsByIds = async (ids: Array): Promise> =
}, []);
};
-/** */
export const findLatestPosts = async ({ count }: { count?: number }): Promise> => {
const _count = count ?? 4;
const posts = await fetchPosts();
@@ -164,7 +159,6 @@ export const findLatestPosts = async ({ count }: { count?: number }): Promise {
if (!isBlogEnabled || !isBlogListRouteEnabled) return [];
return paginate(await fetchPosts(), {
@@ -173,7 +167,6 @@ export const getStaticPathsBlogList = async ({ paginate }: { paginate: PaginateF
});
};
-/** */
export const getStaticPathsBlogPost = async () => {
if (!isBlogEnabled || !isBlogPostRouteEnabled) return [];
return (await fetchPosts()).flatMap((post) => ({
@@ -184,15 +177,16 @@ export const getStaticPathsBlogPost = async () => {
}));
};
-/** */
export const getStaticPathsBlogCategory = async ({ paginate }: { paginate: PaginateFunction }) => {
if (!isBlogEnabled || !isBlogCategoryRouteEnabled) return [];
const posts = await fetchPosts();
const categories = new Set();
- posts.map((post: Post) => {
- typeof post.category === 'string' && categories.add(post.category.toLowerCase());
- });
+ for (const post of posts) {
+ if (typeof post.category === 'string') {
+ categories.add(post.category.toLowerCase());
+ }
+ }
return Array.from(categories).flatMap((category: string) =>
paginate(
@@ -209,15 +203,18 @@ export const getStaticPathsBlogCategory = async ({ paginate }: { paginate: Pagin
);
};
-/** */
export const getStaticPathsBlogTag = async ({ paginate }: { paginate: PaginateFunction }) => {
if (!isBlogEnabled || !isBlogTagRouteEnabled) return [];
const posts = await fetchPosts();
const tags = new Set();
- posts.map((post: Post) => {
- Array.isArray(post.tags) && post.tags.map((tag) => tags.add(tag.toLowerCase()));
- });
+ for (const post of posts) {
+ if (Array.isArray(post.tags)) {
+ for (const tag of post.tags) {
+ tags.add(tag.toLowerCase());
+ }
+ }
+ }
return Array.from(tags).flatMap((tag: string) =>
paginate(
diff --git a/src/utils/images-optimization.ts b/src/utils/images-optimization.ts
index cf9e694..b8c89d7 100644
--- a/src/utils/images-optimization.ts
+++ b/src/utils/images-optimization.ts
@@ -5,7 +5,7 @@ import type { HTMLAttributes } from 'astro/types';
type Layout = 'fixed' | 'constrained' | 'fullWidth' | 'cover' | 'responsive' | 'contained';
-export interface AttributesProps extends HTMLAttributes<'img'> {}
+export type AttributesProps = HTMLAttributes<'img'>;
export interface ImageProps extends Omit, 'src'> {
src?: string | ImageMetadata | null;
diff --git a/src/utils/images.ts b/src/utils/images.ts
index 3eadbb6..665bca9 100644
--- a/src/utils/images.ts
+++ b/src/utils/images.ts
@@ -9,20 +9,18 @@ const load = async function () {
'~/assets/images/**/*.{jpeg,jpg,png,tiff,webp,gif,svg,JPEG,JPG,PNG,TIFF,WEBP,GIF,SVG}'
);
} catch (e) {
- // continue regardless of error
+ console.error('Error loading images:', e);
}
return images;
};
let _images: Record Promise> | undefined = undefined;
-/** */
export const fetchLocalImages = async () => {
_images = _images || (await load());
return _images;
};
-/** */
export const findImage = async (
imagePath?: string | ImageMetadata | null
): Promise => {
@@ -53,7 +51,6 @@ export const findImage = async (
: null;
};
-/** */
export const adaptOpenGraphImages = async (
openGraph: OpenGraph = {},
astroSite: URL | undefined = new URL('')
@@ -66,14 +63,15 @@ export const adaptOpenGraphImages = async (
const defaultWidth = 1200;
const defaultHeight = 626;
+ // TODO: Refactor
const adaptedImages = await Promise.all(
images.map(async (image: OpenGraphMedia) => {
if (image?.url) {
- const resolvedImage = (await findImage(image.url)) as ImageMetadata | undefined;
+ const resolvedImage = await findImage(image.url);
if (!resolvedImage) {
return {
url: '',
- };
+ } satisfies OpenGraphMedia;
}
const _image = await getImage({
@@ -86,18 +84,19 @@ export const adaptOpenGraphImages = async (
if (typeof _image === 'object') {
return {
url: typeof _image.src === 'string' ? String(new URL(_image.src, astroSite)) : 'pepe',
- width: typeof _image.options.width === 'number' ? _image.options.width : undefined,
- height: typeof _image.options.height === 'number' ? _image.options.height : undefined,
- };
+ width: typeof _image.options.width === 'number' ? _image.options.width : defaultWidth,
+ height:
+ typeof _image.options.height === 'number' ? _image.options.height : defaultHeight,
+ } satisfies OpenGraphMedia;
}
return {
url: '',
- };
+ } satisfies OpenGraphMedia;
}
return {
url: '',
- };
+ } satisfies OpenGraphMedia;
})
);
diff --git a/src/utils/permalinks.ts b/src/utils/permalinks.ts
index 70a1282..c2d44c0 100644
--- a/src/utils/permalinks.ts
+++ b/src/utils/permalinks.ts
@@ -24,12 +24,10 @@ export const BLOG_BASE = cleanSlug('blog');
export const CATEGORY_BASE = cleanSlug('category');
export const TAG_BASE = cleanSlug('tag') || 'tag';
-export const POST_PERMALINK_PATTERN = trimSlash('/blog/%slug%' || `${BLOG_BASE}/%slug%`);
+export const POST_PERMALINK_PATTERN = trimSlash(`${BLOG_BASE}/%slug%`);
-/** */
export const getCanonical = (path = ''): string | URL => new URL(path, SITE.origin);
-/** */
export const getPermalink = (slug = '', type = 'page'): string => {
let permalink: string;
@@ -55,13 +53,10 @@ export const getPermalink = (slug = '', type = 'page'): string => {
return definitivePermalink(permalink);
};
-/** */
export const getHomePermalink = (): string => getPermalink('/');
-/** */
export const getBlogPermalink = (): string => getPermalink(BLOG_BASE);
-/** */
export const getAsset = (path: string): string =>
'/' +
[BASE_PATHNAME, path]
@@ -69,5 +64,4 @@ export const getAsset = (path: string): string =>
.filter((el) => !!el)
.join('/');
-/** */
const definitivePermalink = (permalink: string): string => createPath(BASE_PATHNAME, permalink);
diff --git a/tsconfig.json b/tsconfig.json
index 6ccfbaf..6b21b15 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -1,13 +1,14 @@
{
"extends": "astro/tsconfigs/strictest",
"compilerOptions": {
- "jsx": "react-jsx",
"allowJs": true,
"checkJs": true,
"baseUrl": ".",
+ "strictNullChecks": true,
"paths": {
"~/*": ["src/*"]
- },
- "jsxImportSource": "react"
- }
+ }
+ },
+ "include": [".astro/types.d.ts", "**/*"],
+ "exclude": ["dist/"]
}