This commit is contained in:
2025-06-19 13:40:31 +02:00
parent 24d03302b6
commit 60b66ef57c
9 changed files with 138 additions and 28 deletions

View File

@@ -7,9 +7,26 @@ import matter from 'gray-matter';
import { marked } from 'marked';
import DOMPurify from 'dompurify';
import { JSDOM } from 'jsdom';
import hljs from 'highlight.js';
const postsDirectory = path.join(process.cwd(), 'posts');
const renderer = new marked.Renderer();
renderer.code = (code, infostring, escaped) => {
const lang = (infostring || '').match(/\S*/)?.[0];
const highlighted = lang && hljs.getLanguage(lang)
? hljs.highlight(code, { language: lang }).value
: hljs.highlightAuto(code).value;
const langClass = lang ? `language-${lang}` : '';
return `<pre><code class="hljs ${langClass}">${highlighted}</code></pre>`;
};
marked.setOptions({
gfm: true,
breaks: true,
renderer,
});
// Function to get file creation date
function getFileCreationDate(filePath: string): Date {
const stats = fs.statSync(filePath);
@@ -25,12 +42,6 @@ async function getPostBySlug(slug: string) {
let processedContent = '';
try {
// Configure marked options
marked.setOptions({
gfm: true,
breaks: true
});
// Convert markdown to HTML
const rawHtml = marked.parse(content);