chiaweilee / umi-plugin-md

🍚 Markdown(*.md) component plugin for umi.
https://chiaweilee.github.io/umi-plugin-md/
MIT License
16 stars 2 forks source link

锚点和id是随机值 #9

Closed xiaohuoni closed 5 years ago

xiaohuoni commented 5 years ago

锚点和id是一个随机值,如果有需求上的冲突希望多一个配置,支持直接使用文本 image

和我生成的导航对应不上 image

chiaweilee commented 5 years ago

使用 https://github.com/bibig/node-shorthash 生成的 hash,可以考虑下

sh.unique('abcdefg')

xiaohuoni commented 5 years ago

使用 https://github.com/bibig/node-shorthash 生成的 hash,可以考虑下

sh.unique('abcdefg')

这是什么意思呢?

chiaweilee commented 5 years ago

使用 https://github.com/bibig/node-shorthash 生成的 hash,可以考虑下 sh.unique('abcdefg')

这是什么意思呢?

大概是这样子:

const text = $('h1').text(); const hash = sh.unique(text); $('h1').attr('id', hash);

xiaohuoni commented 5 years ago

你是说我需要这样定义路由,还是说你将要这么修改?

chiaweilee commented 5 years ago

你是说我需要这样定义路由,还是说你将要这么修改?

插件是按照这套规则生成的 id

xiaohuoni commented 5 years ago

我也按这个规则可以实现导航了。但是因为是随机数,链接里面没体现内容,不是很完美

chiaweilee commented 5 years ago

我最早选择 hash 的原因有 2 点:

不过这样似乎的确给一些目录的构造造成了困难,比如

https://github.com/mxstbr/markdown-test-file/blob/master/TEST.md

所以这一点可能还得调整