https://github.com/inledgroup/astromdblog
https://github.com/inledgroup/astromdblog
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/inledgroup/astromdblog
- Owner: InledGroup
- License: other
- Created: 2025-09-27T07:34:47.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2026-04-04T14:25:08.000Z (about 2 months ago)
- Last Synced: 2026-04-04T16:52:27.573Z (about 2 months ago)
- Language: CSS
- Size: 13.7 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# astromdblog
Blog template for Astro using Markdown rendering.
Create your own blog with Astro and Markdown.
# How it works
In `pages/blog.astro`, blog entries are listed by calling the `BlogNews` component, which contains a list of entries in JavaScript.
The way to list them is as follows:
// News Section
const newsData = [
{
id: 1,
title: 'Blog new',
summary: 'summary',
date: '17-6-25',
category: 'tech',
image: 'path-to-your-img.png',
slug: 'blog-new'
}
];
As you add entries, you must update this list.
The posts are stored in `pages/blog/`, which is the page that calls the Markdown renderer `MarkdownRender` to render the Markdown document located in `public/blog`.
The structure of the blog page (in this case `undefined.astro`) is as follows:
// Convert Markdown to HTML
function markdownToHtml(markdown: string): string {
return markdown
// Headers
.replace(/^### (.*$)/gim, '$1
')
.replace(/^## (.*$)/gim, '$1
')
.replace(/^# (.*$)/gim, '$1
')
// Bold
.replace(/\*\*(.*)\*\*/gim, '$1')
// Italic
.replace(/\*(.*)\*/gim, '$1')
// Links
.replace(/\[([^\]]*)\]\(([^\)]*)\)/gim, '$1')
// Line breaks
.replace(/\n$/gim, '
')
// Paragraphs
.replace(/\n\n/gim, '')
.replace(/^(.*)$/gim, '
$1
')
// Clean up empty paragraphs
.replace(/<\/p>/gim, '')
.replace(/
<\/p>/gim, '');
}
// Read markdown file
const markdownPath = path.join(process.cwd(), 'public', 'blog', 'undefined.md');
let markdownContent = '';
try {
markdownContent = fs.readFileSync(markdownPath, 'utf-8');
} catch (error) {
console.error('Error reading markdown file:', error);
markdownContent = '# Error\n\nCould not load content.';
}
const htmlContent = markdownToHtml(markdownContent);
Where `const markdownPath = path.join(process.cwd(), 'public', 'blog', 'undefined.md');` is the constant that points to the Markdown document.
# Formatting to Markdown
To format in Markdown, you can use the first visual Markdown editor on GitHub [InMD](https://inmd.inled.es) or write in [MDPDF](https://mdpdf.inled.es) and previsualize the result.