Skip to content

Commit ec24cca

Browse files
committed
add plugins
1 parent c341a6c commit ec24cca

2 files changed

Lines changed: 53 additions & 0 deletions

File tree

_plugins/html_decode_filter.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module Jekyll
2+
module HtmlDecodeFilter
3+
require 'cgi'
4+
5+
def html_decode(input)
6+
return '' if input.nil?
7+
CGI.unescapeHTML(input.to_s)
8+
end
9+
end
10+
end
11+
12+
Liquid::Template.register_filter(Jekyll::HtmlDecodeFilter)
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# _plugins/raw_content_for_collections.rb
2+
module Jekyll
3+
class RawContentForCollections < Generator
4+
safe true
5+
priority :low
6+
7+
def generate(site)
8+
# 遍历所有集合
9+
site.collections.each do |label, collection|
10+
next unless label == 'articles' # 只处理 articles 集合
11+
12+
collection.docs.each do |doc|
13+
# 获取源文件的完整路径
14+
source_path = File.join(site.source, doc.relative_path)
15+
if File.exist?(source_path)
16+
# 读取原始内容(注意:包含 Front Matter)
17+
raw_file_content = File.read(source_path)
18+
19+
# 可选:移除 Front Matter,只保留正文 Markdown
20+
# 如果你希望 raw_content 不包含 Front Matter,取消下面注释
21+
# raw_markdown = remove_front_matter(raw_file_content)
22+
23+
# 这里我们保留整个文件内容(含 Front Matter)
24+
doc.data['raw_content'] = raw_file_content
25+
end
26+
end
27+
end
28+
end
29+
30+
# 可选辅助方法:移除 Front Matter,仅保留 Markdown 正文
31+
private
32+
33+
def remove_front_matter(content)
34+
if content =~ /\A(---\s*\n.*?\n---\s*\n)/m
35+
content.sub(/\A(---\s*\n.*?\n---\s*\n)/m, '')
36+
else
37+
content
38+
end
39+
end
40+
end
41+
end

0 commit comments

Comments
 (0)