Skip to content

Commit

Permalink
Update README and enhance blog metadata generation; change app title;…
Browse files Browse the repository at this point in the history
… add badges for technologies used; implement date validation in metadata retrieval; ensure proper handling of created and updated dates.
  • Loading branch information
wyattowalsh committed Nov 23, 2024
1 parent 1cfbeea commit db92cec
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 19 deletions.
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
# `w4w.dev`
### *My Place on the Web* 🕸️🤖
### *My Personal Web App* 🤖✨

---

<p>
![GitHub commit activity](https://img.shields.io/github/commit-activity/t/wyattowalsh/personal-website?style=for-the-badge&logo=github)
![Website](https://img.shields.io/website?url=https%3A%2F%2Fw4w.dev)
[![Vercel](https://img.shields.io/badge/hosted_on-Vercel-000?logo=vercel&style=for-the-badge)](https://vercel.com)
[![Next.js](https://img.shields.io/badge/Next.js-15-000?logo=next.js&logoColor=white&style=for-the-badge)](https://nextjs.org)
[![TypeScript](https://img.shields.io/badge/TypeScript-v4+-3178C6?logo=typescript&style=for-the-badge)](https://www.typescriptlang.org)
[![TailwindCSS](https://img.shields.io/badge/TailwindCSS-v3-06B6D4?logo=tailwindcss&style=for-the-badge)](https://tailwindcss.com)
[![shadcn/ui](https://img.shields.io/badge/shadcn/ui-stable-000?style=for-the-badge)](https://ui.shadcn.dev)
[![MDX](https://img.shields.io/badge/MDX-v2-000?logo=mdx&style=for-the-badge)](https://mdxjs.com)
[![Giscus](https://img.shields.io/badge/Giscus-enabled-9B83FF?logo=github&style=for-the-badge)](https://giscus.app)
[![YOURLS](https://img.shields.io/badge/YOURLS-v1.9+-3178C6?logo=link&style=for-the-badge)](https://yourls.org)
[![npm](https://img.shields.io/npm/v/next?label=npm&logo=npm&style=for-the-badge)](https://www.npmjs.com/package/next)
<p>

---

Expand Down Expand Up @@ -71,9 +84,10 @@
| **[remark-validate-links](https://github.com/remarkjs/remark-validate-links)** | MDX Plugin | Validates links in MDX content to ensure they are functional. | [GitHub Repository](https://github.com/remarkjs/remark-validate-links) |
| **[eslint-plugin-mdx](https://github.com/mdx-js/eslint-plugin-mdx)** | Linting Plugin | An ESLint plugin that adds support for linting MDX and JSX within Markdown files. | [GitHub Repository](https://github.com/mdx-js/eslint-plugin-mdx) |


---

<div align='center'>
<img height=35 src="https://github.com/user-attachments/assets/d14e9e05-b1a5-4b24-a8da-862453a01641"/>
</div>

---
44 changes: 27 additions & 17 deletions scripts/generateBlogMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ interface PostMetadata {
};
}

function isValidDate(dateString: string | null): boolean {
if (!dateString) return false;
const date = new Date(dateString);
return !isNaN(date.getTime());
}

async function getAllMdxFiles(dir: string, files: string[] = []): Promise<string[]> {
const entries = await fs.readdir(dir, { withFileTypes: true });

Expand Down Expand Up @@ -74,17 +80,17 @@ async function getFileGitDates(filePath: string) {
`git log -1 --format=%aI "${filePath}"`
);

// Ensure dates are valid ISO strings or return null
const createdDate = created.trim() ? new Date(created.trim()).toISOString() : null;
const updatedDate = updated.trim() ? new Date(updated.trim()).toISOString() : null;
// Clean and validate dates
const createdDate = created.trim();
const updatedDate = updated.trim();

return {
created: createdDate,
updated: updatedDate
created: isValidDate(createdDate) ? createdDate : null,
updated: isValidDate(updatedDate) ? updatedDate : undefined // Convert null to undefined
};
} catch (error) {
console.warn(`Failed to get git dates for ${filePath}:`, error);
return { created: null, updated: null };
return { created: null, updated: undefined }; // Convert null to undefined
}
}

Expand Down Expand Up @@ -116,24 +122,28 @@ async function generateMetadata() {
// Get git dates
const gitDates = await getFileGitDates(file);

// Ensure dates are in ISO format
const created = data.created
? new Date(data.created).toISOString()
: gitDates.created
? gitDates.created
: fileStats.birthtime.toISOString();
// Ensure we have a valid created date
let created = data.created;
if (!isValidDate(created)) {
created = gitDates.created;
if (!isValidDate(created)) {
created = fileStats.birthtime.toISOString();
}
}

const updated = gitDates.updated
? gitDates.updated
: fileStats.mtime.toISOString();
// Ensure we have a valid updated date or undefined
let updated = gitDates.updated;
if (!isValidDate(updated)) {
updated = fileStats.mtime.toISOString();
}

slugs.push(slug);
metadata[slug] = {
slug,
title: data.title,
summary: data.summary || '',
created,
updated,
updated, // This will now be string | undefined
date: created, // Keep for compatibility
tags: data.tags || [],
image: data.image,
Expand All @@ -142,7 +152,7 @@ async function generateMetadata() {
readingTime: stats.text,
};

console.log(`Processed metadata for: ${slug}`);
console.log(`Processed metadata for: ${slug} (created: ${created})`);
}));

// Sort slugs by created date
Expand Down

0 comments on commit db92cec

Please sign in to comment.