jekyll-agent-markdown 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 +7 -0
- data/CHANGELOG.md +14 -0
- data/LICENSE.txt +201 -0
- data/README.md +103 -0
- data/lib/jekyll/agent_markdown/configuration.rb +86 -0
- data/lib/jekyll/agent_markdown/destination_claims.rb +63 -0
- data/lib/jekyll/agent_markdown/generator.rb +140 -0
- data/lib/jekyll/agent_markdown/markdown_sibling_path.rb +38 -0
- data/lib/jekyll/agent_markdown/raw_markdown_file.rb +92 -0
- data/lib/jekyll/agent_markdown/version.rb +7 -0
- data/lib/jekyll-agent-markdown.rb +5 -0
- metadata +75 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: b29b2ab68b394cfc7b37489422cbb516b6f4c3dce9af32aeb459438fce2b41ee
|
|
4
|
+
data.tar.gz: ce818d0127fcaf5cb89788144a32795264c962406219db55360fedf3bfb253b0
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: ee88b5e526b873e40eaa405c99810de61431aabbbf43bff1c8705e6e17ed828df408d94581735dcfed3180b10cf3e04116c8a6c216297fbb89c1cffab6521f45
|
|
7
|
+
data.tar.gz: 29c1aaaa685a8c8a44c9ffb7041a0f9c05e9cf1043ebd70aab445a3b5cfc634b0539d2941f56839ed07cb5ce57209657fe708df1f2ecfc0cb170d284f8c0046a
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
## [Unreleased]
|
|
2
|
+
|
|
3
|
+
## [0.1.0] - 2026-08-18
|
|
4
|
+
|
|
5
|
+
- Export Jekyll posts as raw Markdown siblings.
|
|
6
|
+
- Generate an optional `llms.txt` article index.
|
|
7
|
+
- Skip `llms.txt` with a warning when `url` is missing; fail only when `llms_txt` is explicitly configured.
|
|
8
|
+
- Warn and skip instead of silently overwriting when two posts map to the same Markdown path or the path belongs to an existing file.
|
|
9
|
+
- Escape Markdown link syntax in `llms.txt` titles and URLs.
|
|
10
|
+
- Compare portable canonical destinations across pages, static files, and collection documents, including encoded, case-only, Unicode-normalization, file-versus-directory, and `/llms.txt` conflicts.
|
|
11
|
+
- Preserve raw Liquid in Markdown exports and document baseurl-aware alternate links.
|
|
12
|
+
- Reject unsafe destination symlinks, credentialed URLs, and invalid site or per-post configuration values.
|
|
13
|
+
- Keep trailing-slash permalink segments ending in `.html` distinct from file-style `.html` permalinks.
|
|
14
|
+
- Load the small implementation tree explicitly while keeping implementation files directly requireable.
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
https://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Lucian Ghinda
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
https://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
data/README.md
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# jekyll-agent-markdown
|
|
2
|
+
|
|
3
|
+
Export Jekyll posts as raw Markdown next to their normal HTML output, and publish a small `llms.txt` index.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add the gem to your site's `Gemfile` plugin group:
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
group :jekyll_plugins do
|
|
11
|
+
gem "jekyll-agent-markdown"
|
|
12
|
+
end
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Then run `bundle install` and enable it in `_config.yml`:
|
|
16
|
+
|
|
17
|
+
```yaml
|
|
18
|
+
plugins:
|
|
19
|
+
- jekyll-agent-markdown
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Configuration
|
|
23
|
+
|
|
24
|
+
Both exports are enabled by default:
|
|
25
|
+
|
|
26
|
+
```yaml
|
|
27
|
+
agent_markdown:
|
|
28
|
+
posts: true
|
|
29
|
+
llms_txt: true
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
`posts` and `llms_txt` are the only accepted settings. Each accepts `true`, `false`, or one of the false-style strings `"false"`, `"no"`, and `"off"` (case-insensitively). Unknown keys and other values stop the build with a configuration error instead of being silently ignored. An explicit per-post `agent_markdown` value follows the same rules, so a mistyped opt-out cannot publish raw source by accident.
|
|
33
|
+
|
|
34
|
+
Set `url` to your site's absolute HTTP(S) URL; the `llms.txt` index uses it to generate absolute article links:
|
|
35
|
+
|
|
36
|
+
```yaml
|
|
37
|
+
url: https://example.com
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
When `url` is missing, contains credentials, a query, or a fragment, or is not an absolute HTTP(S) URL, `llms.txt` is skipped with a warning and the rest of the build continues. The build only fails when you set `llms_txt` explicitly in `_config.yml`, since that states clear intent.
|
|
41
|
+
|
|
42
|
+
Set `agent_markdown: false` to disable both exports, or `agent_markdown: true` to enable both explicitly (same as leaving it unset). The strings `"false"`, `"no"`, and `"off"` are also treated as false, case-insensitively.
|
|
43
|
+
|
|
44
|
+
Markdown sibling paths are deterministic:
|
|
45
|
+
|
|
46
|
+
| Post URL | Markdown URL |
|
|
47
|
+
|---|---|
|
|
48
|
+
| `/foo/` | `/foo.md` |
|
|
49
|
+
| `/foo.html`, `/foo.htm` | `/foo.md` |
|
|
50
|
+
| `/foo.html/` | `/foo.html.md` |
|
|
51
|
+
| `/foo/index.html` | `/foo.md` |
|
|
52
|
+
| `/foo` | `/foo.md` |
|
|
53
|
+
| `/` | `/index.md` |
|
|
54
|
+
|
|
55
|
+
Extensions are matched case-insensitively, and percent-encoded aliases are compared by their final decoded destination. Destination ownership also treats case-only and Unicode-normalization aliases as equivalent on every platform, keeping builds portable across filesystems. File-versus-directory conflicts are reserved as well. Before adding an export, the plugin checks every page, static file, and writable collection document already known to Jekyll. The existing destination owner wins; later post exports are skipped with a warning and omitted from `llms.txt`. A committed `llms.txt` wins in the same way.
|
|
56
|
+
|
|
57
|
+
The generated file contains the post's original Markdown body with no front matter, HTML conversion, or Liquid rendering. Liquid tags and directives such as `{{ site.title }}` are published literally. Exclude one post with front matter:
|
|
58
|
+
|
|
59
|
+
```yaml
|
|
60
|
+
agent_markdown: false
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Expose the alternate representation from a layout:
|
|
64
|
+
|
|
65
|
+
```liquid
|
|
66
|
+
{% if page.agent_markdown_url %}
|
|
67
|
+
<link rel="alternate" type="text/markdown" href="{{ page.agent_markdown_url | relative_url }}">
|
|
68
|
+
{% endif %}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
The conditional omits the link for opted-out and colliding posts. The `relative_url` filter adds `baseurl` for sites deployed below the domain root.
|
|
72
|
+
|
|
73
|
+
The generated `/llms.txt` is a compact index, for example:
|
|
74
|
+
|
|
75
|
+
```text
|
|
76
|
+
# Example Site
|
|
77
|
+
|
|
78
|
+
> A short description
|
|
79
|
+
|
|
80
|
+
## Articles
|
|
81
|
+
|
|
82
|
+
> Posts only. Pages and collections are not included.
|
|
83
|
+
|
|
84
|
+
- [First article](https://example.com/articles/first.md)
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Deployment notes
|
|
88
|
+
|
|
89
|
+
Configure your host to serve generated `.md` files as `Content-Type: text/markdown; charset=utf-8` and, when appropriate, `X-Robots-Tag: noindex`. This gem writes files only; it cannot set HTTP response headers. Generated files refuse to write through symlinks inside the destination. GitHub Pages safe mode may not run arbitrary plugins, so use a separate build/deploy pipeline there.
|
|
90
|
+
|
|
91
|
+
## v0.1.0 limitations
|
|
92
|
+
|
|
93
|
+
Only posts are exported. Pages and custom collections, custom Markdown transformations or templates, front-matter allowlisting, automatic response headers, sitemaps, and AI-specific metadata are intentionally deferred.
|
|
94
|
+
|
|
95
|
+
## Development
|
|
96
|
+
|
|
97
|
+
Run `bundle exec rake` after `bundle install` to execute both Minitest and RuboCop.
|
|
98
|
+
|
|
99
|
+
The entry point explicitly loads the plugin's small implementation tree without an additional runtime loader dependency. Implementation files also declare their own prerequisites so public constants can be required directly in isolation.
|
|
100
|
+
|
|
101
|
+
## License
|
|
102
|
+
|
|
103
|
+
Apache License 2.0.
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "jekyll"
|
|
4
|
+
require "uri"
|
|
5
|
+
|
|
6
|
+
module Jekyll
|
|
7
|
+
module AgentMarkdown
|
|
8
|
+
class Configuration
|
|
9
|
+
ALLOWED_SETTINGS = %w[llms_txt posts].freeze
|
|
10
|
+
FALSE_STRINGS = %w[false no off].freeze
|
|
11
|
+
|
|
12
|
+
class << self
|
|
13
|
+
def for(site)
|
|
14
|
+
settings = site.config["agent_markdown"]
|
|
15
|
+
return {} if settings.nil? || settings == true
|
|
16
|
+
return false if disabled?(settings)
|
|
17
|
+
|
|
18
|
+
unless settings.is_a?(Hash)
|
|
19
|
+
raise Jekyll::Errors::FatalException, "agent_markdown must be a Hash, true, or false"
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
normalized_settings(settings)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def enabled?(settings, key)
|
|
26
|
+
!disabled?(settings.fetch(key, true))
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def enabled_value?(value, name:)
|
|
30
|
+
validate_value!(name, value)
|
|
31
|
+
!disabled?(value)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def disabled?(value)
|
|
35
|
+
value == false || (value.is_a?(String) && FALSE_STRINGS.include?(value.strip.downcase))
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def absolute_http_url?(url)
|
|
39
|
+
uri = URI.parse(url) if url.is_a?(String)
|
|
40
|
+
uri.is_a?(URI::HTTP) &&
|
|
41
|
+
!uri.host.to_s.empty? &&
|
|
42
|
+
uri.userinfo.nil? &&
|
|
43
|
+
uri.query.nil? &&
|
|
44
|
+
uri.fragment.nil?
|
|
45
|
+
rescue URI::InvalidURIError
|
|
46
|
+
false
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
private
|
|
50
|
+
|
|
51
|
+
def normalized_settings(settings)
|
|
52
|
+
normalized = settings.to_h { |key, value| [key.to_s, value] }
|
|
53
|
+
validate_keys!(normalized)
|
|
54
|
+
validate_values!(normalized)
|
|
55
|
+
normalized
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def validate_keys!(settings)
|
|
59
|
+
unknown = settings.keys - ALLOWED_SETTINGS
|
|
60
|
+
return if unknown.empty?
|
|
61
|
+
|
|
62
|
+
suffix = "s" if unknown.length > 1
|
|
63
|
+
raise Jekyll::Errors::FatalException,
|
|
64
|
+
"unknown agent_markdown setting#{suffix}: #{unknown.sort.join(", ")}"
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def validate_values!(settings)
|
|
68
|
+
settings.each do |key, value|
|
|
69
|
+
validate_value!("agent_markdown.#{key}", value)
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def validate_value!(name, value)
|
|
74
|
+
return if valid_value?(value)
|
|
75
|
+
|
|
76
|
+
raise Jekyll::Errors::FatalException,
|
|
77
|
+
"#{name} must be true, false, or a false-style string; got #{value.inspect}"
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def valid_value?(value)
|
|
81
|
+
value == true || disabled?(value)
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
end
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Jekyll
|
|
4
|
+
module AgentMarkdown
|
|
5
|
+
class DestinationClaims
|
|
6
|
+
def initialize(root)
|
|
7
|
+
@root = identity(root)
|
|
8
|
+
@files = Set.new
|
|
9
|
+
@directories = Set.new
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def add_existing(path)
|
|
13
|
+
add(identity(path))
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def claim?(path)
|
|
17
|
+
candidate = identity(path)
|
|
18
|
+
return false if conflict?(candidate)
|
|
19
|
+
|
|
20
|
+
add(candidate)
|
|
21
|
+
true
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
private
|
|
25
|
+
|
|
26
|
+
def conflict?(candidate)
|
|
27
|
+
@files.include?(candidate) ||
|
|
28
|
+
@directories.include?(candidate) ||
|
|
29
|
+
ancestors(candidate).any? { |ancestor| @files.include?(ancestor) }
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def add(path)
|
|
33
|
+
@files << path
|
|
34
|
+
ancestors(path).each { |ancestor| @directories << ancestor }
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def ancestors(path)
|
|
38
|
+
parent = File.dirname(path)
|
|
39
|
+
ancestors = []
|
|
40
|
+
|
|
41
|
+
while parent != @root && inside_root?(parent)
|
|
42
|
+
ancestors << parent
|
|
43
|
+
parent = File.dirname(parent)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
ancestors
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def inside_root?(path)
|
|
50
|
+
path.start_with?("#{@root}#{File::SEPARATOR}")
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# Treat case and Unicode normalization aliases as collisions everywhere.
|
|
54
|
+
# This preserves the same first-writer behavior across deployment filesystems.
|
|
55
|
+
def identity(path)
|
|
56
|
+
File.expand_path(path)
|
|
57
|
+
.unicode_normalize(:nfc)
|
|
58
|
+
.downcase(:fold)
|
|
59
|
+
.unicode_normalize(:nfc)
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "jekyll"
|
|
4
|
+
require_relative "configuration"
|
|
5
|
+
require_relative "destination_claims"
|
|
6
|
+
require_relative "markdown_sibling_path"
|
|
7
|
+
require_relative "raw_markdown_file"
|
|
8
|
+
|
|
9
|
+
module Jekyll
|
|
10
|
+
module AgentMarkdown
|
|
11
|
+
class Generator < Jekyll::Generator
|
|
12
|
+
include Jekyll::Filters::URLFilters
|
|
13
|
+
|
|
14
|
+
URL_REQUIRED_MESSAGE =
|
|
15
|
+
"url is required for agent_markdown.llms_txt and must be an absolute HTTP(S) URL " \
|
|
16
|
+
"without credentials, a query, or a fragment"
|
|
17
|
+
|
|
18
|
+
# Run after normal- and high-priority generators so their post changes are exported.
|
|
19
|
+
priority :low
|
|
20
|
+
|
|
21
|
+
def generate(site)
|
|
22
|
+
settings = Configuration.for(site)
|
|
23
|
+
return if settings == false
|
|
24
|
+
|
|
25
|
+
@context = Liquid::Context.new({}, {}, { site: site })
|
|
26
|
+
destination_claims = destination_claims(site)
|
|
27
|
+
included_posts = export_posts(site, destination_claims) if Configuration.enabled?(settings, "posts")
|
|
28
|
+
write_llms_txt(site, settings, included_posts || [], destination_claims)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
private
|
|
32
|
+
|
|
33
|
+
def destination_claims(site)
|
|
34
|
+
DestinationClaims.new(site.dest).tap do |claims|
|
|
35
|
+
site.each_site_file { |item| claims.add_existing(item.destination(site.dest)) }
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def export_posts(site, destination_claims)
|
|
40
|
+
site.posts.docs.filter_map { |post| export_post(site, destination_claims, post) }
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def export_post(site, destination_claims, post)
|
|
44
|
+
setting = post.data.fetch("agent_markdown", true)
|
|
45
|
+
setting_name = "agent_markdown in #{post.relative_path}"
|
|
46
|
+
return unless Configuration.enabled_value?(setting, name: setting_name)
|
|
47
|
+
|
|
48
|
+
file = RawMarkdownFile.new(site, MarkdownSiblingPath.for(post.url), post.content)
|
|
49
|
+
url = file.url
|
|
50
|
+
return collision_warning(post, url) unless claim_destination?(destination_claims, site, file)
|
|
51
|
+
|
|
52
|
+
post.data["agent_markdown_url"] = url
|
|
53
|
+
site.static_files << file
|
|
54
|
+
post
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def collision_warning(post, url)
|
|
58
|
+
Jekyll.logger.warn "AgentMarkdown:",
|
|
59
|
+
"skipping #{post.relative_path}: #{url} already belongs to another file"
|
|
60
|
+
nil
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def write_llms_txt(site, settings, posts, destination_claims)
|
|
64
|
+
return unless Configuration.enabled?(settings, "llms_txt")
|
|
65
|
+
return unless llms_txt_ready?(site, settings)
|
|
66
|
+
|
|
67
|
+
file = RawMarkdownFile.new(site, "/llms.txt", llms_txt(site, posts))
|
|
68
|
+
return llms_txt_collision_warning unless claim_destination?(destination_claims, site, file)
|
|
69
|
+
|
|
70
|
+
site.static_files << file
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def claim_destination?(destination_claims, site, file)
|
|
74
|
+
destination_claims.claim?(file.destination(site.dest))
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def llms_txt_collision_warning
|
|
78
|
+
Jekyll.logger.warn "AgentMarkdown:",
|
|
79
|
+
"skipping /llms.txt: the destination already belongs to another file"
|
|
80
|
+
nil
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
# A missing url only fails the build when llms_txt was explicitly
|
|
84
|
+
# configured; the default is to warn and skip so adding the gem never
|
|
85
|
+
# breaks a previously green build.
|
|
86
|
+
def llms_txt_ready?(site, settings)
|
|
87
|
+
return true if Configuration.absolute_http_url?(site.config["url"])
|
|
88
|
+
raise Jekyll::Errors::FatalException, URL_REQUIRED_MESSAGE if settings.key?("llms_txt")
|
|
89
|
+
|
|
90
|
+
Jekyll.logger.warn "AgentMarkdown:", "#{URL_REQUIRED_MESSAGE}; skipping llms.txt"
|
|
91
|
+
false
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def llms_txt(site, posts)
|
|
95
|
+
sections = [llms_headings(site), article_links(site, posts)]
|
|
96
|
+
"#{sections.reject(&:empty?).join("\n\n")}\n"
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def llms_headings(site)
|
|
100
|
+
title = one_line(site.config.fetch("title", ""))
|
|
101
|
+
headings = ["# #{title}".rstrip]
|
|
102
|
+
description = one_line(site.config["description"])
|
|
103
|
+
headings << "> #{description}" unless description.empty?
|
|
104
|
+
headings << "## Articles"
|
|
105
|
+
headings << "> Posts only. Pages and collections are not included."
|
|
106
|
+
headings.join("\n\n")
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def one_line(value)
|
|
110
|
+
return "" if value.nil? || value == false
|
|
111
|
+
|
|
112
|
+
value.to_s.gsub(/\s+/, " ").strip
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def article_links(site, posts)
|
|
116
|
+
site_url = site.config["url"].sub(%r{/+\z}, "")
|
|
117
|
+
posts.map { |post| article_link(site_url, post) }.join("\n")
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
def article_link(site_url, post)
|
|
121
|
+
url = "#{site_url}#{relative_url(post.data.fetch("agent_markdown_url"))}"
|
|
122
|
+
"- [#{link_title(post)}](#{escaped_link_url(url)})"
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
# Backslashes and square brackets would end the Markdown link text early;
|
|
126
|
+
# whitespace runs (including newlines) would break the one-entry-per-line
|
|
127
|
+
# format.
|
|
128
|
+
def link_title(post)
|
|
129
|
+
post.data.fetch("title", post.basename_without_ext)
|
|
130
|
+
.to_s.gsub(/\s+/, " ").strip
|
|
131
|
+
.gsub(/[\\\[\]]/) { |character| "\\#{character}" }
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
# Unescaped parentheses would end the Markdown link destination early.
|
|
135
|
+
def escaped_link_url(url)
|
|
136
|
+
url.gsub("(", "%28").gsub(")", "%29")
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "jekyll"
|
|
4
|
+
|
|
5
|
+
module Jekyll
|
|
6
|
+
module AgentMarkdown
|
|
7
|
+
class MarkdownSiblingPath
|
|
8
|
+
def self.for(document_url)
|
|
9
|
+
new(document_url).to_s
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def initialize(document_url)
|
|
13
|
+
@document_url = document_url.to_s
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def to_s
|
|
17
|
+
normalized = path_without_output_suffix
|
|
18
|
+
return "/index.md" if normalized.empty?
|
|
19
|
+
|
|
20
|
+
"#{normalized}.md"
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
private
|
|
24
|
+
|
|
25
|
+
def path_without_output_suffix
|
|
26
|
+
path = canonical_url
|
|
27
|
+
return path.sub(%r{/index\.html?\z}i, "") if path.match?(%r{/index\.html?\z}i)
|
|
28
|
+
return path.sub(%r{/\z}, "") if path.end_with?("/")
|
|
29
|
+
|
|
30
|
+
path.sub(/\.html?\z/i, "")
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def canonical_url
|
|
34
|
+
Jekyll::URL.escape_path(Jekyll::URL.unescape_path(@document_url))
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "fileutils"
|
|
4
|
+
require "jekyll"
|
|
5
|
+
|
|
6
|
+
module Jekyll
|
|
7
|
+
module AgentMarkdown
|
|
8
|
+
class RawMarkdownFile < StaticFile
|
|
9
|
+
def initialize(site, url, content)
|
|
10
|
+
@content = content
|
|
11
|
+
path = validated_path(url)
|
|
12
|
+
super(site, site.source, File.dirname(path), File.basename(path))
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# In-memory files have no source path. Returning nil also makes Jekyll's
|
|
16
|
+
# incremental regenerator write them on every build.
|
|
17
|
+
def path
|
|
18
|
+
nil
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# The inherited implementation stats the source path, which never exists
|
|
22
|
+
# for generated files.
|
|
23
|
+
def modified_time
|
|
24
|
+
@modified_time ||= @site.time
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# Front-matter defaults target authored files, not plugin output.
|
|
28
|
+
def write?
|
|
29
|
+
true
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def write(destination)
|
|
33
|
+
output = self.destination(destination)
|
|
34
|
+
validate_destination!(destination, output)
|
|
35
|
+
FileUtils.mkdir_p(File.dirname(output))
|
|
36
|
+
validate_destination!(destination, output)
|
|
37
|
+
File.open(output, write_flags, 0o644) { |file| file.write(@content) }
|
|
38
|
+
true
|
|
39
|
+
rescue Errno::ELOOP
|
|
40
|
+
raise Jekyll::Errors::FatalException, "unsafe generated destination: #{output.inspect}"
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
private
|
|
44
|
+
|
|
45
|
+
# Validate a decoded copy, but keep the encoded URL for StaticFile so
|
|
46
|
+
# Jekyll performs exactly one decode when it computes the destination.
|
|
47
|
+
def validated_path(url)
|
|
48
|
+
path = url.to_s
|
|
49
|
+
decoded_path = Jekyll::URL.unescape_path(path)
|
|
50
|
+
return path if root_relative?(decoded_path) && !decoded_path.split("/").include?("..")
|
|
51
|
+
|
|
52
|
+
raise Jekyll::Errors::FatalException, "unsafe generated path: #{url.inspect}"
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def root_relative?(path)
|
|
56
|
+
path.start_with?("/") && !path.start_with?("//") && path != "/"
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def validate_destination!(destination, output)
|
|
60
|
+
root = File.expand_path(destination)
|
|
61
|
+
expanded_output = File.expand_path(output)
|
|
62
|
+
validate_destination_boundary!(root, expanded_output, output)
|
|
63
|
+
validate_destination_symlinks!(root, expanded_output, output)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def validate_destination_boundary!(root, expanded_output, output)
|
|
67
|
+
return if expanded_output.start_with?("#{root}#{File::SEPARATOR}")
|
|
68
|
+
|
|
69
|
+
raise Jekyll::Errors::FatalException, "unsafe generated destination: #{output.inspect}"
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def validate_destination_symlinks!(root, expanded_output, output)
|
|
73
|
+
relative_path = expanded_output.delete_prefix("#{root}#{File::SEPARATOR}")
|
|
74
|
+
current_path = root
|
|
75
|
+
unsafe = relative_path.split(File::SEPARATOR).any? do |component|
|
|
76
|
+
current_path = File.join(current_path, component)
|
|
77
|
+
File.symlink?(current_path)
|
|
78
|
+
end
|
|
79
|
+
return unless unsafe
|
|
80
|
+
|
|
81
|
+
raise Jekyll::Errors::FatalException, "unsafe generated destination: #{output.inspect}"
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def write_flags
|
|
85
|
+
flags = File::WRONLY | File::CREAT | File::TRUNC | File::BINARY
|
|
86
|
+
return flags unless File::Constants.const_defined?(:NOFOLLOW)
|
|
87
|
+
|
|
88
|
+
flags | File::Constants::NOFOLLOW
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: jekyll-agent-markdown
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Lucian Ghinda
|
|
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.3'
|
|
19
|
+
- - "<"
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: '5'
|
|
22
|
+
type: :runtime
|
|
23
|
+
prerelease: false
|
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
25
|
+
requirements:
|
|
26
|
+
- - ">="
|
|
27
|
+
- !ruby/object:Gem::Version
|
|
28
|
+
version: '4.3'
|
|
29
|
+
- - "<"
|
|
30
|
+
- !ruby/object:Gem::Version
|
|
31
|
+
version: '5'
|
|
32
|
+
description: A Jekyll plugin that makes post Markdown available alongside rendered
|
|
33
|
+
HTML.
|
|
34
|
+
email:
|
|
35
|
+
- lucian@ghinda.com
|
|
36
|
+
executables: []
|
|
37
|
+
extensions: []
|
|
38
|
+
extra_rdoc_files: []
|
|
39
|
+
files:
|
|
40
|
+
- CHANGELOG.md
|
|
41
|
+
- LICENSE.txt
|
|
42
|
+
- README.md
|
|
43
|
+
- lib/jekyll-agent-markdown.rb
|
|
44
|
+
- lib/jekyll/agent_markdown/configuration.rb
|
|
45
|
+
- lib/jekyll/agent_markdown/destination_claims.rb
|
|
46
|
+
- lib/jekyll/agent_markdown/generator.rb
|
|
47
|
+
- lib/jekyll/agent_markdown/markdown_sibling_path.rb
|
|
48
|
+
- lib/jekyll/agent_markdown/raw_markdown_file.rb
|
|
49
|
+
- lib/jekyll/agent_markdown/version.rb
|
|
50
|
+
homepage: https://github.com/lucianghinda/jekyll-agent-markdown
|
|
51
|
+
licenses:
|
|
52
|
+
- Apache-2.0
|
|
53
|
+
metadata:
|
|
54
|
+
homepage_uri: https://github.com/lucianghinda/jekyll-agent-markdown
|
|
55
|
+
source_code_uri: https://github.com/lucianghinda/jekyll-agent-markdown/tree/main
|
|
56
|
+
changelog_uri: https://github.com/lucianghinda/jekyll-agent-markdown/blob/main/CHANGELOG.md
|
|
57
|
+
rubygems_mfa_required: 'true'
|
|
58
|
+
rdoc_options: []
|
|
59
|
+
require_paths:
|
|
60
|
+
- lib
|
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
62
|
+
requirements:
|
|
63
|
+
- - ">="
|
|
64
|
+
- !ruby/object:Gem::Version
|
|
65
|
+
version: 3.2.0
|
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
67
|
+
requirements:
|
|
68
|
+
- - ">="
|
|
69
|
+
- !ruby/object:Gem::Version
|
|
70
|
+
version: '0'
|
|
71
|
+
requirements: []
|
|
72
|
+
rubygems_version: 4.0.11
|
|
73
|
+
specification_version: 4
|
|
74
|
+
summary: Exports Jekyll posts as raw Markdown siblings and llms.txt
|
|
75
|
+
test_files: []
|