w1n78
w1n78

Reputation: 789

How do you remove markdown when using strip_html for meta description in Jekyll?

i'm trying to use the following code to generate my meta description tag

<meta name="description" content="{{ page.content | strip_html | truncatewords: 50 }}">

but this is what's displayed

##Sending Several Documents to a Group## Using online storage accounts like [Dropbox](http://dropbox.com)

is there a way to also strip markdown tags?

Upvotes: 1

Views: 1567

Answers (1)

David Jacquel
David Jacquel

Reputation: 52799

You can do a :

<meta name="description" 
content="{{ page.content | markdownify | strip_html | truncatewords: 50 }}">

But it will only works with md/markdown files, not html. And this will not render Liquid tags.

The solution can be to set a description: foo bar in the page/post front matter and get it in _includes/head.html with a :

{% if page.description %}
    <meta name="description" content="{{ page.description }}">
{% else %}
    <meta name="description" content="{{ site.description }}">
{% endif %}

Upvotes: 10

Related Questions