class JekyllPush::Site

Attributes

baseurl[R]
dir[R]
repo[R]

Public Class Methods

new(config = nil) click to toggle source

@param config [Hash] a site configuration hash

# File lib/jekyll_push/site.rb, line 10
def initialize(config = nil)
  @config   = config || JekyllPush.config_from_file
  @baseurl  = @config.fetch :baseurl, ''
  @repo     = @config.fetch :repo_name, ''
  @dir      = site_dir
rescue TypeError => e
  raise JekyllPush::Error::InvalidConfig, "An invalid (non-Hash) config was provided.\n#{e}"
end

Public Instance Methods

gh_baseurl() click to toggle source

Use the repostory name as the baseurl when publishing to GitHub pages if available

@return [String]

# File lib/jekyll_push/site.rb, line 28
def gh_baseurl
  if @repo.empty?
    warn Rainbow("Warning: Building the site without the 'repo_name' baseurl is not recommended when using GitHub pages.").yellow if @baseurl.empty?
    @baseurl
  else
    puts Rainbow("Rebuilding with baseurl '/#{@repo}'").cyan
    "/#{@repo}"
  end
end
rebuild(target) click to toggle source

Rebuild the Jekyll site @return [Nil]

# File lib/jekyll_push/site.rb, line 40
def rebuild(target)
  @baseurl = gh_baseurl if target == 'gh-pages'

  FileUtils.rm_r @dir if File.directory? @dir

  opts = Jekyll.configuration destination: @dir, baseurl: @baseurl
  Jekyll::Site.new(opts).process
end
site_dir() click to toggle source

@return [String]

# File lib/jekyll_push/site.rb, line 20
def site_dir
  File.join `pwd`.strip, '_site'
end