mirror of https://gitlab.com/curben/blog
34 lines
796 B
JavaScript
34 lines
796 B
JavaScript
'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.75em" viewBox="15 15 1635 1635">
|
|
<use href="/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()
|
|
})
|