I am trying to add description in <head>
tag which is come from backed server via API. But in backend i have rich text editor which is generate text with html tag.
But i want to add only plain text in description for improving SEO performance. So here is the solution, i think you need it also π
In computed section we can declare a function which will responsible for generate plain text from mixed with html tag.
computed:{
strippedHtml() {
let regex = /(<([^>]+)>)/ig;
return this.description.replace(regex, "");
}
now display it in your template by {{strippedHtml}}
π
and you can add it also in
head: {
title: 'your title',
meta: [
{
hid: 'description',
name: 'description',
content: this.strippedHtml
}
],
}
Thank You π
Top comments (3)
At the end, this one should probably be handled by the backend itself (if possible).
Thanks for the idea tho!
you are absolutely right.. But it's fun doing some experiment. right ?
Regex is always fun. π