Skip to content

Commit

Permalink
Create generate_search_json.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyjurg authored Jul 12, 2024
1 parent 38d9ff0 commit 016ae00
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions docs/_plugins/generate_search_json.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
require 'json'

module Jekyll
class SearchJsonGenerator < Generator
safe true

def generate(site)
items = []
site.posts.docs.each do |post|
items << {
title: post.data['title'],
url: post.url,
content: post.content.gsub(/<\/?[^>]*>/, "") # Remove HTML tags
}
end

File.open('search.json', 'w') do |f|
f.write(JSON.pretty_generate(items))
end
end
end
end

0 comments on commit 016ae00

Please sign in to comment.