giuem / hexo-filter-crossorigin

Append crossorigin attribute to HTML elements
MIT License
1 stars 0 forks source link

Shouldn't process all <link> elements #6

Closed SukkaW closed 4 years ago

SukkaW commented 4 years ago

https://runkit.com/sukkaw/5dd424854e2cde0013e84050

const appendAttr = require('hexo-filter-crossorigin/lib/appendAttr.js');
require('chai').should();

const tags = [
    { "name": "link", "crossorigin": true }
];

const html_1 = '<link rel="preconnect" href="//cdn.jsdelivr.net">';
const html_2 = '<link href="https://blog.skk.moe/" rel="canonical">';

const expected_1 = '<link rel="preconnect" href="//cdn.jsdelivr.net" crossorigin="anonymous">';
const expected_2 = html_2;

appendAttr.default(html_1, tags).should.eql(expected_1);
appendAttr.default(html_2, tags).should.eql(expected_2);
AssertionError: expected '<link href="https://blog.skk.moe/" rel="canonical" crossorigin="anonymous">' to deeply equal '<link href="https://blog.skk.moe/" rel="canonical">'
giuem commented 4 years ago

Hmm, I really don't know which <link> should be ignore. Maybe introduce a new configure to ignore some tags?

SukkaW commented 4 years ago

@giuem Maybe specific element selector instead of tag name would be fine? Since the plugin is using cheerio.

giuem commented 4 years ago

Indeed, you can do it right now. There is a confused description in README which I have fixed.