# frozen_string_literal: truemoduleJekyllclassPageincludeConvertibleattr_writer:dirattr_accessor:basename,:content,:data,:ext,:name,:output,:pager,:sitealias_method:extname,:ext# Attributes for Liquid templatesATTRIBUTES_FOR_LIQUID=%w(
content
dir
excerpt
name
path
url
).freeze# A set of extensions that are considered HTML or HTML-like so we# should not alter them, this includes .xhtml through XHTM5.HTML_EXTENSIONS=%w(
.html
.xhtml
.htm
).freeze# Initialize a new Page.## site - The Site object.# base - The String path to the source.# dir - The String path between the source and the file.# name - The String filename of the file.definitialize(site,base,dir,name)@site=site@base=base@dir=dir@name=name@path=ifsite.in_theme_dir(base)==base# we're in a themesite.in_theme_dir(base,dir,name)elsesite.in_source_dir(base,dir,name)endprocess(name)read_yaml(PathManager.join(base,dir),name)generate_excerptifsite.config["page_excerpts"]data.default_proc=procdo|_,key|site.frontmatter_defaults.find(relative_path,type,key)endJekyll::Hooks.trigger:pages,:post_init,selfend# The generated directory into which the page will be placed# upon generation. This is derived from the permalink or, if# permalink is absent, will be '/'## Returns the String destination directory.defdirurl.end_with?("/")?url:url_dirend# The full path and filename of the post. Defined in the YAML of the post# body.## Returns the String permalink or nil if none has been set.defpermalinkdata.nil??nil:data["permalink"]end# The template of the permalink.## Returns the template String.deftemplateif!html?"/:path/:basename:output_ext"elsifindex?"/:path/"elseUtils.add_permalink_suffix("/:path/:basename",site.permalink_style)endend# The generated relative url of this page. e.g. /about.html.## Returns the String url.defurl@url||=URL.new(:template=>template,:placeholders=>url_placeholders,:permalink=>permalink).to_send# Returns a hash of URL placeholder names (as symbols) mapping to the# desired placeholder replacements. For details see "url.rb"defurl_placeholders{:path=>@dir,:basename=>basename,:output_ext=>output_ext,}end# Extract information from the page filename.## name - The String filename of the page file.## NOTE: `String#gsub` removes all trailing periods (in comparison to `String#chomp`)# Returns nothing.defprocess(name)returnunlessnameself.ext=File.extname(name)self.basename=name[0..-ext.length-1].gsub(%r!\.*\z!,"")end# Add any necessary layouts to this post## layouts - The Hash of {"name" => "layout"}.# site_payload - The site payload Hash.## Returns String rendered page.defrender(layouts,site_payload)site_payload["page"]=to_liquidsite_payload["paginator"]=pager.to_liquiddo_layout(site_payload,layouts)end# The path to the source file## Returns the path to the source filedefpathdata.fetch("path"){relative_path}end# The path to the page source file, relative to the site sourcedefrelative_path@relative_path||=PathManager.join(@dir,@name).delete_prefix("/")end# Obtain destination path.## dest - The String path to the destination dir.## Returns the destination file path String.defdestination(dest)@destination||={}@destination[dest]||=beginpath=site.in_dest_dir(dest,URL.unescape_path(url))path=File.join(path,"index")ifurl.end_with?("/")path<<output_extunlesspath.end_with?output_extpathendend# Returns the object as a debug String.definspect"#<#{self.class} @relative_path=#{relative_path.inspect}>"end# Returns the Boolean of whether this Page is HTML or not.defhtml?HTML_EXTENSIONS.include?(output_ext)end# Returns the Boolean of whether this Page is an index file or not.defindex?basename=="index"enddeftrigger_hooks(hook_name,*args)Jekyll::Hooks.trigger:pages,hook_name,self,*argsenddefwrite?trueenddefexcerpt_separator@excerpt_separator||=(data["excerpt_separator"]||site.config["excerpt_separator"]).to_senddefexcerptreturn@excerptifdefined?(@excerpt)@excerpt=data["excerpt"]?data["excerpt"].to_s:nilenddefgenerate_excerpt?!excerpt_separator.empty?&&instance_of?(Jekyll::Page)&&html?endprivatedefgenerate_excerptreturnunlessgenerate_excerpt?data["excerpt"]||=Jekyll::PageExcerpt.new(self)enddefurl_dir@url_dir||=beginvalue=File.dirname(url)value.end_with?("/")?value:"#{value}/"endendendend