DEV Community

sium_hossain
sium_hossain

Posted on • Edited on

6 1

Vue-Nuxt remove html tags from rendered text for SEO

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.
text with html

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, "");
    }


Enter fullscreen mode Exit fullscreen mode

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
      }
    ],
  }


Enter fullscreen mode Exit fullscreen mode

Thank You 😎

SurveyJS custom survey software

Simplify data collection in your JS app with a fully integrated form management platform. Includes support for custom question types, skip logic, integrated CCS editor, PDF export, real-time analytics & more. Integrates with any backend system, giving you full control over your data and no user limits.

Learn more

Top comments (3)

Collapse
 
kissu profile image
Konstantin BIFERT

At the end, this one should probably be handled by the backend itself (if possible).
Thanks for the idea tho!

Collapse
 
siumhossain profile image
sium_hossain

you are absolutely right.. But it's fun doing some experiment. right ?

Collapse
 
kissu profile image
Konstantin BIFERT

Regex is always fun. 😉

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs