From b5ddf318a0ce01e1847d10c6372f82d84a68a8df Mon Sep 17 00:00:00 2001 From: neveler <55753029+neveler@users.noreply.github.com> Date: Sat, 28 Mar 2026 14:18:50 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E9=87=8D=E6=9E=84=20alert=20=E6=8F=92?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Gemfile | 1 - _data/plugins/auto_alert.yml | 15 ----------- _plugins/alert.rb | 40 ++++++++++++++++++++++++++++++ _plugins/auto-alert.rb | 48 ------------------------------------ 4 files changed, 40 insertions(+), 64 deletions(-) delete mode 100644 _data/plugins/auto_alert.yml create mode 100644 _plugins/alert.rb delete mode 100644 _plugins/auto-alert.rb diff --git a/Gemfile b/Gemfile index 3ba85cff..63857683 100644 --- a/Gemfile +++ b/Gemfile @@ -33,4 +33,3 @@ gem "http_parser.rb", "0.8.0", :platforms => [:jruby] # plugin dependencies gem "nokogiri", "1.18.10" -gem "addressable", "2.8.7" diff --git a/_data/plugins/auto_alert.yml b/_data/plugins/auto_alert.yml deleted file mode 100644 index daa43c46..00000000 --- a/_data/plugins/auto_alert.yml +++ /dev/null @@ -1,15 +0,0 @@ -note: - title: 注意 - class_name: notice--info -tip: - title: 提示 - class_name: notice--success -important: - title: 重要 - class_name: notice--primary -warning: - title: 警告 - class_name: notice--warning -caution: - title: 谨慎 - class_name: notice--danger diff --git a/_plugins/alert.rb b/_plugins/alert.rb new file mode 100644 index 00000000..fbc7c290 --- /dev/null +++ b/_plugins/alert.rb @@ -0,0 +1,40 @@ +require "kramdown/converter/html" +require "kramdown/element" + +module Alert + module HtmlExtension + def convert_blockquote(el, indent) + types = %w(note tip important warning caution) + first = el.children.first + return super unless first&.type == :p + return super if first.children.empty? + + target = first.children.first + return super unless target&.type == :text + + down = target.value.downcase + types.each do |type| + prefix = "[!#{type}]" + + # case A:
[!NOTE]
+ if down == prefix + el.attr["data-type"] = type + first.children.shift + break + end + + head = prefix + "\n" + next unless down.start_with?(head) + + # case B:[!NOTE]\n some text
+ el.attr["data-type"] = type + target.value = target.value[head.length..-1] || "" + break + end + + super + end + end +end + +Kramdown::Converter::Html.prepend(Alerts::HtmlExtension) diff --git a/_plugins/auto-alert.rb b/_plugins/auto-alert.rb deleted file mode 100644 index bb8ce96c..00000000 --- a/_plugins/auto-alert.rb +++ /dev/null @@ -1,48 +0,0 @@ -require "nokogiri" - -Jekyll::Hooks.register [:pages, :documents], :post_convert do |doc| - next unless doc.output_ext == ".html" - site = doc.site - next unless site.data["plugins"] - alert_type = site.data["plugins"]["auto_alert"] - next unless alert_type - - fragment = Nokogiri::HTML::DocumentFragment.parse(doc.content) - # 遍历 HTML 中的所有 blockquote 标签 - fragment.css("blockquote").each do |item| - # 找出第一个子节点,用于判断是否含有 [!type] 标记 - first_child = item.at_css("*:first-child") - next unless first_child - next unless first_child.name == "p" - - inner_html = first_child.inner_html.downcase - - # 遍历所有 alert 类型 - alert_type.each do |type, data| - prefix = "[!#{type}]" - prefix_with_newline = "#{prefix}\n" - - # 情况一:完整匹配 [!type] 形式[!NOTE]
- if inner_html == prefix - # 将 alert 类型对应的 class 加入 blockquote - item["class"] = [item["class"], data["class_name"]].compact.join(" ") - - # 将替换为
[!NOTE]\n\n other content
- elsif inner_html.start_with? prefix_with_newline - # 将 alert 类型对应的 class 加入 blockquote - item["class"] = [item["class"], data["class_name"]].compact.join(" ") - # 在原段落前插入标题[!NOTE]\n\n other content
- first_child.add_previous_sibling "\n other content
- first_child.inner_html = first_child.inner_html[prefix_with_newline.length..-1] || "" - break - end - end - end - doc.content = fragment.to_html -end From a7a571834f06c97a42a46f1c65fad63a0a9d6f56 Mon Sep 17 00:00:00 2001 From: neveler <55753029+neveler@users.noreply.github.com> Date: Sat, 28 Mar 2026 14:23:38 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _sass/minimal-mistakes-plus.scss | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/_sass/minimal-mistakes-plus.scss b/_sass/minimal-mistakes-plus.scss index 1d6d0b45..f33be05e 100644 --- a/_sass/minimal-mistakes-plus.scss +++ b/_sass/minimal-mistakes-plus.scss @@ -3,6 +3,26 @@ blockquote { margin-inline: 0; font-style: normal; + + &[data-type="note"] { + @extend .notice--info; + } + + &[data-type="tip"] { + @extend .notice--success; + } + + &[data-type="important"] { + @extend .notice--primary; + } + + &[data-type="warning"] { + @extend .notice--warning; + } + + &[data-type="caution"] { + @extend .notice--danger; + } } * { From 8b4575d423797b9aab869fbc6bf62d32c4c9dff4 Mon Sep 17 00:00:00 2001 From: neveler <55753029+neveler@users.noreply.github.com> Date: Sat, 28 Mar 2026 14:29:05 +0800 Subject: [PATCH 3/4] update --- _plugins/alert.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_plugins/alert.rb b/_plugins/alert.rb index fbc7c290..f4cd81a2 100644 --- a/_plugins/alert.rb +++ b/_plugins/alert.rb @@ -37,4 +37,4 @@ def convert_blockquote(el, indent) end end -Kramdown::Converter::Html.prepend(Alerts::HtmlExtension) +Kramdown::Converter::Html.prepend(Alert::HtmlExtension) From 73dd0f903c5cb7a82262996e3f02ff6e69156821 Mon Sep 17 00:00:00 2001 From: neveler <55753029+neveler@users.noreply.github.com> Date: Sat, 28 Mar 2026 14:43:25 +0800 Subject: [PATCH 4/4] Update alert.rb --- _plugins/alert.rb | 3 --- 1 file changed, 3 deletions(-) diff --git a/_plugins/alert.rb b/_plugins/alert.rb index f4cd81a2..dcadad49 100644 --- a/_plugins/alert.rb +++ b/_plugins/alert.rb @@ -1,6 +1,3 @@ -require "kramdown/converter/html" -require "kramdown/element" - module Alert module HtmlExtension def convert_blockquote(el, indent)