mirror of https://gitlab.com/curben/blog
feat: add a link button next to a heading
inspired by MDN Web Docs https://developer.mozilla.org/en-US/
This commit is contained in:
parent
a5dbc691ee
commit
5e40a69534
|
@ -0,0 +1,34 @@
|
||||||
|
'use strict'
|
||||||
|
/* global hexo */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Add Link button next to a heading
|
||||||
|
* cheerio is provided by hexo package
|
||||||
|
*/
|
||||||
|
|
||||||
|
const cheerio = require('cheerio')
|
||||||
|
|
||||||
|
hexo.extend.filter.register('after_render:html', (str) => {
|
||||||
|
const $ = cheerio.load(str)
|
||||||
|
const svg = `<svg height="0.8em" viewBox="15 15 1635 1635">
|
||||||
|
<desc>Link icon</desc>
|
||||||
|
<use href="/hexo-testing/svg/link.svg#link"/>
|
||||||
|
</svg>`
|
||||||
|
|
||||||
|
const headings = ['h2', 'h3']
|
||||||
|
|
||||||
|
headings.forEach(heading => {
|
||||||
|
$(heading).each((index, element) => {
|
||||||
|
if ($(element).children('a').children('svg').length === 0) {
|
||||||
|
const text = $(element).text().trim()
|
||||||
|
|
||||||
|
$(element).append($(element).children('a').append(svg))
|
||||||
|
|
||||||
|
const cache = $(element).children()
|
||||||
|
$(element).text(text + ' ').append(cache)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
return $.html()
|
||||||
|
})
|
|
@ -0,0 +1 @@
|
||||||
|
<svg id="link" xmlns="http://www.w3.org/2000/svg" viewBox="15 15 1635 1635"><path d="M1456 1216c0-26-10-50-28-68l-208-208c-18-18-43-28-68-28-29 0-52 11-72 32 33 33 72 61 72 112 0 53-43 96-96 96-51 0-79-39-112-72-21 20-33 43-33 73 0 25 10 50 28 68l206 207c18 18 43 27 68 27s50-9 68-26l147-146c18-18 28-42 28-67zM753 511c0-25-10-50-28-68L519 236c-18-18-43-28-68-28s-50 10-68 27L236 381c-18 18-28 42-28 67 0 26 10 50 28 68l208 208c18 18 43 27 68 27 29 0 52-10 72-31-33-33-72-61-72-112 0-53 43-96 96-96 51 0 79 39 112 72 21-20 33-43 33-73zm895 705c0 76-31 150-85 203l-147 146c-54 54-127 83-203 83-77 0-150-30-204-85l-206-207c-54-54-83-127-83-203 0-79 32-154 88-209l-88-88c-55 56-129 88-208 88-76 0-150-30-204-84L100 652c-55-55-84-127-84-204 0-76 31-150 85-203L248 99c54-54 127-83 203-83 77 0 150 30 204 85l206 207c54 54 83 127 83 203 0 79-32 154-88 209l88 88c55-56 129-88 208-88 76 0 150 30 204 84l208 208c55 55 84 127 84 204z"/></svg>
|
After Width: | Height: | Size: 931 B |
Loading…
Reference in New Issue