Fix failing tests and add unit tests
This commit is contained in:
+17
-22
@@ -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");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user