hexo-util icon indicating copy to clipboard operation
hexo-util copied to clipboard

Feature Request: Add an option to choose other slugify function

Open twang2218 opened this issue 7 years ago • 5 comments

The default slugize is very simple and fast, however, it's not that useful for CJK characters. Could you make it possible to choose another slugify function, such as https://github.com/andyhu/node-transliteration ?

twang2218 avatar Aug 19 '16 18:08 twang2218

Why don't you use other slugify function instead of this one? Do you want to change the default behavior of Hexo engine by assign anothor slugize function?

hcoona avatar Mar 06 '17 13:03 hcoona

I found that if the anchor point ID is in chinese, it will not jump normally.

<a class="post-toc-link" href="#3-散列算法"></a>

<h2 id="3-散列算法">...</h2>

I think a slugize is necessary to add chinese conversion methods, like the encodeURIComponent or translation.

mygu avatar Jun 22 '18 09:06 mygu

@mygu I recently worked on encodeURL() with support of anchor.

In the example that you gave, what is the expected value for h2 id? should it be,

<h2 id="3-%E6%95%A3%E5%88%97%E7%AE%97%E6%B3%95">...</h2>

curbengh avatar Sep 14 '19 08:09 curbengh

@curbengh Yes, it's looks good. :+1:

mygu avatar Oct 09 '19 09:10 mygu

I don't think encodeURI() can be added to slugize, otherwise hexo new post "散列算法" will result in the following front matter in the post,

title: %E6%95%A3%E5%88%97%E7%AE%97%E6%B3%95

In regards to your issue, I think encodeURI should be added to toc.js and hexo-renderer-marked instead.

Edit: I just tested

<html>
  <head></head>
  <body>
    <a href="#3-散列算法">Description of Same-Page Links</a>
  </br></br></br></br></br></br></br></br></br></br></br></br>
  </br></br></br></br></br></br></br></br></br></br></br></br>
  </br></br></br></br></br></br></br></br></br></br></br></br>
  </br></br></br></br></br></br></br></br></br></br></br></br>
  </br></br></br></br></br></br></br></br></br></br></br></br>
  </br></br></br></br></br></br></br></br></br></br></br></br>
  </br></br></br></br></br></br></br></br></br></br></br></br>
  </br></br></br></br></br></br></br></br></br></br></br></br>
  </br></br></br></br></br></br></br></br></br></br></br></br>
  </br></br></br></br></br></br></br></br></br></br></br></br>
  <h1 id="3-散列算法">Title</h1>
  </body>
</html>

works for me (Firefox).

Longer text example.

curbengh avatar Oct 09 '19 09:10 curbengh