trifle-docs 0.7.0 → 0.7.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: 9f51e6c6b892eaca5b790d652ccb970146c9e98b624cf3353c84af3ffb95ed4c
4
- data.tar.gz: f5058c9fa39c81a635db554fabffaab5535f57a76a078138319df0e72732cd49
3
+ metadata.gz: 2f5639f53f19ef35690cc1f68d2866cb05c8edc61f4c31cbe77f75c27083d27d
4
+ data.tar.gz: 197207ceb689bc6e539c37dc7443a9a513f4eb135436d0a04df58d7cfbab074b
5
5
  SHA512:
6
- metadata.gz: 48ce9ec16b882be46f90825f0e12bb13c783fa16e5b22f5eae27551418a5e58d112a321496fdf46810474c68de5f8933661931a696b6378bc836ffd7a8e74192
7
- data.tar.gz: 9721a213e1f2cef167e0adf4ed18025b0740ba6594e26f6f0f326e4e6412631f5957447f503cd2ca45c4ce4e2df5efb497a15a8aaf2943a29b246a2c373869a8
6
+ metadata.gz: 4647c880321bb90b15779068c670ce28961002f638ab447ed76dfb8ea2d49d8fe312edc3402d588c7399e1d5b7a73b53288c557a6a1ff4d02589af57b8684fe1
7
+ data.tar.gz: 312f3d0a696d060f7f871dee17946215fd8eb500783771f4d6fe962f4b533b5766e396b05b133aba83a52e28ce426d08348c30842b482e05412bfbd219c379e8
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- trifle-docs (0.7.0)
4
+ trifle-docs (0.7.1)
5
5
  redcarpet
6
6
  rouge
7
7
  sinatra
@@ -32,7 +32,7 @@ module Trifle
32
32
  content = Trifle::Docs::Helper::Llms.homepage_markdown
33
33
  halt(404, 'Not Found') if content.nil?
34
34
 
35
- content_type 'text/markdown'
35
+ content_type 'text/plain'
36
36
  content
37
37
  end
38
38
 
@@ -43,7 +43,7 @@ module Trifle
43
43
  content = Trifle::Docs::Helper::Llms.full_markdown
44
44
  halt(404, 'Not Found') if content.nil? || content.strip.empty?
45
45
 
46
- content_type 'text/markdown'
46
+ content_type 'text/plain'
47
47
  content
48
48
  end
49
49
 
@@ -77,6 +77,7 @@ module Trifle
77
77
  meta = Trifle::Docs.meta(url: url)
78
78
  halt(404, 'Not Found') if meta.nil?
79
79
 
80
+ set_vary_header unless meta['type'] == 'file'
80
81
  return render_markdown(meta, url) if render_markdown?(meta, request, params)
81
82
  return send_file(meta['path']) if meta['type'] == 'file'
82
83
 
@@ -84,7 +85,7 @@ module Trifle
84
85
  end
85
86
 
86
87
  def render_markdown(meta, url)
87
- content_type 'text/markdown'
88
+ content_type markdown_content_type(request)
88
89
  Trifle::Docs::Helper::MarkdownLayout.render(
89
90
  meta: meta,
90
91
  raw_content: Trifle::Docs.raw_content(url: url),
@@ -110,6 +111,25 @@ module Trifle
110
111
  content
111
112
  end
112
113
 
114
+ def markdown_content_type(request)
115
+ return 'text/plain' if Trifle::Docs::Helper::AiDetection.ai_scraper?(request.user_agent)
116
+
117
+ 'text/markdown'
118
+ end
119
+
120
+ def set_vary_header
121
+ headers['Vary'] = append_vary(headers['Vary'], 'User-Agent')
122
+ headers['Vary'] = append_vary(headers['Vary'], 'Accept')
123
+ end
124
+
125
+ def append_vary(existing, value)
126
+ values = existing.to_s.split(',').map(&:strip).reject(&:empty?)
127
+ return value if values.empty?
128
+ return existing if values.any? { |entry| entry.casecmp(value).zero? }
129
+
130
+ (values + [value]).join(', ')
131
+ end
132
+
113
133
  private :handle_request
114
134
  end
115
135
  end
@@ -37,7 +37,7 @@ if Object.const_defined?('Rails')
37
37
  return render_not_found if content.nil?
38
38
  return render_not_found if !allow_empty && content.strip.empty?
39
39
 
40
- render plain: content, content_type: 'text/markdown'
40
+ render plain: content, content_type: 'text/plain'
41
41
  end
42
42
 
43
43
  def render_sitemap(url)
@@ -73,7 +73,7 @@ if Object.const_defined?('Rails')
73
73
  meta: meta,
74
74
  raw_content: Trifle::Docs.raw_content(url: url, config: configuration),
75
75
  sitemap: Trifle::Docs.sitemap(config: configuration)
76
- ), content_type: 'text/markdown'
76
+ ), content_type: markdown_content_type
77
77
  end
78
78
 
79
79
  def fetch_meta(url)
@@ -81,6 +81,7 @@ if Object.const_defined?('Rails')
81
81
  end
82
82
 
83
83
  def render_for_meta(meta, url, wants_md, request)
84
+ set_vary_header unless file_meta?(meta)
84
85
  return render_markdown(url: url, meta: meta) if render_markdown?(meta, wants_md, request)
85
86
  return render_file(meta: meta) if file_meta?(meta)
86
87
 
@@ -110,6 +111,25 @@ if Object.const_defined?('Rails')
110
111
 
111
112
  request.headers['Accept'].to_s.include?('text/markdown')
112
113
  end
114
+
115
+ def markdown_content_type
116
+ return 'text/plain' if Trifle::Docs::Helper::AiDetection.ai_scraper?(request.user_agent)
117
+
118
+ 'text/markdown'
119
+ end
120
+
121
+ def set_vary_header
122
+ response.headers['Vary'] = append_vary(response.headers['Vary'], 'User-Agent')
123
+ response.headers['Vary'] = append_vary(response.headers['Vary'], 'Accept')
124
+ end
125
+
126
+ def append_vary(existing, value)
127
+ values = existing.to_s.split(',').map(&:strip).reject(&:empty?)
128
+ return value if values.empty?
129
+ return existing if values.any? { |entry| entry.casecmp(value).zero? }
130
+
131
+ (values + [value]).join(', ')
132
+ end
113
133
  end
114
134
 
115
135
  class PageController < ActionController::Base
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Trifle
4
4
  module Docs
5
- VERSION = '0.7.0'
5
+ VERSION = '0.7.1'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trifle-docs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jozef Vaclavik
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-01-27 00:00:00.000000000 Z
11
+ date: 2026-01-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler