Skip to content

fix: compatibility with cheerio 1.0.0+ (#3313)#3315

Merged
yoshinorin merged 3 commits intohexojs:masterfrom
curbengh:fix-meta
Oct 28, 2018
Merged

fix: compatibility with cheerio 1.0.0+ (#3313)#3315
yoshinorin merged 3 commits intohexojs:masterfrom
curbengh:fix-meta

Conversation

@curbengh
Copy link
Copy Markdown
Contributor

@curbengh curbengh commented Oct 27, 2018

Fix #3313. Related to #3129.

  1. When a third-party plugin uses cheerio 1.0.0-rc.1+, <html><head><body> are automatically added to every empty or open tag (see Automatically adding <html><head><body> ? cheeriojs/cheerio#1031 All examples are broken for v1.0.0 (rc2) - cheerio outputs html-tags cheeriojs/cheerio#1239). If I have <p>, it will results in,
<html><head></head><body><p></body></html>
  1. meta_generator.js prepend meta generator tag to every <head>. e.g.
<html><head><meta name="generator"...></head><body><p></body></html>
  1. Those extra <html><head><body> are stripped away in the final $.html(), leaving
<meta name="generator"...><p>

As a workaround, meta_generator.js prepend only to non-empty real <head>. I assume Hexo page has at least meta charset or css in the <head>.

Without this workaround, if I use any plugin that uses cheerio 1.0.0+ (e.g. hexo-nofollow), meta_generator will also prepend tag to <body> (see curbengh/hexo-testing@f4824bb).

Thank you for creating a pull request to contribute to Hexo code! Before you open the request please review the following guidelines and tips to help it be more easily integrated:

  • Add test cases for the changes.
  • Passed the CI test.

cc @h404bi

@curbengh curbengh changed the title fix: compatibility with cheerio 1.0.0+ #3313 fix: compatibility with cheerio 1.0.0+ (#3313) Oct 27, 2018
@coveralls
Copy link
Copy Markdown

coveralls commented Oct 27, 2018

Coverage Status

Coverage remained the same at 97.27% when pulling 4d071c4 on weyusi:fix-meta into bbc2f04 on hexojs:master.

chawyehsu
chawyehsu previously approved these changes Oct 27, 2018
Copy link
Copy Markdown
Contributor

@chawyehsu chawyehsu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@curbengh
Copy link
Copy Markdown
Contributor Author

curbengh commented Oct 28, 2018

I should create a test case, learning...

Edit: Added a test case.

@@ -0,0 +1,28 @@
'use strict';

const should = require('chai').should(); // eslint-disable-line
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We were changed to use globally chai.should in this commit.
So, no need this line.

Copy link
Copy Markdown
Contributor Author

@curbengh curbengh Oct 28, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed

const should = require('chai').should(); // eslint-disable-line

describe('Meta Generator', function() {
const Hexo = require('../../../lib/hexo');
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now, We are migrating hexo code to ES6 syntax.
Would you please change to arrow function ? Also others.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed

@yoshinorin
Copy link
Copy Markdown
Member

Other implementation and test code I will review later.
Thanks !!

@yoshinorin yoshinorin merged commit 51808d5 into hexojs:master Oct 28, 2018
@yoshinorin
Copy link
Copy Markdown
Member

LGTM! Thanks!

@JoeyBling
Copy link
Copy Markdown

I think this caused the problem. Can you fix it?

#3652

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

meta generator in <body> when using hexo-nofollow plugin

6 participants