Class: Jekyll::PaginateV2::AutoPages::BaseAutoPage

Inherits:
Jekyll::Page
  • Object
show all
Defined in:
lib/jekyll-paginate-v2/autopages/pages/baseAutoPage.rb

Direct Known Subclasses

CategoryAutoPage, CollectionAutoPage, TagAutoPage

Instance Method Summary collapse

Constructor Details

#initialize(site, base, autopage_config, pagination_config, layout_name, set_autopage_data_lambda, get_autopage_permalink_lambda, get_autopage_title_lambda, display_name) ⇒ BaseAutoPage

Returns a new instance of BaseAutoPage.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/jekyll-paginate-v2/autopages/pages/baseAutoPage.rb', line 5

def initialize(site, base, autopage_config, pagination_config, layout_name, set_autopage_data_lambda, get_autopage_permalink_lambda, get_autopage_title_lambda, display_name)
  @site = site
  @base = base
  @name = 'index.html'
          
  layout_dir = '_layouts'

  # Path is only used by the convertible module and accessed below when calling read_yaml
  # Handling themes stored in a gem
  @path = if site.in_theme_dir(site.source) == site.source # we're in a theme
            site.in_theme_dir(site.source, layout_dir, layout_name)
          else
            site.in_source_dir(site.source, layout_dir, layout_name)
          end
  
  self.process(@name) # Creates the base name and extension
  self.read_yaml(File.join(site.source, layout_dir), layout_name)

  # Merge the config with any config that might already be defined in the layout
  pagination_layout_config = Jekyll::Utils.deep_merge_hashes( pagination_config, self.data['pagination'] || {} )

  # Read any possible autopage overrides in the layout page
  autopage_layout_config = Jekyll::Utils.deep_merge_hashes( autopage_config, self.data['autopages'] || {} )
  
  # Now set the page specific pagination data
  set_autopage_data_lambda.call(pagination_layout_config)

  # Get permalink structure
  permalink_formatted = get_autopage_permalink_lambda.call(autopage_layout_config['permalink'])

  # Construct the title
  page_title = autopage_layout_config['title']
         
  # NOTE: Should we set this before calling read_yaml as that function validates the permalink structure 
  self.data['permalink'] = permalink_formatted
  @url = File.join(permalink_formatted, @name)
  @dir = permalink_formatted

  self.data['layout'] = File.basename(layout_name, File.extname(layout_name))
  self.data['title'] = get_autopage_title_lambda.call( page_title )
  self.data['pagination']  = pagination_layout_config # Store the pagination configuration

  # Add the auto page flag in there to be able to detect the page (necessary when figuring out where to load it from)
  # TODO: Need to re-think this variable!!!
  self.data['autopage'] = {"layout_path" => File.join( layout_dir, layout_name ), 'display_name' => display_name.to_s }

  data.default_proc = proc do |_, key|
    site.frontmatter_defaults.find(File.join(layout_dir, layout_name), type, key)
  end

  # Trigger a page event
  #Jekyll::Hooks.trigger :pages, :post_init, self
end