|
6 | 6 | -- from llms.md output independently of the HTML format. |
7 | 7 | -- Only runs when llms-txt is enabled (guarded by filterIf in main.lua). |
8 | 8 |
|
9 | | -local constants = require("modules/constants") |
10 | | - |
11 | | -local function list_contains(list, value) |
12 | | - if not list then return false end |
13 | | - for _, v in ipairs(list) do |
14 | | - if v == value then return true end |
15 | | - end |
16 | | - return false |
17 | | -end |
| 9 | +function llms_resolve_conditional_content() |
| 10 | + -- Determine if a ConditionalBlock should be visible for llms-txt output. |
| 11 | + -- Returns true (include), false (exclude), or nil (no llms-txt condition). |
| 12 | + local function is_llms_visible(tbl) |
| 13 | + local constants = require("modules/constants") |
| 14 | + local function list_contains(list, value) |
| 15 | + if not list then return false end |
| 16 | + for _, v in ipairs(list) do |
| 17 | + if v == value then return true end |
| 18 | + end |
| 19 | + return false |
| 20 | + end |
18 | 21 |
|
19 | | --- Determine if a ConditionalBlock should be visible for llms-txt output. |
20 | | --- Returns true (include), false (exclude), or nil (no llms-txt condition). |
21 | | -local function is_llms_visible(tbl) |
22 | | - local cond = tbl.condition |
23 | | - local has_when = list_contains(cond[constants.kWhenFormat], "llms-txt") |
24 | | - local has_unless = list_contains(cond[constants.kUnlessFormat], "llms-txt") |
| 22 | + local cond = tbl.condition |
| 23 | + local has_when = list_contains(cond[constants.kWhenFormat], "llms-txt") |
| 24 | + local has_unless = list_contains(cond[constants.kUnlessFormat], "llms-txt") |
25 | 25 |
|
26 | | - if not has_when and not has_unless then return nil end |
| 26 | + if not has_when and not has_unless then return nil end |
27 | 27 |
|
28 | | - if tbl.behavior == constants.kContentVisible then |
29 | | - -- content-visible when-format="llms-txt" -> include for llms |
30 | | - -- content-visible unless-format="llms-txt" -> exclude for llms |
31 | | - return has_when |
32 | | - else -- content-hidden |
33 | | - -- content-hidden when-format="llms-txt" -> exclude for llms |
34 | | - -- content-hidden unless-format="llms-txt" -> include for llms |
35 | | - return has_unless |
| 28 | + if tbl.behavior == constants.kContentVisible then |
| 29 | + -- content-visible when-format="llms-txt" -> include for llms |
| 30 | + -- content-visible unless-format="llms-txt" -> exclude for llms |
| 31 | + return has_when |
| 32 | + else -- content-hidden |
| 33 | + -- content-hidden when-format="llms-txt" -> exclude for llms |
| 34 | + -- content-hidden unless-format="llms-txt" -> include for llms |
| 35 | + return has_unless |
| 36 | + end |
36 | 37 | end |
37 | | -end |
38 | 38 |
|
39 | | -function llms_resolve_conditional_content() |
40 | 39 | return { |
41 | 40 | ConditionalBlock = function(tbl) |
42 | 41 | local llms_visible = is_llms_visible(tbl) |
|
0 commit comments