An open API service indexing awesome lists of open source software.

https://github.com/inledgroup/astromdblog


https://github.com/inledgroup/astromdblog

Last synced: about 1 month ago
JSON representation

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.