2017-09-25 22:35:06 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-09-28 20:20:31 +00:00
|
|
|
require 'yaml'
|
2017-10-05 19:42:32 +00:00
|
|
|
require 'jekyll'
|
|
|
|
require_relative 'jekyll'
|
|
|
|
require_relative 'sutty/models/post'
|
2017-09-25 22:35:06 +00:00
|
|
|
|
2017-09-28 20:20:31 +00:00
|
|
|
# Sutty
|
2017-09-25 22:35:06 +00:00
|
|
|
module Sutty
|
2017-09-28 20:20:31 +00:00
|
|
|
# La raíz
|
|
|
|
def self.root
|
|
|
|
@root ||= File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
|
|
|
end
|
|
|
|
|
|
|
|
# La configuración
|
|
|
|
def self.settings
|
2017-10-05 19:42:32 +00:00
|
|
|
@settings ||= YAML.safe_load(File.read(Sutty.config_file))
|
2017-09-28 20:20:31 +00:00
|
|
|
end
|
2017-09-25 22:35:06 +00:00
|
|
|
|
2017-09-28 20:20:31 +00:00
|
|
|
def self.config_file
|
|
|
|
@config_file ||= File.join(Sutty.root, '_config.yml')
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.sites_dir
|
|
|
|
@sites_dir ||= File.join(Sutty.root, Sutty.settings['sites_dir'])
|
|
|
|
end
|
2017-09-25 22:35:06 +00:00
|
|
|
|
2017-10-05 19:42:32 +00:00
|
|
|
# Comprueba que el directorio parezca ser de jekyll
|
|
|
|
def self.jekyll?(dir)
|
|
|
|
File.directory?(dir) && File.exist?(File.join(dir, '_config.yml'))
|
|
|
|
end
|
|
|
|
|
2017-09-28 20:20:31 +00:00
|
|
|
def self.sites
|
2017-10-05 19:42:32 +00:00
|
|
|
@sites ||= Dir.entries('_sites/').map do |j|
|
|
|
|
# no queremos . ni .. ni archivos ocultos
|
|
|
|
next if j.start_with? '.'
|
|
|
|
|
|
|
|
j = Sutty.path_from_name(j)
|
|
|
|
next unless Sutty.jekyll? j
|
|
|
|
|
|
|
|
Dir.chdir(j) do
|
|
|
|
config = ::Jekyll.configuration('source' => Dir.pwd)
|
|
|
|
|
|
|
|
# No necesitamos cargar plugins en este momento
|
|
|
|
%w[plugins gems].each do |unneeded|
|
|
|
|
config[unneeded] = [] if config.key? unneeded
|
|
|
|
end
|
|
|
|
|
|
|
|
::Jekyll::Site.new(config)
|
|
|
|
end
|
|
|
|
end.compact
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.find(name)
|
|
|
|
Sutty.sites.select { |s| s.name == name }.first
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.path_from_name(name)
|
|
|
|
File.realpath(File.join(Sutty.sites_dir, name))
|
2017-09-25 22:35:06 +00:00
|
|
|
end
|
|
|
|
end
|