Skip to content

Commit b4efcbf

Browse files
authored
Revert "Add baseurl-aware Pagefind bundlePath tag for GitHub Pages project sites"
1 parent 5037613 commit b4efcbf

2 files changed

Lines changed: 6 additions & 63 deletions

File tree

‎README.md‎

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -109,23 +109,17 @@ Using the Default UI is still supported, but it is no longer Pagefind's primary
109109
You can add the Pagefind UI to any page with the following snippet. The `/pagefind/` directory, or the directory specified by `output_subdir` in the [config](#1-output_subdir), will be created along with its files.
110110

111111
```liquid
112-
<script src="{% pagefind_asset_url 'pagefind-ui.js' %}"></script>
113-
<link rel="stylesheet" href="{% pagefind_asset_url 'pagefind-ui.css' %}" />
112+
<script src="{{ '/pagefind/pagefind-ui.js' | relative_url }}"></script>
113+
<link rel="stylesheet" href="{{ '/pagefind/pagefind-ui.css' | relative_url }}" />
114114
115115
<div id="search"></div>
116116
<script>
117117
window.addEventListener('DOMContentLoaded', (event) => {
118-
new PagefindUI({
119-
element: "#search",
120-
showSubResults: true,
121-
bundlePath: "{% pagefind_bundle_path %}"
122-
});
118+
new PagefindUI({ element: "#search", showSubResults: true });
123119
});
124120
</script>
125121
```
126122

127-
`{% pagefind_asset_url 'filename' %}` and `{% pagefind_bundle_path %}` both handle all four combinations of `baseurl` and `output_subdir` being set or unset, so the snippet works correctly for root deployments, GitHub Pages project sites, and custom `output_subdir` values without any extra configuration.
128-
129123
For dark mode:
130124

131125
```css
@@ -142,15 +136,13 @@ For more details, see [Using the Default UI](https://pagefind.app/docs/ui-usage/
142136

143137
#### 2. Pagefind Component UI
144138

145-
Add the following snippet to `<head>`. The bundle directory specified by `output_subdir` in the [config](#1-output_subdir) (default: `pagefind`) will be created along with its files.
139+
Add the following snippet to `<head>`. The `/pagefind/` directory, or the directory specified by `output_subdir` in the [config](#1-output_subdir), will be created along with its files.
146140

147141
```liquid
148-
<script src="{% pagefind_asset_url 'pagefind-component-ui.js' %}" type="module"></script>
149-
<link rel="stylesheet" href="{% pagefind_asset_url 'pagefind-component-ui.css' %}" />
142+
<script src="{{ '/pagefind/pagefind-component-ui.js' | relative_url }}" type="module"></script>
143+
<link rel="stylesheet" href="{{ '/pagefind/pagefind-component-ui.css' | relative_url }}" />
150144
```
151145

152-
If you initialize the component via JavaScript, pass `bundlePath: "{% pagefind_bundle_path %}"` so the search bundle resolves correctly when `baseurl` is set.
153-
154146
For dark mode:
155147

156148
```html

‎lib/jekyll-pagefind.rb‎

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ module Jekyll
1111
# module Jekyll::Pagefind
1212
module Pagefind
1313
GEM_ROOT = File.expand_path("..", __dir__)
14-
DEFAULT_OUTPUT_SUBDIR = "pagefind"
1514

1615
def self.pagefind_binary_path # rubocop:disable Metrics/MethodLength,Metrics/PerceivedComplexity
1716
os = RbConfig::CONFIG["host_os"]
@@ -81,25 +80,6 @@ def self.build_cli_arguments(config) # rubocop:disable Metrics/MethodLength,Metr
8180
args.join(" ")
8281
end
8382

84-
def self.bundle_path(config)
85-
plugin_config = config["jekyll_pagefind"] || {}
86-
output_subdir = plugin_config.fetch("output_subdir", DEFAULT_OUTPUT_SUBDIR).to_s
87-
output_subdir = DEFAULT_OUTPUT_SUBDIR if output_subdir.empty?
88-
baseurl = config.fetch("baseurl", "").to_s
89-
90-
segments = [baseurl, output_subdir].filter_map do |segment|
91-
normalized = normalize_path_segment(segment)
92-
normalized unless normalized.empty?
93-
end
94-
95-
"/#{segments.join("/")}/"
96-
end
97-
98-
def self.normalize_path_segment(segment)
99-
segment.to_s.gsub(%r{\A/+|/+\z}, "")
100-
end
101-
private_class_method :normalize_path_segment
102-
10383
def self.run_pagefind(site_destination, extra_arguments = "") # rubocop:disable Metrics/MethodLength,Metrics/AbcSize
10484
binary = pagefind_binary_path
10585

@@ -129,35 +109,6 @@ def self.run_pagefind(site_destination, extra_arguments = "") # rubocop:disable
129109
raise "Pagefind binary exited with non-zero status code: #{status.exitstatus}"
130110
end
131111
end
132-
133-
# Liquid tag that emits a baseurl-aware Pagefind bundle path.
134-
class BundlePathTag < Liquid::Tag
135-
def render(context)
136-
site = context.registers[:site]
137-
return "/#{DEFAULT_OUTPUT_SUBDIR}/" unless site
138-
139-
Jekyll::Pagefind.bundle_path(site.config)
140-
end
141-
end
142-
143-
# Liquid tag that emits a full baseurl-aware URL for a Pagefind asset file.
144-
# Usage: {% pagefind_asset_url "pagefind-ui.js" %}
145-
# Handles all combinations of baseurl and output_subdir being set or unset.
146-
class AssetUrlTag < Liquid::Tag
147-
def initialize(tag_name, markup, tokens)
148-
super
149-
@filename = markup.strip.delete("'\"")
150-
end
151-
152-
def render(context)
153-
site = context.registers[:site]
154-
base = site ? Jekyll::Pagefind.bundle_path(site.config) : "/#{DEFAULT_OUTPUT_SUBDIR}/"
155-
"#{base}#{@filename}"
156-
end
157-
end
158-
159-
Liquid::Template.register_tag("pagefind_bundle_path", Jekyll::Pagefind::BundlePathTag)
160-
Liquid::Template.register_tag("pagefind_asset_url", Jekyll::Pagefind::AssetUrlTag)
161112
end
162113
end
163114

0 commit comments

Comments
 (0)