Compare commits

...
Sign in to create a new pull request.

1 commit

Author SHA1 Message Date
Chew
c3e99619ef
Sync to algolia 2022-02-20 18:55:26 -06:00
5 changed files with 134 additions and 5 deletions

39
.github/scripts/upload_algolia.rb vendored Normal file
View file

@ -0,0 +1,39 @@
require 'algolia'
require 'json'
APPLICATION_ID = ARGV[0]
API_KEY = ARGV[1]
puts "Building client..."
client = Algolia::Search::Client.create(APPLICATION_ID, API_KEY)
index = client.init_index('geyserwiki')
puts "Building jekyll..."
# Build the site
#`bundle exec jekyll build` Actions does this for us
# Grab the data.json
# @type [Array<Hash>]
data = JSON.parse(File.read('_site/search/data.json'))
#puts "Data is #{data}"
puts "Data is #{data.length}"
# Remove any data that url does not start with /floodgate, /geyser, or /other
data = data.delete_if { |d| !d['url'].start_with?('/floodgate', '/geyser', '/other') }
# Add ObjectID to each data item with the value of the ID
data = data.map do |d|
d['objectID'] = d['id']
d
end
#puts "Data is #{data}"
puts "Saving Objects"
index.save_objects(data)
puts "Done"

27
.github/workflows/algolia.yml vendored Normal file
View file

@ -0,0 +1,27 @@
name: Index Algolia
on:
push:
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repo content
uses: actions/checkout@v2
- name: Build Jekyll
run: |
jekyll build --trace --config _config.yml
- name: Setup Ruby
uses: ruby/setup-ruby@v2
with:
ruby-version: 3.0
bundler-cache: true
- name: Check permalinks
run: ruby .github/scripts/algolia.rb {{ secrets.ALGOLIA_APP_ID }} {{ secrets.ALGOLIA_API_KEY }}

View file

@ -16,8 +16,13 @@ source "https://rubygems.org"
# If you want to use GitHub Pages, remove the "gem "jekyll"" above and
# uncomment the line below. To upgrade, run `bundle update github-pages`.
gem "github-pages", group: :jekyll_plugins
gem 'webrick'
# If you have any plugins, put them here!
# group :jekyll_plugins do
# gem "jekyll-github-metadata", "~> 1.0"
# end
# Required for GitHub Pages
gem 'algolia'
gem 'json'

View file

@ -9,6 +9,10 @@ GEM
zeitwerk (~> 2.2, >= 2.2.2)
addressable (2.8.0)
public_suffix (>= 2.0.2, < 5.0)
algolia (2.2.2)
faraday (>= 0.15, < 2.0)
multi_json (~> 1.0)
net-http-persistent
coffee-script (2.4.1)
coffee-script-source
execjs
@ -17,6 +21,7 @@ GEM
commonmarker (0.17.13)
ruby-enum (~> 0.5)
concurrent-ruby (1.1.9)
connection_pool (2.2.5)
dnsruby (1.61.9)
simpleidn (~> 0.1)
em-websocket (0.5.3)
@ -25,7 +30,6 @@ GEM
ethon (0.15.0)
ffi (>= 1.15.0)
eventmachine (1.2.7)
eventmachine (1.2.7-x64-mingw32)
execjs (2.8.1)
faraday (1.9.3)
faraday-em_http (~> 1.0)
@ -51,7 +55,6 @@ GEM
faraday-rack (1.0.0)
faraday-retry (1.0.3)
ffi (1.15.5)
ffi (1.15.5-x64-mingw32)
forwardable-extended (2.6.0)
gemoji (3.0.1)
github-pages (223)
@ -219,6 +222,7 @@ GEM
gemoji (~> 3.0)
html-pipeline (~> 2.2)
jekyll (>= 3.0, < 5.0)
json (2.6.1)
kramdown (2.3.1)
rexml
kramdown-parser-gfm (1.1.0)
@ -234,12 +238,13 @@ GEM
jekyll-feed (~> 0.9)
jekyll-seo-tag (~> 2.1)
minitest (5.15.0)
multi_json (1.15.0)
multipart-post (2.1.1)
net-http-persistent (4.0.1)
connection_pool (~> 2.2)
nokogiri (1.13.1)
mini_portile2 (~> 2.7.0)
racc (~> 1.4)
nokogiri (1.13.1-x64-mingw32)
racc (~> 1.4)
octokit (4.22.0)
faraday (>= 0.9)
sawyer (~> 0.8.0, >= 0.5.3)
@ -277,8 +282,8 @@ GEM
unf (0.1.4)
unf_ext
unf_ext (0.0.8)
unf_ext (0.0.8-x64-mingw32)
unicode-display_width (1.8.0)
webrick (1.7.0)
zeitwerk (2.5.4)
PLATFORMS
@ -286,7 +291,10 @@ PLATFORMS
x64-mingw32
DEPENDENCIES
algolia
github-pages
json
webrick
BUNDLED WITH
2.2.32

50
pages/pages.json Normal file
View file

@ -0,0 +1,50 @@
---
title: Search
layout: none
sitemap: false
permalink: /search/data.json
not_editable: true
excluded_in_search: true
---
[
{% for post in site.docs %}
{% unless post.excluded_in_search %}
{% if added %},{% endif %}
{% assign added = false %}
{
"id": "{{ post.url | slugify }}",
"title": "{{ post.title | xml_escape }}",
"url": "{{ post.url | xml_escape }}",
"content": {{ post.content | strip_html | replace_regex: "[\s/\n]+"," " | strip | jsonify }}
}
{% assign added = true %}
{% endunless %}
{% endfor %}
{% for post in site.posts %}
{% unless post.excluded_in_search %}
{% if added %},{% endif %}
{% assign added = false %}
{
"id": "{{ post.url | slugify }}",
"title": "{{ post.title | xml_escape }}",
"url": "{{ post.url | xml_escape }}",
"content": {{ post.content | strip_html | replace_regex: "[\s/\n]+"," " | strip | jsonify }}
}
{% assign added = true %}
{% endunless %}
{% endfor %}
{% for post in site.pages %}
{% unless post.excluded_in_search %}
{% if added %},{% endif %}
{% assign added = false %}
{
"id": "{{ post.url | slugify }}",
"title": "{{ post.title | xml_escape }}",
"url": "{{ post.url | xml_escape }}",
"content": {{ post.content | strip_html | replace_regex: "[\s/\n]+"," " | strip | jsonify }}
}
{% assign added = true %}
{% endunless %}
{% endfor %}
]