Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: Add search #454

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ jobs:
bundler-cache: true
cache-version: 2

- name: Set up Node
uses: actions/setup-node@v3
with:
node-version: 16

- name: Build & Validate
run: rake validate

Expand Down
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ RUN git config --global --add safe.directory /usr/src/docs && git config --globa

RUN gem install 'bundler:~>1' rake

RUN curl -fsSL https://deb.nodesource.com/setup_16.x | bash - && apt-get install -y nodejs

COPY . ./

RUN rake dependencies
Expand Down
10 changes: 3 additions & 7 deletions Rakefile
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a missing call to npm build-search-index in this file?

Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,15 @@ task :dependencies do
sh('bundle install --path gems')
end

sh('npm install')

# Fix pathutil on Ruby 3; works around https://github.com/envygeeks/pathutil/pull/5
# as suggested by https://stackoverflow.com/a/73909894/67873
pathutil_path = `bundle exec gem which pathutil`.strip()
content = File.read(pathutil_path).gsub(', kwd', ', **kwd')
File.write(pathutil_path, content)
end

task :spelling_dependencies do
sh('npm install')
end

file '_sass/brand/.git' do
sh('git submodule update --init')
end
Expand All @@ -42,8 +40,6 @@ task :build => [:dependencies, :submodules] do
sh('bundle exec jekyll build --config _config.yml')
end

task :build_spellings => [:build, :spelling_dependencies]

task :validate_kit_versions do
data = YAML.load_file('_data/kit_versions.yml')
data.each do |entry|
Expand Down Expand Up @@ -161,7 +157,7 @@ task :validate_sidebar_tree => [:build] do
puts "Sidebar links validated successfully"
end

task :validate_spellings => [:build_spellings] do
task :validate_spellings => [:build] do
sh('npm run spell-check')
end

Expand Down
1 change: 1 addition & 0 deletions _includes/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<meta name="description" content="{% if page.excerpt %}{{ page.excerpt | strip_html | strip_newlines | truncate: 160 }}{% else %}{{ site.description }}{% endif %}">

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.0/css/all.min.css" integrity="sha512-xh6O/CkQoPOWDdYTDqeRdPCVd1SpvCA9XXcUnZS2FmJNp1coAFzvtCN9BmamE+4aHK8yyUHUSCcJHgXloTyT2A==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<link href="{{ '/_pagefind/pagefind-ui.css' | prepend: site.baseurl }}" rel="stylesheet">
<link rel="stylesheet" href="{{ '/css/main.css' | prepend: site.baseurl }}">

{% if page.extra_css %}
Expand Down
2 changes: 2 additions & 0 deletions _includes/script.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@
<script>window.plausible = window.plausible || function() { (window.plausible.q = window.plausible.q || []).push(arguments) }</script>

<script src="{{ '/js/navigation.js' | prepend: site.baseurl }}"></script>
<script src="{{ '/_pagefind/pagefind-ui.js' | prepend: site.baseurl }}"></script>
<script src="{{ '/js/search.js' | prepend: site.baseurl }}"></script>
7 changes: 5 additions & 2 deletions _layouts/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,21 @@
---
<div class="header-card">
<div class="fixed-width">
<h1>Documentation</h1>
<h1 data-pagefind-meta="title:{{ page.title }}">Documentation</h1>
</div>
</div>
<div class="mobile-only mobile-index">
{% include sidebar.html %}
</div>
<div class="fixed-width">
<div id="search"></div>
</div>
<div class="main">
<div class="row fixed-width">
<div class="column m-3-12 desktop-only">
{% include sidebar.html %}
</div>
<div class="column m-9-12 doc">
<div class="column m-9-12 doc" data-pagefind-body>
{{ content }}
</div>
</div>
Expand Down
1 change: 0 additions & 1 deletion _sass/base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
}

html, body {
background: $sr-black;
font-family: $main-font-family;
font-size: 16px;
height: 100%;
Expand Down
17 changes: 17 additions & 0 deletions _sass/search.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
:root {
--pagefind-ui-scale: 0.8;
--pagefind-ui-primary: #{$sr-blue};
--pagefind-ui-text: #{$sr-black};
--pagefind-ui-border: #{$sr-medium-grey};
--pagefind-ui-tag: #{$sr-medium-grey};
--pagefind-ui-border-radius: 0px;
--pagefind-ui-border-width: 1px;
}

.pagefind-ui__search-clear {
border: none;
}

#search {
margin-top: $spacing;
}
3 changes: 2 additions & 1 deletion css/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
"docs",
"messages",
"footer",
"syntax-highlighting"
"syntax-highlighting",
"search"
;
17 changes: 17 additions & 0 deletions js/search.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
window.addEventListener('DOMContentLoaded', (event) => {
if (!window.PagefindUI) {
console.warn("Unable to initialize search - perhaps we're running locally");
return;
}

new PagefindUI({
element: "#search",
resetStyles: false,
processResult: function (result) {
// Remove the `.html` suffix
// `index.html` is already handled for us.
result.url = result.url.replace(".html", "")
return result;
}
});
});
109 changes: 108 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 4 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
{
"scripts": {
"test": "npm run spell-check",
"spell-check": "cspell"
"spell-check": "cspell",
"build-search-index": "pagefind"
},
"@comments": [
"These dependencies are only for testing the site.",
"The site is built with Jekyll so site dependencies should be in the Gemfile."
],
"dependencies": {
"cspell": "5.18.5"
"cspell": "5.18.5",
"pagefind": "^0.12.0"
}
Comment on lines 7 to 10
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're moving to actually building JS stuff here we should move cspell into devDependencies.

}
1 change: 1 addition & 0 deletions pagefind.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
source: ./_site