jekyll-vitepress-theme 1.2.1 → 1.2.2

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: 66fe5075d52518e812e3a2d8f6e17af3ac03678587c4ba791e577189b725374f
4
- data.tar.gz: 692859f3b2f76e628a59235a565cd4837663e663896d0d0770ac2ab123b2dc62
3
+ metadata.gz: 87a44689ffa884d7e6d6e6a7ab80c6919ecd5e09d828307d16a94816176fed28
4
+ data.tar.gz: 0b1346f4a809c05492379ac6464b958b251d4977e4a86fd7bfee6b758916856a
5
5
  SHA512:
6
- metadata.gz: 99c56f6757de3f76dd02188eb5f044b65d431b094153b75ea69c88cfc5af427a3467a3a96cf4e07c5434899b5942a8f00ad7b0886b0db39f816f3fff6ac3548f
7
- data.tar.gz: a6abce7ca7eaf12ec365ad41eb800f7f9ca7d470851670eda401979f7c45f8e499766d7c2fb9aff72702f52fbda95cbb017b4c4f8711f11d7dd19db9de7f44e1
6
+ metadata.gz: 137bbe877456978ccfd6d4565a3c05f6efa686f6361b8970ea21eb0aa93d659db5f286e460dd2d398ccab8b39e09f0c33c1b77e50a01a966ee161f459db467f9
7
+ data.tar.gz: 9ce78c0cc99df03cb514841771d83b8de04a058418dcb7694c69b631dcb2e1a3b1b38f3b4bf86e159f2babc1ab50ae9700f59fe031910f3713fcf193e8e390a0
data/README.md CHANGED
@@ -7,6 +7,7 @@ A reusable Jekyll theme gem that reproduces the VitePress default docs experienc
7
7
  - VitePress-style layout structure (top nav, sidebar, outline, doc footer)
8
8
  - Appearance toggle with `auto -> dark -> light`
9
9
  - Local search modal (`/`, `Ctrl/Cmd+K`, `Cmd+K`)
10
+ - Automatic `/search.json` generation for the home page and sidebar collections
10
11
  - Optional GitHub star button with live count (`jekyll_vitepress.github_star`)
11
12
  - Code block copy button, language labels, file-title bars and icons
12
13
  - Page-level "Copy page" split button with raw Markdown copy + plain `.md` view (`jekyll_vitepress.copy_page`, enabled by default)
@@ -3,6 +3,75 @@ require 'rouge'
3
3
 
4
4
  module Jekyll
5
5
  module VitePressTheme
6
+ module SearchIndex
7
+ module_function
8
+
9
+ TEMPLATE = <<~LIQUID.freeze
10
+ [
11
+ {% assign first = true %}
12
+ {% assign home_page = site.pages | where: 'url', '/' | first %}
13
+ {% if home_page %}
14
+ {% assign home_excerpt = home_page.content | markdownify | strip_html | strip_newlines | replace: ' ', ' ' | strip | truncate: 2400, '' %}
15
+ {
16
+ "title": {{ home_page.title | default: site.title | strip_html | strip | jsonify }},
17
+ "url": {{ home_page.url | relative_url | jsonify }},
18
+ "content": {{ home_excerpt | jsonify }}
19
+ }
20
+ {% assign first = false %}
21
+ {% endif %}
22
+ {% assign sidebar_groups = site.data.sidebar %}
23
+ {% for group in sidebar_groups %}
24
+ {% assign docs = site[group.collection] | sort: 'nav_order' %}
25
+ {% for doc in docs %}
26
+ {% if doc.title and doc.url %}
27
+ {% unless first %},{% endunless %}
28
+ {% assign excerpt = doc.content | markdownify | strip_html | strip_newlines | replace: ' ', ' ' | strip | truncate: 2400, '' %}
29
+ {
30
+ "title": {{ doc.title | strip_html | strip | jsonify }},
31
+ "url": {{ doc.url | relative_url | jsonify }},
32
+ "content": {{ excerpt | jsonify }}
33
+ }
34
+ {% assign first = false %}
35
+ {% endif %}
36
+ {% endfor %}
37
+ {% endfor %}
38
+ ]
39
+ LIQUID
40
+
41
+ class GeneratedPage < Jekyll::PageWithoutAFile
42
+ def initialize(site)
43
+ super(site, site.source, '', 'search.json')
44
+
45
+ self.content = TEMPLATE
46
+ data['layout'] = nil
47
+ data['permalink'] = '/search.json'
48
+ end
49
+ end
50
+
51
+ def apply(site)
52
+ return if custom_page?(site)
53
+
54
+ site.pages << GeneratedPage.new(site)
55
+ end
56
+
57
+ def custom_page?(site)
58
+ site.pages.any? { |page| search_index_path?(page.path) || search_index_url?(page.url) } ||
59
+ site.static_files.any? { |file| search_index_path?(file.path) || search_index_url?(file.relative_path) }
60
+ end
61
+
62
+ def search_index_path?(value)
63
+ return false unless value
64
+
65
+ Pathname.new(value.to_s).basename.to_s == 'search.json'
66
+ rescue ArgumentError
67
+ false
68
+ end
69
+
70
+ def search_index_url?(value)
71
+ value.to_s.strip == '/search.json'
72
+ end
73
+ end
74
+
6
75
  module LastUpdated
7
76
  module_function
8
77
 
@@ -160,6 +229,7 @@ end
160
229
  Jekyll::Hooks.register :site, :post_read do |site|
161
230
  Jekyll::VitePressTheme::VersionLabel.apply(site)
162
231
  Jekyll::VitePressTheme::RougeStyles.apply(site)
232
+ Jekyll::VitePressTheme::SearchIndex.apply(site)
163
233
  end
164
234
 
165
235
  Jekyll::Hooks.register :documents, :pre_render do |document, payload|
@@ -1,5 +1,5 @@
1
1
  module Jekyll
2
2
  module VitePressTheme
3
- VERSION = "1.2.1".freeze
3
+ VERSION = "1.2.2".freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-vitepress-theme
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carmine Paolino