mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-25 17:06:21 +00:00
61 lines
1.4 KiB
Ruby
61 lines
1.4 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require 'yaml'
|
|
require 'jekyll'
|
|
require_relative 'jekyll'
|
|
require_relative 'sutty/models/post'
|
|
|
|
# Sutty
|
|
module Sutty
|
|
# La raíz
|
|
def self.root
|
|
@root ||= File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
|
end
|
|
|
|
# La configuración
|
|
def self.settings
|
|
@settings ||= YAML.safe_load(File.read(Sutty.config_file))
|
|
end
|
|
|
|
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
|
|
|
|
# Comprueba que el directorio parezca ser de jekyll
|
|
def self.jekyll?(dir)
|
|
File.directory?(dir) && File.exist?(File.join(dir, '_config.yml'))
|
|
end
|
|
|
|
def self.sites
|
|
@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))
|
|
end
|
|
end
|