llm-docs-builder 1.1.0 → 1.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c9ce6fbe87a426d69139719ecd76489c5aed030517167758ea0b2df452f3d636
4
- data.tar.gz: 9ce3bfab8d25b4c3a9f11b899f20038da89463eb82ffde1b69106ce4934377c8
3
+ metadata.gz: 924dcb07f4f13389791b2667f921ee7a4c4b1528f0177947e322e60590a10ae4
4
+ data.tar.gz: bbb45ad93c3691b89ad5ebbe8bd445ae8aeaf28014965403bcd1453cef64cd35
5
5
  SHA512:
6
- metadata.gz: 9f98c868bfde76f265dd69854a43da9c67b48f5310234611105a6dec00a62236070461484b52c8e08c85cf9fd7bfcbffea0a85e92ce0943ac879b9dc532d3b77
7
- data.tar.gz: 6a6340a373df54139338af837a7755b3148fdaef4d58810779cd88b5e2c5f1cca6edda231cee9e3cdace9cc60d465b14e0d78ecf41c3e338fb9fc40029d3f4c0
6
+ metadata.gz: 42cf1209d78964b9efdc66969c2085ec403b92493af1f93628280b77965c23acff5131d126bdd5d210eab0fb9484b4c71f7836d5547754650443133dafa161a3
7
+ data.tar.gz: ed64b63741192464c38db29a107bf10b4f1fa3089842839cc0f1f0eecb3410b6724a1281c02e1aab7f92e75a18eac7df12bfcb847588cf245780cae7fe8e01b0
@@ -0,0 +1,2 @@
1
+ # Every change needs a review from a maintainer before it can merge.
2
+ * @mensfeld
@@ -41,7 +41,7 @@ jobs:
41
41
  run: rm -f Gemfile.lock
42
42
 
43
43
  - name: Set up Ruby
44
- uses: ruby/setup-ruby@7f797815d8adceb1c412e7abefdd1ab4abc47a5f # v1.335.0
44
+ uses: ruby/setup-ruby@145243922b4465b78e04dd66294782c7de45901f # v1.345.0
45
45
  with:
46
46
  ruby-version: ${{ matrix.ruby }}
47
47
  bundler-cache: true
@@ -66,9 +66,9 @@ jobs:
66
66
  steps:
67
67
  - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
68
68
  - name: Set up Ruby
69
- uses: ruby/setup-ruby@7f797815d8adceb1c412e7abefdd1ab4abc47a5f # v1.335.0
69
+ uses: ruby/setup-ruby@145243922b4465b78e04dd66294782c7de45901f # v1.345.0
70
70
  with:
71
- ruby-version: '4.0.9'
71
+ ruby-version: '4.0.10'
72
72
  bundler-cache: true
73
73
  - name: Run yard-lint
74
74
  run: bundle exec yard-lint lib/
@@ -52,14 +52,14 @@ jobs:
52
52
 
53
53
  - name: Login to Docker Hub
54
54
  if: github.event_name != 'pull_request'
55
- uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4
55
+ uses: docker/login-action@8aa5831fb8d48d8f76594c7ddde61ae58019f550 # v4
56
56
  with:
57
57
  username: ${{ secrets.DOCKERHUB_USERNAME }}
58
58
  password: ${{ secrets.DOCKERHUB_TOKEN }}
59
59
 
60
60
  - name: Login to GitHub Container Registry
61
61
  if: github.event_name != 'pull_request'
62
- uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4
62
+ uses: docker/login-action@8aa5831fb8d48d8f76594c7ddde61ae58019f550 # v4
63
63
  with:
64
64
  registry: ghcr.io
65
65
  username: ${{ github.actor }}
@@ -24,7 +24,7 @@ jobs:
24
24
  fetch-depth: 0
25
25
 
26
26
  - name: Set up Ruby
27
- uses: ruby/setup-ruby@7f797815d8adceb1c412e7abefdd1ab4abc47a5f # v1.335.0
27
+ uses: ruby/setup-ruby@145243922b4465b78e04dd66294782c7de45901f # v1.345.0
28
28
  with:
29
29
  bundler-cache: false
30
30
 
@@ -32,4 +32,4 @@ jobs:
32
32
  run: |
33
33
  bundle install --jobs 4 --retry 3
34
34
 
35
- - uses: rubygems/release-gem@7f9650160c1a4e7989fdc9855807bdbd421d8b6b # v1.4.1
35
+ - uses: rubygems/release-gem@2654a0fe0dc39725c07fe84d7fe863a084f2424e # v1.5.0
@@ -0,0 +1,23 @@
1
+ name: Verify Action Pins
2
+ on:
3
+ pull_request:
4
+ paths:
5
+ - '.github/workflows/**'
6
+ jobs:
7
+ verify_action_pins:
8
+ runs-on: ubuntu-latest
9
+ steps:
10
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
11
+ - name: Check SHA pins
12
+ run: |
13
+ # Every remote action must be pinned to a full 40-character commit SHA. Local actions
14
+ # (./) and docker:// images are not checked.
15
+ unpinned=$(grep -E -rn --include="*.yml" --include="*.yaml" \
16
+ "^[[:space:]]*(-[[:space:]]+)?uses:[[:space:]]*['\"]?[^.'\"[:space:]]" .github/workflows/ \
17
+ | grep -Ev "uses:[[:space:]]*['\"]?docker://" \
18
+ | grep -Ev "@[0-9a-f]{40}['\"]?([[:space:]]|$)" || true)
19
+ if [ -n "$unpinned" ]; then
20
+ echo "$unpinned"
21
+ echo "::error::Actions should use SHA pins, not tags or branch names"
22
+ exit 1
23
+ fi
data/.rubocop.yml CHANGED
@@ -18,6 +18,10 @@ Metrics/ClassLength:
18
18
  Metrics/MethodLength:
19
19
  Max: 35
20
20
 
21
+ Metrics/ModuleLength:
22
+ Exclude:
23
+ - 'lib/llm_docs_builder/transformers/code_blocks.rb'
24
+
21
25
  Metrics/AbcSize:
22
26
  Max: 40
23
27
 
@@ -40,6 +44,11 @@ Style/MultilineBlockChain:
40
44
  Exclude:
41
45
  - 'spec/**/*'
42
46
 
47
+ # CLI errors must reach stderr even with warnings disabled (-W0), which silences warn
48
+ Style/StderrPuts:
49
+ Exclude:
50
+ - 'lib/llm_docs_builder/cli.rb'
51
+
43
52
  # Disable predicate method naming rule
44
53
  Naming/PredicateMethod:
45
54
  Enabled: false
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 4.0.9
1
+ 4.0.10
data/CHANGELOG.md CHANGED
@@ -1,5 +1,34 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.1.1 (2026-12-03)
4
+ - [Fix] **`bulk-transform` Resolves Relative Links From `base_url` Again** - 1.1.0 made `bulk-transform` resolve relative links from each file's directory, so sites that keep each page in `<Page>/index.md` with links written relative to the docs root got every link nested under the page (`<base_url>/Getting-Started/Kafka-Setup` instead of `<base_url>/Kafka-Setup`), which return 404. The default is back to resolving from `base_url`, as before 1.1.0.
5
+ - Set `relative_links: file` to keep the 1.1.0 behavior (links and query-only links resolve from each file's directory). Any value other than `base_url` or `file` fails with `Invalid relative_links: <value> (use base_url or file)`.
6
+ - [Fix] **`transform` No Longer Overwrites the Generated `llms.txt`** - `transform` writes a file only when `-o/--output` is given, and prints to stdout otherwise. Before, it wrote to the config's `output` (the `generate` target, e.g. `public/llms.txt`), and `-o llms.txt` printed to stdout instead of writing the file.
7
+ - If you relied on the config's `output` for `transform`, pass `-o` instead.
8
+ - [Fix] **Compression Options Keep Code Unchanged** - `remove_duplicates` and `remove_stopwords` no longer edit fenced code, indented code or inline code.
9
+ - `remove_duplicates` no longer drops the last lines and the closing fence of a code block that ends like an earlier one, so the rest of the document no longer turns into code.
10
+ - `remove_stopwords` also keeps `~~~` and indented code blocks and bare URLs (`https://example.com/how-to/use-the-api`) unchanged.
11
+ - `remove_duplicates` keeps repeated paragraphs that hold inline code.
12
+ - `normalize_headings` skips every code block the other options detect, so a `#` line in a ```` block that holds a ``` line no longer counts as a heading.
13
+ - [Fix] **Cleanup Options Keep Code Unchanged** - `remove_comments`, `remove_badges`, `remove_images` and `remove_blockquotes` no longer edit fenced code, indented code or inline code, so HTML and Markdown examples stay intact. With `remove_blockquotes`, code inside a blockquote loses its quote markers like the text around it.
14
+ - [Fix] **Missing `--config` File Fails the Run** - `generate`, `transform` and `bulk-transform` now exit 1 with `Config file not found: <path>` when the file given with `--config` does not exist, and write nothing. Before, they ran with the defaults (`docs: .`), so `bulk-transform` wrote `*.llm.md` next to every Markdown file under the current directory. Without `--config`, a missing `llm-docs-builder.yml` still means the defaults. `Config.new` with a missing file is unchanged.
15
+ - [Fix] **CLI Errors Go to stderr** - Error messages are now printed to stderr instead of stdout, so `transform -d missing.md > out.md` no longer writes the error into `out.md`. The `validate` report ("Invalid llms.txt file" and its errors) stays on stdout, as the command's result. Only CLI output changes, not the Ruby API.
16
+ - [Fix] **Unknown Options Are Usage Errors** - An unknown option (e.g. `transform --foo`) now prints `Error: invalid option: --foo` and a pointer to `--help` instead of `Unexpected error: ...`.
17
+ - [Fix] **`parse` Prints Its Summary Without `--verbose`** - `parse` now always prints the title, description and link counts; `--verbose` also lists each link.
18
+ - [Fix] **`transform --output` Ends the File With a Newline** - The output file now ends with `\n`; one is added only if the content lacks it.
19
+ - [Fix] **`--config` No Longer Mixes In `llm-docs-builder.yml`** - With `--config other.yml`, keys that `other.yml` leaves out (`title`, `description`, `base_url`, `body`, `custom_instruction`) are no longer taken from `llm-docs-builder.yml` in the current directory. The config is now loaded once.
20
+ - [Fix] **`remove_code_examples` No Longer Truncates Documents** - The first line indented by four spaces or a tab no longer deletes everything after it. Only indented code blocks are removed; nested list items and list continuation lines stay.
21
+ - A heading or a fence that is not indented now ends a list, so indented code after it counts as code. `base_url` and `convert_urls` no longer rewrite links in such code either.
22
+ - [Fix] **`parse` and `validate` Read `llms.txt` by Default** - Without `--docs`, both commands now read `llms.txt` in the current directory, as documented. Before, they took the config's `docs` setting (the docs directory for `generate`, `.` by default) and failed with "Is a directory".
23
+ - [Fix] **`bulk-transform` Skips Nested Excludes and Hidden Directories** - `bulk-transform` now picks files like `generate` does.
24
+ - A trailing `/**` in `excludes` matches files at any depth (`**/private/**` now skips `private/sub/b.md`), and patterns also match the path relative to the docs directory.
25
+ - Hidden directories (e.g. `.github/`) are skipped unless `include_hidden` is set, as documented in 0.9.4.
26
+ - [Fix] **llms.txt Sections Match the Documented Priorities** - `generate` now sorts pages into sections as the README describes.
27
+ - Pages that match no rule (e.g. `configuration.md`, `install.md`) go to `Documentation` (`priority:medium`) instead of `Optional` (`priority:low`).
28
+ - API docs (`api.md`) go to `Documentation` instead of `Examples`.
29
+ - Example files (`examples.md`) go to `Examples`.
30
+ - Only reference and advanced pages (`reference.md`, `advanced.md`) stay in `Optional`.
31
+
3
32
  ## 1.1.0 (2026-11-02)
4
33
  - [Enhancement] **Relative Link Resolution** - `base_url` link expansion now resolves relative links like a browser would.
5
34
  - `../` and `./` segments are normalized (`../other.md` → `https://example.com/other.md` instead of `https://example.com/docs/../other.md`).
data/Dockerfile CHANGED
@@ -4,7 +4,7 @@
4
4
  # Creates a minimal Docker image (~50MB) for running the CLI without Ruby installation
5
5
 
6
6
  # Stage 1: Builder
7
- FROM ruby:4.0-alpine AS builder
7
+ FROM ruby:4.0.10-alpine AS builder
8
8
 
9
9
  # Install build dependencies
10
10
  RUN apk add --no-cache \
@@ -36,7 +36,7 @@ RUN bundle config set --local without 'development test' && \
36
36
  RUN gem build llm-docs-builder.gemspec
37
37
 
38
38
  # Stage 2: Runtime
39
- FROM ruby:4.0-alpine
39
+ FROM ruby:4.0.10-alpine
40
40
 
41
41
  # Install runtime dependencies and build tools for native extensions
42
42
  RUN apk add --no-cache \
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- llm-docs-builder (1.1.0)
4
+ llm-docs-builder (1.1.1)
5
5
  nokogiri (~> 1.17)
6
6
  zeitwerk (~> 2.6)
7
7
 
@@ -11,20 +11,20 @@ GEM
11
11
  ast (2.4.3)
12
12
  coderay (1.1.3)
13
13
  diff-lcs (1.6.2)
14
- io-console (0.9.4)
15
- json (3.0.2)
14
+ io-console (0.9.5)
15
+ json (3.2.0)
16
16
  language_server-protocol (3.17.0.6)
17
17
  lint_roller (1.1.0)
18
18
  method_source (1.1.0)
19
19
  mini_portile2 (2.8.9)
20
- nokogiri (1.19.4)
20
+ nokogiri (1.19.7)
21
21
  mini_portile2 (~> 2.8.2)
22
22
  racc (~> 1.4)
23
- parallel (2.2.0)
24
- parser (3.3.12.0)
23
+ parallel (2.3.0)
24
+ parser (3.3.14.0)
25
25
  ast (~> 2.4.1)
26
26
  racc
27
- prism (1.9.0)
27
+ prism (2.1.0)
28
28
  pry (0.16.1)
29
29
  coderay (~> 1.1)
30
30
  method_source (~> 1.0)
@@ -32,44 +32,46 @@ GEM
32
32
  racc (1.8.1)
33
33
  rainbow (3.1.1)
34
34
  rake (13.4.2)
35
- regexp_parser (2.13.1)
35
+ regexp_parser (2.13.4)
36
36
  reline (0.7.0)
37
37
  io-console (~> 0.5)
38
38
  rspec (3.13.2)
39
39
  rspec-core (~> 3.13.0)
40
40
  rspec-expectations (~> 3.13.0)
41
41
  rspec-mocks (~> 3.13.0)
42
- rspec-core (3.13.6)
42
+ rspec-core (3.13.7)
43
43
  rspec-support (~> 3.13.0)
44
- rspec-expectations (3.13.5)
44
+ rspec-expectations (3.13.6)
45
45
  diff-lcs (>= 1.2.0, < 2.0)
46
46
  rspec-support (~> 3.13.0)
47
- rspec-mocks (3.13.8)
47
+ rspec-mocks (3.13.9)
48
48
  diff-lcs (>= 1.2.0, < 2.0)
49
49
  rspec-support (~> 3.13.0)
50
- rspec-support (3.13.7)
51
- rubocop (1.91.0)
50
+ rspec-support (3.13.8)
51
+ rubocop (1.93.0)
52
52
  json (>= 2.3)
53
53
  language_server-protocol (~> 3.17.0.2)
54
54
  lint_roller (~> 1.1.0)
55
55
  parallel (>= 1.10)
56
56
  parser (>= 3.3.0.2)
57
57
  rainbow (>= 2.2.2, < 4.0)
58
- regexp_parser (>= 2.9.3, < 3.0)
59
- rubocop-ast (>= 1.49.0, < 2.0)
58
+ regexp_parser (>= 2.11.3, < 3.0)
59
+ rubocop-ast (>= 1.54.0, < 2.0)
60
60
  ruby-progressbar (~> 1.7)
61
61
  unicode-display_width (>= 2.4.0, < 4.0)
62
- rubocop-ast (1.50.0)
62
+ rubocop-ast (1.54.0)
63
+ ast (~> 2.4)
63
64
  parser (>= 3.3.7.2)
64
- prism (~> 1.7)
65
+ prism (>= 1.7)
66
+ racc
65
67
  ruby-progressbar (1.13.0)
66
68
  simplecov (1.3.2)
67
69
  unicode-display_width (3.3.0)
68
70
  unicode-emoji (~> 4.3)
69
71
  unicode-emoji (4.3.0)
70
72
  warning (1.6.0)
71
- yard (0.9.45)
72
- yard-lint (1.13.0)
73
+ yard (0.9.46)
74
+ yard-lint (1.15.0)
73
75
  yard (~> 0.9)
74
76
  zeitwerk (~> 2.6)
75
77
  zeitwerk (2.8.3)
data/README.md CHANGED
@@ -163,12 +163,20 @@ calculate_compression: false # Calculate compression ratios (slower)
163
163
  excludes:
164
164
  - "**/private/**"
165
165
  - "**/drafts/**"
166
+ include_hidden: false # Include files in hidden directories (e.g. .github/)
166
167
  ```
167
168
 
169
+ **Output file (`output`):** the `llms.txt` path that `generate` writes. `transform` does not use it: it prints to stdout, or writes the file given with `-o`.
170
+
171
+ **File selection (`generate` and `bulk-transform`):** both commands pick the same `.md` files under `docs`.
172
+ - `excludes` patterns match the path relative to `docs` (`private/a.md`) or the path starting with the `docs` value as written (`./docs/private/a.md`); a trailing `/**` matches files at any depth.
173
+ - Hidden directories (names starting with `.`, e.g. `.github/`) are skipped by default. Set `include_hidden: true` to include their files. Hidden files (e.g. `.notes.md`) are always skipped.
174
+
168
175
  **Link expansion (`base_url`):** relative links become absolute URLs.
169
176
  - Inline links, images (also linked images, `[![alt](a.png)](../intro.md)`) and reference-style definitions (`[a]: ../intro.md`) are expanded. `<path with spaces>` destinations are resolved and their spaces encoded as `%20`.
170
- - `bulk-transform` resolves links from each file's directory under `docs`. Single-file `transform` (and `LlmDocsBuilder.transform_markdown`) resolves them from `base_url`: with `base_url: https://myproject.io/docs`, `../intro.md` becomes `https://myproject.io/intro.md`.
171
- - Links starting with `/` resolve from `base_url`. In `bulk-transform`, a query-only link (`[q](?tab=2)`) resolves to the current page (`.../page.md?tab=2`).
177
+ - Relative links resolve from `base_url` (`relative_links: base_url`, the default): with `base_url: https://myproject.io/docs`, `../intro.md` becomes `https://myproject.io/intro.md`, and `[Setup](Kafka-Setup)` in `Getting-Started/index.md` becomes `https://myproject.io/docs/Kafka-Setup`. This fits sites that keep each page in its own directory (`<Page>/index.md`) with links written relative to the docs root.
178
+ - `relative_links: file` makes `bulk-transform` resolve links from each file's directory under `docs` instead, like a browser on a file tree: `./setup.md` in `guides/intro.md` becomes `<base_url>/guides/setup.md`, and a query-only link (`[q](?tab=2)`) resolves to the current page (`.../page.md?tab=2`). Single-file `transform` always resolves from `base_url`.
179
+ - Links starting with `/` resolve from `base_url`.
172
180
  - Left unchanged: links in fenced code, indented code and inline code; anchors (`#x`); protocol-relative URLs (`//cdn.io/a.md`); URLs with any scheme, in any case (`HTTPS:`, `sftp:`, `urn:`, `mailto:`); HTML `<a href>` and `<img src>`.
173
181
 
174
182
  ## CLI Commands
@@ -322,8 +330,8 @@ Generate enriched llms.txt files with token counts, timestamps, and priority lab
322
330
  **Enhanced llms.txt (with metadata enabled):**
323
331
  ```markdown
324
332
  - [Getting Started](https://myproject.io/docs/Getting-Started.md): Quick start guide (tokens:450, updated:2025-10-13, priority:high)
325
- - [Configuration](https://myproject.io/docs/Configuration.md): Configuration options (tokens:2800, updated:2025-10-12, priority:high)
326
- - [Advanced Topics](https://myproject.io/docs/Advanced.md): Deep dive topics (tokens:5200, updated:2025-09-15, priority:medium)
333
+ - [Configuration](https://myproject.io/docs/Configuration.md): Configuration options (tokens:2800, updated:2025-10-12, priority:medium)
334
+ - [Advanced Topics](https://myproject.io/docs/Advanced.md): Deep dive topics (tokens:5200, updated:2025-09-15, priority:low)
327
335
  ```
328
336
 
329
337
  **Benefits:**
@@ -348,7 +356,7 @@ calculate_compression: true # Show compression ratios (slower, requires transfor
348
356
  Documents are automatically organized into multiple sections based on priority, following the llms.txt specification:
349
357
 
350
358
  **Priority-based categorization:**
351
- - **Documentation** (priority 1-3): Essential docs like README, getting started guides, user guides
359
+ - **Documentation** (priority 1-3): README, getting started guides, user guides, API docs and every page that matches no other rule
352
360
  - **Examples** (priority 4-5): Tutorials and example files
353
361
  - **Optional** (priority 6-7): Advanced topics and reference documentation
354
362
 
@@ -362,6 +370,8 @@ Documents are automatically organized into multiple sections based on priority,
362
370
 
363
371
  - [README](README.md): Main documentation
364
372
  - [Getting Started](getting-started.md): Quick start guide
373
+ - [Configuration](configuration.md): Configuration options
374
+ - [API](api.md): Public API
365
375
 
366
376
  ## Examples
367
377
 
@@ -370,8 +380,8 @@ Documents are automatically organized into multiple sections based on priority,
370
380
 
371
381
  ## Optional
372
382
 
373
- - [Advanced Topics](advanced.md): Deep dive into advanced features
374
383
  - [API Reference](reference.md): Complete API reference
384
+ - [Advanced Topics](advanced.md): Deep dive into advanced features
375
385
  ```
376
386
 
377
387
  Empty sections are automatically omitted. The "Optional" section aligns with the llms.txt spec for marking secondary content that can be skipped when context windows are limited.
@@ -415,8 +425,10 @@ All compression features can be used individually for fine-grained control:
415
425
  - `remove_images: true` - Remove all image syntax
416
426
  - `remove_code_examples: true` - Remove fenced code blocks, indented code, and inline code
417
427
  - `remove_blockquotes: true` - Remove blockquote formatting (preserves content)
418
- - `remove_duplicates: true` - Remove duplicate paragraphs using fuzzy matching
419
- - `remove_stopwords: true` - Remove common stopwords from prose (preserves code blocks)
428
+ - `remove_duplicates: true` - Remove paragraphs that repeat an earlier one after whitespace and case normalization (paragraphs with code are kept)
429
+ - `remove_stopwords: true` - Remove common stopwords from prose (preserves code blocks, inline code and bare URLs)
430
+
431
+ `remove_comments`, `remove_badges`, `remove_images` and `remove_blockquotes` leave code (fenced, indented and inline) unchanged.
420
432
 
421
433
  ### Content Enhancement Options
422
434
 
@@ -29,8 +29,11 @@ module LlmDocsBuilder
29
29
  # @param options [Hash] transformation options
30
30
  # @option options [String] :base_url base URL for expanding relative links
31
31
  # @option options [Boolean] :convert_urls convert HTML URLs to markdown format
32
+ # @option options [String] :relative_links `'base_url'` (default) resolves relative links from
33
+ # `base_url`, `'file'` from each file's directory
32
34
  # @option options [String] :suffix suffix for transformed files (default: '.llm')
33
35
  # @option options [Array<String>] :excludes glob patterns for files to exclude
36
+ # @option options [Boolean] :include_hidden include files in hidden directories
34
37
  # @option options [Boolean] :verbose enable verbose output
35
38
  def initialize(docs_path, options = {})
36
39
  @docs_path = docs_path
@@ -53,8 +56,6 @@ module LlmDocsBuilder
53
56
  transformed_files = []
54
57
 
55
58
  markdown_files.each do |file_path|
56
- next if should_exclude?(file_path)
57
-
58
59
  puts "Transforming #{file_path}..." if options[:verbose]
59
60
 
60
61
  transformed_content = transform_file(file_path)
@@ -76,50 +77,29 @@ module LlmDocsBuilder
76
77
 
77
78
  # Recursively scans the docs directory for markdown files
78
79
  #
79
- # Skips hidden files (starting with dot) and already transformed files (ending with
80
- # the suffix, e.g. README.llm.md) and returns sorted array of paths
80
+ # See MarkdownFinder for the files it skips
81
81
  #
82
- # @return [Array<String>] paths to markdown files
82
+ # @return [Array<String>] sorted paths to markdown files
83
83
  def find_markdown_files
84
- files = []
85
- output_ending = "#{options[:suffix]}.md".downcase
86
-
87
- Find.find(docs_path) do |path|
88
- next unless File.file?(path)
89
- next unless path.match?(/\.md$/i)
90
- next if File.basename(path).start_with?('.')
91
- next if output_ending != '.md' && path.downcase.end_with?(output_ending)
92
-
93
- files << path
94
- end
95
-
96
- files.sort
97
- end
98
-
99
- # Tests if file matches any exclusion pattern from options
100
- #
101
- # Uses File.fnmatch with pathname and dotmatch flags
102
- #
103
- # @param file_path [String] path to check
104
- # @return [Boolean] true if file should be excluded
105
- def should_exclude?(file_path)
106
- excludes = Array(options[:excludes])
107
-
108
- excludes.any? do |pattern|
109
- File.fnmatch(pattern, file_path, File::FNM_PATHNAME | File::FNM_DOTMATCH)
110
- end
84
+ MarkdownFinder.new(docs_path, options).files.sort
111
85
  end
112
86
 
113
87
  # Applies markdown transformations to a single file
114
88
  #
115
- # Creates MarkdownTransformer instance and delegates transformation. Passes the file's
116
- # path relative to the docs directory so relative links resolve from its own location.
89
+ # Creates MarkdownTransformer instance and delegates transformation. With `relative_links: 'file'`
90
+ # it passes the file's path relative to the docs directory so relative links resolve from its own
91
+ # location; otherwise they resolve from `base_url`.
117
92
  #
118
93
  # @param file_path [String] path to markdown file
119
94
  # @return [String] transformed content
120
95
  def transform_file(file_path)
121
- source_path = Pathname.new(file_path).relative_path_from(Pathname.new(docs_path)).to_s
122
- transformer = MarkdownTransformer.new(file_path, options.merge(source_path: source_path))
96
+ file_options = options
97
+ if options[:relative_links].to_s == 'file'
98
+ source_path = Pathname.new(file_path).relative_path_from(Pathname.new(docs_path)).to_s
99
+ file_options = options.merge(source_path: source_path)
100
+ end
101
+
102
+ transformer = MarkdownTransformer.new(file_path, file_options)
123
103
  transformer.transform
124
104
  end
125
105