Module: Jekyll::VitePressTheme::SearchIndex
- Defined in:
- lib/jekyll/vitepress_theme/hooks.rb
Overview
rubocop:enable Metrics/ModuleLength
Defined Under Namespace
Classes: GeneratedPage
Constant Summary collapse
- TEMPLATE =
<<~LIQUID.freeze [ {% assign first = true %} {% assign home_page = site.pages | where: 'url', '/' | first %} {% if home_page %} {% assign home_excerpt = home_page.content | markdownify | strip_html | strip_newlines | replace: ' ', ' ' | strip | truncate: 2400, '' %} { "title": {{ home_page.title | default: site.title | strip_html | strip | jsonify }}, "url": {{ home_page.url | relative_url | jsonify }}, "content": {{ home_excerpt | jsonify }} } {% assign first = false %} {% endif %} {% assign generated_sidebar = site.data.jekyll_vitepress_sidebar %} {% assign sidebar_groups = generated_sidebar.groups | default: site.data.sidebar %} {% for group in sidebar_groups %} {% if group.docs %} {% assign docs = group.docs %} {% else %} {% assign docs = site[group.collection] | sort: 'nav_order' %} {% endif %} {% for doc in docs %} {% if doc.title and doc.url %} {% unless first %},{% endunless %} {% assign excerpt = doc.content | markdownify | strip_html | strip_newlines | replace: ' ', ' ' | strip | truncate: 2400, '' %} { "title": {{ doc.title | strip_html | strip | jsonify }}, "url": {{ doc.url | relative_url | jsonify }}, "content": {{ excerpt | jsonify }} } {% assign first = false %} {% endif %} {% endfor %} {% endfor %} ] LIQUID
Class Method Summary collapse
- .apply(site) ⇒ Object
- .custom_page?(site) ⇒ Boolean
- .search_index_path?(value) ⇒ Boolean
- .search_index_url?(value) ⇒ Boolean
Class Method Details
.apply(site) ⇒ Object
281 282 283 284 285 |
# File 'lib/jekyll/vitepress_theme/hooks.rb', line 281 def apply(site) return if custom_page?(site) site.pages << GeneratedPage.new(site) end |
.custom_page?(site) ⇒ Boolean
287 288 289 290 |
# File 'lib/jekyll/vitepress_theme/hooks.rb', line 287 def custom_page?(site) site.pages.any? { |page| search_index_path?(page.path) || search_index_url?(page.url) } || site.static_files.any? { |file| search_index_path?(file.path) || search_index_url?(file.relative_path) } end |
.search_index_path?(value) ⇒ Boolean
292 293 294 295 296 297 298 |
# File 'lib/jekyll/vitepress_theme/hooks.rb', line 292 def search_index_path?(value) return false unless value Pathname.new(value.to_s).basename.to_s == 'search.json' rescue ArgumentError false end |
.search_index_url?(value) ⇒ Boolean
300 301 302 |
# File 'lib/jekyll/vitepress_theme/hooks.rb', line 300 def search_index_url?(value) value.to_s.strip == '/search.json' end |