I've been working on a blogging platform with Vue that serves Markdown (*.md) files for posts. My goal is to display a list of published posts on the main page along with a preview of the first 30 words of each post. Currently, I have a function that utilizes front-matter
to extract metadata from the file header and postData
to retrieve the Markdown content:
import fm from "front-matter";
function postPreview() {
var fmData = fm(postData).body;
var words = fmData.split(" ");
return words.slice(0, 30).join(" ");
}
The issue arises when images or links are included in the Markdown, as I only want to show the plain text. For instance, if the Markdown contains:
![alt-text...](link-to-some-picture) Here is a [link](link-to-some-website) in my file.
The preview should display as:
Here is a link in my file.
Do you know of any libraries that could help achieve this?