Class: Jekyll::Plugins::PaginateV3::Query::Parser
- Inherits:
-
Object
- Object
- Jekyll::Plugins::PaginateV3::Query::Parser
- Defined in:
- lib/jekyll-paginate-v3/query/parser.rb
Overview
Parses and evaluates the shared "search" format used across v3.
Supported input forms:
- String:
pages,posts,all,everything - Hash:
{ pages: '*' },{ posts: ['news/*', 'blog/*'] } - Array: combination of string/hash entries
- Delimited String:
pages, posts(delimiter is configurable)
Used by Pagination::Model and Templates::Builder to resolve configured sources into concrete site items.
Constant Summary collapse
- SEARCH_TYPE_PAGES =
Internal search-source identifiers. Keeping them distinct from collection labels means changing a keyword genuinely releases its former label.
'__paginate_v3_search_pages__'.freeze
- SEARCH_TYPE_ALL =
'__paginate_v3_search_all__'.freeze
- SEARCH_TYPE_EVERYTHING =
'__paginate_v3_search_everything__'.freeze
- SEARCH_TYPE_BY_KEY =
{ 'pages' => SEARCH_TYPE_PAGES, 'all' => SEARCH_TYPE_ALL, 'everything' => SEARCH_TYPE_EVERYTHING }.freeze
Class Method Summary collapse
-
.entry_label(entry) ⇒ Object
Formats one parsed entry into a compact human-readable label.
-
.first_type(raw_search, keywords, split_delimiter: ',') ⇒ Object
Returns the first parsed search type if present.
-
.normalise_keywords(raw_keywords) ⇒ Object
Normalises keyword mapping so callers can safely pass partial config.
-
.parse(raw_search, keywords, split_delimiter: ',') ⇒ Object
Parses a search definition into an array of normalised entries.
-
.path_allowed?(relative_path, normalised_paths) ⇒ Boolean
Matches a site-relative path against optional search path filters.
Class Method Details
.entry_label(entry) ⇒ Object
Formats one parsed entry into a compact human-readable label.
61 62 63 64 65 66 67 68 |
# File 'lib/jekyll-paginate-v3/query/parser.rb', line 61 def self.entry_label(entry) normalised_entry = Utils.safe_hash(entry) type = normalised_entry['type'].to_s.strip paths = Utils.arrayify(normalised_entry['paths']).map { |path| path.to_s.strip }.reject(&:empty?) return type if paths.empty? "#{type} (#{paths.join(', ')})" end |
.first_type(raw_search, keywords, split_delimiter: ',') ⇒ Object
Returns the first parsed search type if present.
42 43 44 |
# File 'lib/jekyll-paginate-v3/query/parser.rb', line 42 def self.first_type(raw_search, keywords, split_delimiter: ',') parse(raw_search, keywords, split_delimiter: split_delimiter).first&.fetch('type', nil) end |
.normalise_keywords(raw_keywords) ⇒ Object
Normalises keyword mapping so callers can safely pass partial config.
71 72 73 74 75 76 77 78 79 |
# File 'lib/jekyll-paginate-v3/query/parser.rb', line 71 def self.normalise_keywords(raw_keywords) defaults = { 'pages' => 'pages', 'all' => 'all', 'everything' => 'everything' } defaults.merge(Utils.safe_hash(raw_keywords)) end |
.parse(raw_search, keywords, split_delimiter: ',') ⇒ Object
Parses a search definition into an array of normalised entries.
Each entry has shape: { 'type' => <String>, 'paths' => <Array|nil> }
where paths == nil means no path filtering.
35 36 37 38 39 |
# File 'lib/jekyll-paginate-v3/query/parser.rb', line 35 def self.parse(raw_search, keywords, split_delimiter: ',') parsed_entries = [] parse_into(raw_search, keywords, parsed_entries, split_delimiter) parsed_entries end |
.path_allowed?(relative_path, normalised_paths) ⇒ Boolean
Matches a site-relative path against optional search path filters.
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/jekyll-paginate-v3/query/parser.rb', line 47 def self.path_allowed?(relative_path, normalised_paths) return true if normalised_paths.nil? || normalised_paths.empty? clean_path = Utils.remove_leading_slash(relative_path.to_s) normalised_paths.any? do |pattern| if pattern.include?('*') File.fnmatch?(pattern, clean_path, File::FNM_PATHNAME) else clean_path.start_with?(Utils.remove_leading_slash(pattern)) end end end |