hexojs / hexo

A fast, simple & powerful blog framework, powered by Node.js.
https://hexo.io
MIT License
39.23k stars 4.83k forks source link

How to decode page.excerpt as description? #2543

Closed kiwenlau closed 4 years ago

kiwenlau commented 7 years ago

I'd like to add description meta in my blog page for SEO:

 <meta name="description" content="作为Node.js开发者,有必要全面了解一下Node命令的所有选项,这样在关键时刻才能得心应手。" >

I add following code in head.ejs

<meta name="description" content="<%= strip_html(page.excerpt) %>" >

But the result is unreadable:

 <meta name="description" content="&amp;#x8BD1;&amp;#x8005;&amp;#x6309;: &amp;#x4F5C;&amp;#x4E3A;Node.js&amp;#x5F00;&amp;#x53D1;&amp;#x8005;&amp;#xFF0C;&amp;#x6709;&amp;#x5FC5;&amp;#x8981;&amp;#x5168;&amp;#x9762;&amp;#x4E86;&amp;#x89E3;&amp;#x4E00;&amp;#x4E0B;Node&amp;#x547D;&amp;#x4EE4;&amp;#x7684;&amp;#x6240;&amp;#x6709;&amp;#x9009;&amp;#x9879;&amp;#xFF0C;&amp;#x8FD9;&amp;#x6837;&amp;#x5728;&amp;#x5173;&amp;#x952E;&amp;#x65F6;&amp;#x523B;&amp;#x624D;&amp;#x80FD;&amp;#x5F97;&amp;#x5FC3;&amp;#x5E94;&amp;#x624B;&amp;#x3002;" >

It seems not right because search engine may not understand it.

I tried to decode the content using http://www.cafewebmaster.com/online_tools/utf_decode. So the messy code is called "HTML entities decode".

How can I decode them in head.ejs to generate correct html?

neoFelhz commented 7 years ago

Hey, there is how hexo-theme-material make it: https://github.com/viosey/hexo-theme-material/commit/a4f6eabde6ad4e7eaae4cae9f5876e5ee9f7bd97 I use the replace to avoid the messy code. There is a demo: https://blog.nfz.moe

kiwenlau commented 7 years ago

@neoFelhz THX. But it does not work...

stevenjoezhang commented 4 years ago

Use open_graph helper.

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because lack of recent activity. It will be closed if no further activity occurs. Thank you for your contributions.