Module: Jekyll::LlmsOutput
- Defined in:
- lib/jekyll-llms-output/version.rb,
lib/jekyll-llms-output/generator.rb,
lib/jekyll-llms-output/full_builder.rb,
lib/jekyll-llms-output/index_builder.rb
Defined Under Namespace
Classes: FullBuilder, IndexBuilder
Constant Summary
collapse
- VERSION =
"0.1.0"
- DEFAULTS =
{
"enabled" => true,
"index" => {
"enabled" => true,
"output" => "/llms.txt",
"data" => "llms",
"title" => nil,
"description" => nil,
"collections" => ["posts"],
},
"full" => {
"enabled" => true,
"output" => "/llms-full.txt",
"collections" => ["posts"],
"pages" => false,
"page_extensions" => [".md", ".markdown"],
"separator" => "\n\n---\n\n",
"include_url" => true,
"include_date" => true,
"respect_markdown_output" => false,
},
}.freeze
Class Method Summary
collapse
Class Method Details
.config_for(site) ⇒ Object
30
31
32
33
34
|
# File 'lib/jekyll-llms-output/generator.rb', line 30
def self.config_for(site)
user = site.config["llms_output"] || {}
merged = deep_merge(DEFAULTS, user)
merged
end
|
.deep_merge(a, b) ⇒ Object
36
37
38
39
40
|
# File 'lib/jekyll-llms-output/generator.rb', line 36
def self.deep_merge(a, b)
a.merge(b) do |_, av, bv|
av.is_a?(Hash) && bv.is_a?(Hash) ? deep_merge(av, bv) : bv
end
end
|
.write_all(site) ⇒ Object
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/jekyll-llms-output/generator.rb', line 42
def self.write_all(site)
config = config_for(site)
return unless config["enabled"]
if config["index"]["enabled"]
body = IndexBuilder.new(site, config["index"]).build
write_file(site, config["index"]["output"], body)
Jekyll.logger.info("LlmsOutput:", "wrote #{config["index"]["output"]}")
end
if config["full"]["enabled"]
body = FullBuilder.new(site, config["full"]).build
write_file(site, config["full"]["output"], body)
Jekyll.logger.info("LlmsOutput:", "wrote #{config["full"]["output"]}")
end
end
|
.write_file(site, output_path, body) ⇒ Object
59
60
61
62
63
|
# File 'lib/jekyll-llms-output/generator.rb', line 59
def self.write_file(site, output_path, body)
path = File.join(site.dest, output_path)
FileUtils.mkdir_p(File.dirname(path))
File.write(path, body)
end
|