Skip to content

Commit 39cfb51

Browse files
committed
fix: the doctype and html attr were modified wrongly
This commit fixed the issue that it wrongly changed the doctype and html attributes by emoji-processor, it would introduce some unnecessary issues, such as language missing, wrong doctype and so on.
1 parent 742fbfd commit 39cfb51

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

lib/jekyll-spaceship/processors/emoji-processor.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,14 @@ def emoji_filter(content, selector)
3838
# use nokogiri to parse html
3939
doc = Nokogiri::HTML(content)
4040

41+
body = doc.at('body')
42+
43+
# in case of a page has no the body node, especially when your
44+
# page's layout field of front matter is nil or unavailable
45+
return content if body.nil?
46+
4147
# filter nodes (pre, code)
42-
nodes = doc.css(selector)
48+
nodes = body.css(selector)
4349
nodes.each do |node|
4450
# handle emoji markup
4551
node.inner_html = node.inner_html.gsub(
@@ -48,7 +54,7 @@ def emoji_filter(content, selector)
4854
end
4955

5056
# parse the emoji
51-
content = doc.inner_html
57+
content = body.inner_html
5258
content.scan(/(?<!\\):([\w\d+-]+?)(?<!\\):/) do |match|
5359
# Skip invalid emoji name
5460
emoji = Emoji.find_by_alias match[0]
@@ -65,7 +71,7 @@ def emoji_filter(content, selector)
6571
result)
6672
end
6773

68-
doc.inner_html = content
74+
body.inner_html = content
6975

7076
# restore nodes (pre, code)
7177
nodes.each do |node|

0 commit comments

Comments
 (0)