jekyll-llms 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 23293734537766446bec10323faae85e54243da602e80bca5d8675feffff8abd
4
+ data.tar.gz: 33b4069fbc9e69e04305f33f487788d67e279a2f60842d789400d7f43de87c20
5
+ SHA512:
6
+ metadata.gz: a0e1ad5425441b17e99e316762b097c2f00f8b259cf4b9742ce9440d3712d740b51a160d95317459b94677dcd4fc3a1262e3e5642dba949394216c1af3a1101c
7
+ data.tar.gz: fac4f5e71fce6d09cfc476ac61fe236cfb00fa181d90be85eaa2cf0f17fbf0d62c9804ef11abfc36ae0618acc0b559ac7cc7b13331ed050a87b86b7d3e9ec758
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Stanislav Katkov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,59 @@
1
+ # jekyll-llms
2
+
3
+ Jekyll plugin that produces LLM-friendly formats alongside a regular website.
4
+
5
+ Namely: `llms.txt`, Markdown sidecars, and HTML alternate links to sidecars.
6
+
7
+ ## Installation
8
+
9
+ Add to `Gemfile` and run `bundle install`
10
+ ```ruby
11
+ group :jekyll_plugins do
12
+ gem "jekyll-llms"
13
+ end
14
+ ```
15
+
16
+ Add to `_config` file:
17
+
18
+ ```yaml
19
+ plugins:
20
+ - jekyll-llms
21
+ ```
22
+
23
+
24
+ ## Output
25
+
26
+ - `/llms.txt`: Markdown index of included entries.
27
+ - `*.md`: source-body sidecars for included entries.
28
+ - HTML `<link rel="alternate" type="text/markdown" href="...">` tags pointing to sidecars.
29
+
30
+ Sidecars are source bodies, not HTML-to-Markdown conversions. Front matter is removed. Liquid is rendered unless `render_with_liquid: false` is set.
31
+
32
+ ## Configuration
33
+
34
+ ```yaml
35
+ llms:
36
+ markdown: true
37
+ llms_txt: true
38
+ include:
39
+ - pages
40
+ - posts
41
+ exclude:
42
+ - /404.html
43
+ - /assets/**
44
+ ```
45
+
46
+ - `markdown`: generate sidecars, link `llms.txt` to sidecars, and add HTML alternate links. Default: `true`.
47
+ - `llms_txt`: generate `/llms.txt`. Default: `true`.
48
+ - `include`: `pages`, `posts`, and output collection names. Default: `[pages, posts]`.
49
+ - `exclude`: URL, Markdown path, or source path globs. Default: `[]`.
50
+
51
+ Per-entry opt-out:
52
+
53
+ ```yaml
54
+ llms: false
55
+ ```
56
+
57
+ ## License
58
+
59
+ MIT. See `LICENSE.txt`.
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module Llms
5
+ class Config
6
+ DEFAULTS = {
7
+ "markdown" => true,
8
+ "llms_txt" => true,
9
+ "include" => %w[pages posts],
10
+ "exclude" => [],
11
+ }.freeze
12
+
13
+ def self.from_site(site)
14
+ new(DEFAULTS.merge(site.config["llms"] || {}))
15
+ end
16
+
17
+ def initialize(values)
18
+ @values = values
19
+ end
20
+
21
+ def markdown?
22
+ @values.fetch("markdown")
23
+ end
24
+
25
+ def llms_txt?
26
+ @values.fetch("llms_txt")
27
+ end
28
+
29
+ def includes
30
+ @values.fetch("include")
31
+ end
32
+
33
+ def excludes
34
+ @values.fetch("exclude")
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module Llms
5
+ class Entry
6
+ attr_reader :item, :section, :url
7
+
8
+ def initialize(site:, item:, section:)
9
+ @item = item
10
+ @section = section
11
+ @url = Url.new(site: site, item: item)
12
+ end
13
+
14
+ def description
15
+ item.data.fetch("description", "").strip
16
+ end
17
+
18
+ def enabled?
19
+ item.data.fetch("llms", true)
20
+ end
21
+
22
+ def excluded_by?(patterns)
23
+ patterns.any? do |pattern|
24
+ url.matches?(pattern)
25
+ end
26
+ end
27
+
28
+ def title
29
+ title = item.data.fetch("title", "").strip
30
+ return title unless title.empty?
31
+
32
+ fallback_title
33
+ end
34
+
35
+ private
36
+
37
+ def fallback_title
38
+ if item.respond_to?(:basename_without_ext)
39
+ item.basename_without_ext
40
+ else
41
+ File.basename(item.name, ".*")
42
+ end
43
+ end
44
+
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module Llms
5
+ class EntrySet
6
+ def initialize(site:, config:)
7
+ @site = site
8
+ @config = config
9
+ end
10
+
11
+ def entries
12
+ config.includes.flat_map do |section|
13
+ section_entries(section)
14
+ end.select do |entry|
15
+ entry.enabled? && !entry.excluded_by?(config.excludes)
16
+ end.uniq do |entry|
17
+ entry.item.url
18
+ end
19
+ end
20
+
21
+ private
22
+
23
+ attr_reader :site, :config
24
+
25
+ def section_entries(section)
26
+ items_for(section).map do |item|
27
+ Entry.new(site: site, item: item, section: section)
28
+ end
29
+ end
30
+
31
+ def items_for(section)
32
+ case section
33
+ when "pages"
34
+ site.pages
35
+ when "posts"
36
+ site.posts.docs.sort { |a, b| b <=> a }
37
+ else
38
+ collection_items(section)
39
+ end
40
+ end
41
+
42
+ def collection_items(section)
43
+ collection = site.collections[section]
44
+ return [] unless collection&.write?
45
+
46
+ collection.docs
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "fileutils"
4
+
5
+ module Jekyll
6
+ module Llms
7
+ class FileWriter
8
+ def initialize(destination)
9
+ @destination = destination
10
+ end
11
+
12
+ def write(path, content)
13
+ full_path = File.join(destination, path)
14
+ FileUtils.mkdir_p(File.dirname(full_path))
15
+ File.write(full_path, content)
16
+ end
17
+
18
+ private
19
+
20
+ attr_reader :destination
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module Llms
5
+ class HtmlLinker
6
+ def initialize(site:, entries:)
7
+ @site = site
8
+ @entries = entries
9
+ end
10
+
11
+ def write
12
+ entries.each do |entry|
13
+ write_link(entry)
14
+ end
15
+ end
16
+
17
+ private
18
+
19
+ attr_reader :site, :entries
20
+
21
+ def write_link(entry)
22
+ path = entry.item.destination(site.dest)
23
+ return unless path.end_with?(".html")
24
+ return unless File.file?(path)
25
+
26
+ content = File.read(path)
27
+ File.write(path, content.sub("</head>", "#{link(entry)}\n</head>"))
28
+ end
29
+
30
+ def link(entry)
31
+ %(<link rel="alternate" type="text/markdown" href="#{entry.url.absolute(markdown: true)}">)
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module Llms
5
+ class Index
6
+ def initialize(site:, entries:, markdown:)
7
+ @site = site
8
+ @entries = entries
9
+ @markdown = markdown
10
+ end
11
+
12
+ def content
13
+ content = "# #{title}\n\n"
14
+ content << "> #{description}\n" unless description.empty?
15
+
16
+ entries.group_by(&:section).each do |section, section_entries|
17
+ content << "\n## #{section_title(section)}\n\n"
18
+ section_entries.each do |entry|
19
+ content << "#{entry_line(entry)}\n"
20
+ end
21
+ end
22
+
23
+ content
24
+ end
25
+
26
+ private
27
+
28
+ attr_reader :site, :entries, :markdown
29
+
30
+ def title
31
+ site.config.fetch("title", "Jekyll Site")
32
+ end
33
+
34
+ def description
35
+ site.config.fetch("description", "").strip
36
+ end
37
+
38
+ def entry_line(entry)
39
+ line = "- [#{entry.title}](#{entry.url.absolute(markdown: markdown)})"
40
+ entry.description.empty? ? line : "#{line}: #{entry.description}"
41
+ end
42
+
43
+ def section_title(section)
44
+ section.split(/[_-]/).map(&:capitalize).join(" ")
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module Llms
5
+ class MarkdownSource
6
+ def initialize(site:, item:)
7
+ @site = site
8
+ @item = item
9
+ end
10
+
11
+ def content
12
+ render_liquid(strip_frontmatter(read_file))
13
+ end
14
+
15
+ private
16
+
17
+ attr_reader :site, :item
18
+
19
+ def path
20
+ site.in_source_dir(item.relative_path)
21
+ end
22
+
23
+ def read_file
24
+ File.read(path)
25
+ end
26
+
27
+ def strip_frontmatter(content)
28
+ content =~ Document::YAML_FRONT_MATTER_REGEXP
29
+ Regexp.last_match.post_match
30
+ end
31
+
32
+ def render_liquid(content)
33
+ return content if item["render_with_liquid"] == false
34
+
35
+ Renderer.new(site, nil).render_liquid(content, payload, nil, path)
36
+ end
37
+
38
+ def payload
39
+ site.site_payload.tap do |payload|
40
+ payload["page"] = item
41
+ end
42
+ end
43
+
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module Llms
5
+ class SiteWriter
6
+ def initialize(site)
7
+ @site = site
8
+ @config = Config.from_site(site)
9
+ @entries = EntrySet.new(site: site, config: config).entries
10
+ @files = FileWriter.new(site.dest)
11
+ end
12
+
13
+ def write
14
+ write_index if config.llms_txt?
15
+ if config.markdown?
16
+ write_markdown
17
+ write_html_links
18
+ end
19
+ end
20
+
21
+ private
22
+
23
+ attr_reader :site, :config, :entries, :files
24
+
25
+ def write_index
26
+ files.write("llms.txt", Index.new(site: site, entries: entries, markdown: config.markdown?).content)
27
+ end
28
+
29
+ def write_markdown
30
+ entries.each do |entry|
31
+ files.write(entry.url.markdown_path, MarkdownSource.new(site: site, item: entry.item).content)
32
+ end
33
+ end
34
+
35
+ def write_html_links
36
+ HtmlLinker.new(site: site, entries: entries).write
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module Llms
5
+ class Url
6
+ MATCH_FLAGS = File::FNM_PATHNAME | File::FNM_EXTGLOB
7
+
8
+ def initialize(site:, item:)
9
+ @site = site
10
+ @item = item
11
+ end
12
+
13
+ def absolute(markdown:)
14
+ "#{prefix}#{path(markdown: markdown)}"
15
+ end
16
+
17
+ def markdown_path
18
+ url = item.url
19
+ return "#{url}index.md" if url.end_with?("/")
20
+
21
+ File.join(File.dirname(url), "#{File.basename(url, ".*")}.md")
22
+ end
23
+
24
+ def matches?(pattern)
25
+ candidates.any? do |candidate|
26
+ glob_match?(pattern, candidate)
27
+ end
28
+ end
29
+
30
+ private
31
+
32
+ attr_reader :site, :item
33
+
34
+ def path(markdown:)
35
+ markdown ? markdown_path : item.url
36
+ end
37
+
38
+ def prefix
39
+ url, baseurl = site.config.fetch_values("url", "baseurl")
40
+
41
+ "#{url.delete_suffix("/")}#{baseurl.delete_suffix("/")}"
42
+ end
43
+
44
+ def candidates
45
+ [item.url, markdown_path, relative_source_path]
46
+ end
47
+
48
+ def relative_source_path
49
+ "/#{item.relative_path}"
50
+ end
51
+
52
+ def glob_match?(pattern, candidate)
53
+ File.fnmatch?(pattern.delete_prefix("/"), candidate.delete_prefix("/"), MATCH_FLAGS)
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module Llms
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "jekyll"
4
+ require "jekyll/llms/config"
5
+ require "jekyll/llms/entry"
6
+ require "jekyll/llms/entry_set"
7
+ require "jekyll/llms/file_writer"
8
+ require "jekyll/llms/html_linker"
9
+ require "jekyll/llms/index"
10
+ require "jekyll/llms/markdown_source"
11
+ require "jekyll/llms/site_writer"
12
+ require "jekyll/llms/url"
13
+ require "jekyll/llms/version"
14
+
15
+ module Jekyll
16
+ module Llms
17
+ class << self
18
+ def write(site)
19
+ SiteWriter.new(site).write
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ Jekyll::Hooks.register :site, :post_write do |site|
26
+ Jekyll::Llms.write(site)
27
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "jekyll/llms"
metadata ADDED
@@ -0,0 +1,148 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll-llms
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Stanislav Katkov
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: jekyll
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '4.0'
19
+ - - "<"
20
+ - !ruby/object:Gem::Version
21
+ version: '5.0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ version: '4.0'
29
+ - - "<"
30
+ - !ruby/object:Gem::Version
31
+ version: '5.0'
32
+ - !ruby/object:Gem::Dependency
33
+ name: minitest
34
+ requirement: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - "~>"
37
+ - !ruby/object:Gem::Version
38
+ version: '5.0'
39
+ type: :development
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - "~>"
44
+ - !ruby/object:Gem::Version
45
+ version: '5.0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: mutant
48
+ requirement: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - "~>"
51
+ - !ruby/object:Gem::Version
52
+ version: '0.16'
53
+ type: :development
54
+ prerelease: false
55
+ version_requirements: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '0.16'
60
+ - !ruby/object:Gem::Dependency
61
+ name: mutant-minitest
62
+ requirement: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - "~>"
65
+ - !ruby/object:Gem::Version
66
+ version: '0.16'
67
+ type: :development
68
+ prerelease: false
69
+ version_requirements: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - "~>"
72
+ - !ruby/object:Gem::Version
73
+ version: '0.16'
74
+ - !ruby/object:Gem::Dependency
75
+ name: rake
76
+ requirement: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - "~>"
79
+ - !ruby/object:Gem::Version
80
+ version: '13.0'
81
+ type: :development
82
+ prerelease: false
83
+ version_requirements: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - "~>"
86
+ - !ruby/object:Gem::Version
87
+ version: '13.0'
88
+ - !ruby/object:Gem::Dependency
89
+ name: simplecov
90
+ requirement: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - "~>"
93
+ - !ruby/object:Gem::Version
94
+ version: '0.22'
95
+ type: :development
96
+ prerelease: false
97
+ version_requirements: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - "~>"
100
+ - !ruby/object:Gem::Version
101
+ version: '0.22'
102
+ description: Generates llms.txt and Markdown sidecars for Jekyll pages and posts.
103
+ email:
104
+ - git@skatkov.com
105
+ executables: []
106
+ extensions: []
107
+ extra_rdoc_files: []
108
+ files:
109
+ - LICENSE.txt
110
+ - README.md
111
+ - lib/jekyll-llms.rb
112
+ - lib/jekyll/llms.rb
113
+ - lib/jekyll/llms/config.rb
114
+ - lib/jekyll/llms/entry.rb
115
+ - lib/jekyll/llms/entry_set.rb
116
+ - lib/jekyll/llms/file_writer.rb
117
+ - lib/jekyll/llms/html_linker.rb
118
+ - lib/jekyll/llms/index.rb
119
+ - lib/jekyll/llms/markdown_source.rb
120
+ - lib/jekyll/llms/site_writer.rb
121
+ - lib/jekyll/llms/url.rb
122
+ - lib/jekyll/llms/version.rb
123
+ homepage: https://github.com/skatkov/jekyll-llms
124
+ licenses:
125
+ - MIT
126
+ metadata:
127
+ allowed_push_host: https://rubygems.org
128
+ homepage_uri: https://github.com/skatkov/jekyll-llms
129
+ rubygems_mfa_required: 'true'
130
+ source_code_uri: https://github.com/skatkov/jekyll-llms
131
+ rdoc_options: []
132
+ require_paths:
133
+ - lib
134
+ required_ruby_version: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '3.0'
139
+ required_rubygems_version: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ requirements: []
145
+ rubygems_version: 4.0.10
146
+ specification_version: 4
147
+ summary: Generate LLM-friendly files for Jekyll sites.
148
+ test_files: []