sitepress-pagefind 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: db070f8c3379862fe48bc773ac0e7fdb00844f2511720788f11f46d05ba90e96
4
+ data.tar.gz: 26bb73b6d8e5d7efc4770973838d222f1e033a2d3c3e3f82c9ed375e3c0e8174
5
+ SHA512:
6
+ metadata.gz: a66f5bf3f6f3c2d20c5fb2eb185f4a25ce691219358927e5415bf6f94af64a39f70d299fe852da43470eb3f3f4e7e41ffc27869ec981f445c24186640e67dc4e
7
+ data.tar.gz: 6203881e2551d8db8f9b2d294ca33445f3c8da357336c5eee737bb442ddeb0656cac5bc67121036593981efd3d01ee4ce14d60f78071fb4c716439a0b4b73370
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright Julian Rubisch
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # Sitepress::Pagefind
2
+ A [Pagefind](https://pagefind.app/) integration for [Sitepress-Rails](https://sitepress.cc/getting-started/rails)
3
+
4
+ > [!IMPORTANT]
5
+ > For now, this plugin is intended to be used with a mounted Sitepress installation (i.e. `sitepress-rails`)
6
+
7
+ > [!CAUTION]
8
+ > For now the only tested case is one where no dynamic parts (i.e. those pertaining to a logged in user) are embedded in the static Sitepress pages.
9
+
10
+
11
+ ## Installation
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem "sitepress-pagefind"
16
+ ```
17
+
18
+ And then execute:
19
+ ```bash
20
+ $ bundle
21
+ ```
22
+
23
+ Then run the installer:
24
+
25
+ ```bash
26
+ $ bin/rails g sitepress:pagefind:install
27
+ ```
28
+
29
+ This installs
30
+ - the `@pagefind/default-ui` JavaScript package
31
+ - a Stimulus controller attachable to a `<dialog>`
32
+ - a template `_search` partial for your convenience.
33
+
34
+ ## Usage
35
+ To compile a Pagefind index, run the following rake task:
36
+
37
+ ```bash
38
+ $ bin/rails sitepress:pagefind:build
39
+ ```
40
+
41
+
42
+ This task will also be invoked by `assets:precompile` so you don't have to alter your build scripts.
43
+
44
+ > [!TIP]
45
+ > If you want to opt out of this behavior, just set the `SKIP_SITEPRESS_PAGEFIND_BUILD` environment variable.
46
+
47
+
48
+ ## License
49
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/setup"
2
+
3
+ APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
4
+ load "rails/tasks/engine.rake"
5
+
6
+ load "rails/tasks/statistics.rake"
7
+
8
+ require "bundler/gem_tasks"
File without changes
data/config/routes.rb ADDED
@@ -0,0 +1,2 @@
1
+ Rails.application.routes.draw do
2
+ end
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Explain the generator
3
+
4
+ Example:
5
+ bin/rails generate install Thing
6
+
7
+ This will create:
8
+ what/will/it/create
@@ -0,0 +1,24 @@
1
+ class Sitepress::Pagefind::InstallGenerator < Rails::Generators::Base
2
+ source_root File.expand_path("templates", __dir__)
3
+
4
+ def install_javascript_deps
5
+ # stimulus?
6
+ if File.exist? Rails.root.join("config", "importmap.rb")
7
+ say "Pinning @pagefind/default-ui"
8
+ run "bin/importmap pin @pagefind/default-ui"
9
+ else
10
+ say "Installing @pagefind/default-ui"
11
+ run "yarn add @pagefind/default-ui"
12
+ end
13
+ end
14
+
15
+ def copy_search_controller
16
+ say "Copying the Stimulus search controller"
17
+ copy_file "search_controller.js", "app/javascript/controllers/search_controller.js"
18
+ end
19
+
20
+ def copy_search_partial
21
+ say "Copying the template search partial"
22
+ copy_file "_search.html.erb", "app/views/pagefind/_search.html.erb"
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ class Sitepress::Pagefind::InstallGenerator < Rails::Generators::NamedBase
2
+ source_root File.expand_path("templates", __dir__)
3
+ end
@@ -0,0 +1,20 @@
1
+ <div data-controller="search">
2
+ <div data-search-target="button">
3
+ <div role="button" data-action="click->search#open keydown.meta+k@document->search#open keydown.ctrl+k@document->search#open" class="outline secondary search">
4
+ <span>Search</span>
5
+ <kbd>Cmd/Ctrl+K</kbd>
6
+ </div>
7
+
8
+ <dialog data-search-target="dialog">
9
+ <article>
10
+ <header>
11
+ <button aria-label="Close" rel="prev" data-action="search#close"></button>
12
+ <p>
13
+ <strong>Global Site Search</strong>
14
+ </p>
15
+ </header>
16
+ <div data-search-target="search"></div>
17
+ </article>
18
+ </dialog>
19
+ </div>
20
+ </div>
@@ -0,0 +1,21 @@
1
+ <li data-controller="search">
2
+ <div data-search-target="button">
3
+ <div role="button" data-action="click->search#open keydown.meta+k@document->search#open keydown.ctrl+k@document->search#open" class="outline secondary search">
4
+ <%= heroicon "magnifying-glass" %>
5
+ <span>Search</span>
6
+ <kbd>Cmd/Ctrl+K</kbd>
7
+ </div>
8
+
9
+ <dialog data-search-target="dialog">
10
+ <article>
11
+ <header>
12
+ <button aria-label="Close" rel="prev" data-action="search#close"></button>
13
+ <p>
14
+ <strong>Global Site Search</strong>
15
+ </p>
16
+ </header>
17
+ <div data-search-target="search"></div>
18
+ </article>
19
+ </dialog>
20
+ </div>
21
+ </li>
@@ -0,0 +1,28 @@
1
+ import { Controller } from "@hotwired/stimulus";
2
+ import { PagefindUI } from "@pagefind/default-ui";
3
+
4
+ // Connects to data-controller="search"
5
+ export default class extends Controller {
6
+ static targets = ["button", "dialog", "search"];
7
+
8
+ connect() {
9
+ this.search = new PagefindUI({
10
+ element: this.searchTarget,
11
+ highlightParam: "highlight",
12
+ autofocus: true,
13
+ showImages: false,
14
+ });
15
+ }
16
+
17
+ disconnect() {
18
+ this.search.destroy();
19
+ }
20
+
21
+ open() {
22
+ this.dialogTarget.showModal();
23
+ }
24
+
25
+ close() {
26
+ this.dialogTarget.close();
27
+ }
28
+ }
@@ -0,0 +1,6 @@
1
+ module Sitepress
2
+ module Pagefind
3
+ class Engine < ::Rails::Engine
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,9 @@
1
+ module Sitepress
2
+ module Pagefind
3
+ class Railtie < ::Rails::Railtie
4
+ rake_tasks do
5
+ load "tasks/sitepress/pagefind_tasks.rake"
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,6 @@
1
+ module Sitepress
2
+ module Pagefind
3
+ class Railtie < ::Rails::Railtie
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ module Sitepress
2
+ module Pagefind
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,8 @@
1
+ require "sitepress/pagefind/version"
2
+ require "sitepress/pagefind/engine"
3
+
4
+ module Sitepress
5
+ module Pagefind
6
+ # Your code goes here...
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ require "sitepress/pagefind/version"
2
+ require "sitepress/pagefind/railtie"
3
+
4
+ module Sitepress
5
+ module Pagefind
6
+ # Your code goes here...
7
+ end
8
+ end
@@ -0,0 +1,41 @@
1
+ namespace :sitepress do
2
+ namespace :pagefind do
3
+ desc "Compile the sitepress site and build a pagefind index"
4
+ task build: :environment do
5
+ site = Sitepress::Site.new(root_path: "app/content")
6
+ build_path = Rails.root.join("tmp/sitepress")
7
+ pagefind_output_path = Rails.root.join("public/pagefind")
8
+
9
+ if File.exist? build_path
10
+ puts "Purging output directory"
11
+ FileUtils.rm_r build_path
12
+ end
13
+
14
+ compiler = Sitepress::Compiler::Files.new(root_path: build_path, site:)
15
+
16
+ compiler.compile
17
+
18
+ puts <<~END
19
+
20
+ Building Pagefind Index
21
+
22
+ END
23
+
24
+ system "npx pagefind --site #{build_path} --output-path #{pagefind_output_path}"
25
+ end
26
+ end
27
+ end
28
+
29
+ unless ENV["SKIP_SITEPRESS_PAGEFIND_BUILD"]
30
+ if Rake::Task.task_defined?("assets:precompile")
31
+ Rake::Task["assets:precompile"].enhance(["sitepress:pagefind:build"])
32
+ end
33
+
34
+ if Rake::Task.task_defined?("test:prepare")
35
+ Rake::Task["test:prepare"].enhance(["sitepress:pagefind:build"])
36
+ elsif Rake::Task.task_defined?("spec:prepare")
37
+ Rake::Task["spec:prepare"].enhance(["sitepress:pagefind:build"])
38
+ elsif Rake::Task.task_defined?("db:test:prepare")
39
+ Rake::Task["db:test:prepare"].enhance(["sitepress:pagefind:build"])
40
+ end
41
+ end
@@ -0,0 +1,39 @@
1
+ namespace :sitepress do
2
+ namespace :pagefind do
3
+ desc "Compile the sitepress site and build a pagefind index"
4
+ task build: :environment do
5
+ site = Sitepress::Site.new(root_path: "app/content")
6
+ build_path = Rails.root.join("tmp/sitepress")
7
+ pagefind_output_path = Rails.root.join("public/pagefind")
8
+
9
+ puts "Purging output directory"
10
+ FileUtils.rm_r build_path
11
+
12
+ compiler = Sitepress::Compiler::Files.new(root_path: build_path, site:)
13
+
14
+ compiler.compile
15
+
16
+ puts <<~END
17
+
18
+ Building Pagefind Index
19
+
20
+ END
21
+
22
+ system "npx pagefind --site #{build_path} --output-path #{pagefind_output_path}"
23
+ end
24
+ end
25
+ end
26
+
27
+ unless ENV["SKIP_SITEPRESS_BUILD"]
28
+ if Rake::Task.task_defined?("assets:precompile")
29
+ Rake::Task["assets:precompile"].enhance(["sitepress:pagefind:build"])
30
+ end
31
+
32
+ if Rake::Task.task_defined?("test:prepare")
33
+ Rake::Task["test:prepare"].enhance(["sitepress:pagefind:build"])
34
+ elsif Rake::Task.task_defined?("spec:prepare")
35
+ Rake::Task["spec:prepare"].enhance(["sitepress:pagefind:build"])
36
+ elsif Rake::Task.task_defined?("db:test:prepare")
37
+ Rake::Task["db:test:prepare"].enhance(["sitepress:pagefind:build"])
38
+ end
39
+ end
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sitepress-pagefind
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Julian Rubisch
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-06-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '7'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: sitepress-core
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '4'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '4'
41
+ description: ''
42
+ email:
43
+ - julian@julianrubisch.at
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - MIT-LICENSE
49
+ - README.md
50
+ - Rakefile
51
+ - app/assets/config/sitepress_pagefind_manifest.js
52
+ - config/routes.rb
53
+ - lib/generators/sitepress/pagefind/install/USAGE
54
+ - lib/generators/sitepress/pagefind/install/install_generator.rb
55
+ - lib/generators/sitepress/pagefind/install/install_generator.rb~
56
+ - lib/generators/sitepress/pagefind/install/templates/_search.html.erb
57
+ - lib/generators/sitepress/pagefind/install/templates/_search.html.erb~
58
+ - lib/generators/sitepress/pagefind/install/templates/search_controller.js
59
+ - lib/sitepress/pagefind.rb
60
+ - lib/sitepress/pagefind.rb~
61
+ - lib/sitepress/pagefind/engine.rb
62
+ - lib/sitepress/pagefind/railtie.rb
63
+ - lib/sitepress/pagefind/railtie.rb~
64
+ - lib/sitepress/pagefind/version.rb
65
+ - lib/tasks/sitepress/pagefind_tasks.rake
66
+ - lib/tasks/sitepress/pagefind_tasks.rake~
67
+ homepage: https://github.com/julianrubisch/sitepress-pagefind
68
+ licenses:
69
+ - MIT
70
+ metadata:
71
+ homepage_uri: https://github.com/julianrubisch/sitepress-pagefind
72
+ source_code_uri: https://github.com/julianrubisch/sitepress-pagefind
73
+ post_install_message:
74
+ rdoc_options: []
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ requirements: []
88
+ rubygems_version: 3.5.6
89
+ signing_key:
90
+ specification_version: 4
91
+ summary: A Pagefind integration for Sitepress
92
+ test_files: []