// src/routes/articles/[slug].tsx
import { component$, Resource, useResource$, useStore } from '@builder.io/qwik';
import { type DocumentHead, useLocation } from '@builder.io/qwik-city';
import { marked } from "marked";
import articles from '~/data/articles';
import styles from './article.module.css';
export default component$(() => {
const location = useLocation();
const store = useStore({ article: null, notFound: false });
const slug = location.params.slug;
const article = articles.find(a => a.slug === slug);
// useDocumentHead(() => {
// if (!article) {
// return {
// title: '404 Not Found | Your Site Name',
// meta: [{ name: 'description', content: 'The requested article was not found.' }],
// };
// }
// return {
// title: `${article.title} | Your Site Name`,
// meta: [{ name: 'description', content: article.description }],
// };
// });
const parseMarkdown = (text: string | undefined): string => {
if (!text) return '';
// Custom renderer
const renderer = new marked.Renderer();
// Override function to handle headings
renderer.heading = (text, level) => {
const escapedText = text.toLowerCase().replace(/[^\w]+/g, '-');
return `${text}`;
};
// Override function to handle links
renderer.link = (href, title, text) => {
if (href.startsWith('/')) {
href = `https://github.com/Lissy93/personal-security-checklist/blob/old-version/${href}`;
}
title = title ? `title="${title}"` : '';
return `${text}`;
};
// Sanitize the input to remove