Class: Jekyll::AmpPost

Inherits:
Page
  • Object
show all
Defined in:
lib/jekyll/amp_generate.rb

Overview

Defines the base class of AMP posts

Instance Method Summary collapse

Constructor Details

#initialize(site, base, dir, post) ⇒ AmpPost

Returns a new instance of AmpPost.


4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/jekyll/amp_generate.rb', line 4

def initialize(site, base, dir, post)
  @site = site
  @base = base
  @dir = dir
  # Needed for posts with permalink
  @url = dir
  @name = 'index.html'
  self.process(@name)
  self.read_yaml(File.join(base, '_layouts'), 'amp.html')
  self.content               = post.content
  self.data['body']          = (Liquid::Template.parse post.content).render site.site_payload

  # Merge all data from post so that keys from self.data have higher priority
  self.data = post.data.merge(self.data)

  # Remove non needed keys from data
  # Excerpt will cause an error if kept
  self.data.delete('excerpt')
  # Generating the page fails silently if page has a permalink and it is copied
  # over to the AMP version
  self.data.delete('permalink')

  self.data['canonical_url'] = post.url
end