Fix failing tests and add unit tests

This commit is contained in:
adilallo
2025-09-12 10:26:21 -06:00
parent 0f9bc0d74e
commit c8f63ca39a
14 changed files with 1833 additions and 89 deletions
+17 -22
View File
@@ -8,11 +8,24 @@ import { validateBlogPost, sanitizeBlogPost } from "./validation.js";
*/
/**
* Convert markdown content to HTML with basic formatting
* @param {string} markdown - Raw markdown content
* @returns {string} HTML content
* Generate a URL-friendly slug from a string
* @param {string} text - Text to convert to slug
* @returns {string} URL-friendly slug
*/
function markdownToHtml(markdown) {
function generateSlug(text) {
return text
.toLowerCase()
.replace(/[^\w\s-]/g, "") // Remove special characters
.replace(/\s+/g, "-") // Replace spaces with hyphens
.replace(/-+/g, "-") // Replace multiple hyphens with single
.trim();
}
/**
* Get all blog post files from the content directory
* @returns {Array} Array of file paths
*/
export function markdownToHtml(markdown) {
if (!markdown) return "";
return (
@@ -41,24 +54,6 @@ function markdownToHtml(markdown) {
);
}
/**
* Generate a URL-friendly slug from a string
* @param {string} text - Text to convert to slug
* @returns {string} URL-friendly slug
*/
function generateSlug(text) {
return text
.toLowerCase()
.replace(/[^\w\s-]/g, "") // Remove special characters
.replace(/\s+/g, "-") // Replace spaces with hyphens
.replace(/-+/g, "-") // Replace multiple hyphens with single
.trim();
}
/**
* Get all blog post files from the content directory
* @returns {Array} Array of file paths
*/
export function getBlogPostFiles() {
const contentDirectory = path.join(process.cwd(), "content/blog");