lib/cosensee/page_store.rb in cosensee-0.6.0 vs lib/cosensee/page_store.rb in cosensee-0.8.0
- old
+ new
@@ -4,22 +4,33 @@
# require 'uri'
module Cosensee
# To search for pages
class PageStore
+ DEFAULT_PIN_TITLES = ['HOME'].freeze
+
+ extend Delegatable
+
def initialize(project:)
@project = project
@pages = project.pages
@pages_by_title = nil
@linking_pages = nil
@linked_pages = nil
+ @pin_titles = DEFAULT_PIN_TITLES.dup
end
+ attr_reader :pin_titles, :pages
+
def pages_by_title
- @pages_by_title ||= create_title_index(@pages)
+ @pages_by_title ||= create_title_index(pages)
end
+ def find_page_by_title(title)
+ pages_by_title[title]
+ end
+
def linking_pages
setup_link_indexes unless @linking_pages
@linking_pages
end
@@ -42,12 +53,24 @@
pages.each_with_object({}) do |page, hash|
hash[page.title] = page
end
end
+ def pinned_pages
+ pages_by_title.fetch_values(*pin_titles) { nil }.compact
+ end
+
def find_link_pages_by_title(title)
pages = linking_pages[title] + linked_pages[title]
- pages.sort_by(&:updated)
+ pages.sort_by(&:updated).uniq.reverse
+ end
+
+ def dump_search_data
+ pages.map do |page|
+ { title: page.title,
+ link: page.link_path,
+ summary: page.summary_text }
+ end
end
def setup_link_indexes
@linking_pages = Hash.new { |h, k| h[k] = [] }
@linked_pages = Hash.new { |h, k| h[k] = [] }