5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-07-05 22:25:46 +00:00

Merge branch 'panel.sutty.nl' of https://0xacab.org/sutty/sutty into panel.sutty.nl

This commit is contained in:
Sutty 2023-05-13 21:00:00 +00:00
commit 398c223b0e
8 changed files with 123 additions and 60 deletions

View file

@ -58,7 +58,6 @@ gem 'inline_svg'
gem 'httparty' gem 'httparty'
gem 'safe_yaml' gem 'safe_yaml'
gem 'jekyll', '~> 4.2.0' gem 'jekyll', '~> 4.2.0'
gem 'jekyll-data'
gem 'jekyll-commonmark' gem 'jekyll-commonmark'
gem 'jekyll-images' gem 'jekyll-images'
gem 'jekyll-include-cache' gem 'jekyll-include-cache'

View file

@ -276,8 +276,6 @@ GEM
terminal-table (~> 2.0) terminal-table (~> 2.0)
jekyll-commonmark (1.4.0) jekyll-commonmark (1.4.0)
commonmarker (~> 0.22) commonmarker (~> 0.22)
jekyll-data (1.1.2)
jekyll (>= 3.3, < 5.0.0)
jekyll-images (0.4.0) jekyll-images (0.4.0)
jekyll (~> 4) jekyll (~> 4)
ruby-filemagic (~> 0.7) ruby-filemagic (~> 0.7)
@ -591,7 +589,6 @@ DEPENDENCIES
jbuilder (~> 2.5) jbuilder (~> 2.5)
jekyll (~> 4.2.0) jekyll (~> 4.2.0)
jekyll-commonmark jekyll-commonmark
jekyll-data
jekyll-images jekyll-images
jekyll-include-cache jekyll-include-cache
kaminari kaminari

View file

@ -30,7 +30,7 @@ class GitlabNotifierJob < ApplicationJob
count: 1, count: 1,
issue: @issue['iid'], issue: @issue['iid'],
user_agents: [user_agent].compact, user_agents: [user_agent].compact,
params: [request&.filtered_parameters].compact, params: request&.filtered_parameters&.as_json,
urls: [url].compact urls: [url].compact
} }
end end
@ -192,7 +192,7 @@ class GitlabNotifierJob < ApplicationJob
``` ```
#{request.request_method} #{url} #{request.request_method} #{url}
#{pp request.filtered_parameters} #{pp request.filtered_parameters.as_json}
``` ```
REQUEST REQUEST

View file

@ -0,0 +1,36 @@
# frozen_string_literal: true
module Jekyll
module Readers
# Permite leer datos utilizando rutas absolutas.
#
# {Jekyll::DataReader} usa {Dir.chdir} con rutas relativas, lo que
# en nuestro uso provoca confusiones en el lector de datos.
#
# Con este módulo, podemos leer todos los archivos usando rutas
# absolutas, lo que nos permite reemplazar jekyll-data, que agregaba
# código duplicado.
module DataReaderDecorator
extend ActiveSupport::Concern
included do
def read_data_to(dir, data)
return unless File.directory?(dir) && !@entry_filter.symlink?(dir)
Dir.glob(File.join(dir, '*')).each do |path|
next if @entry_filter.symlink?(path)
entry = Pathname.new(path).relative_path_from(dir).to_s
if File.directory?(path)
read_data_to(path, data[sanitize_filename(entry)] = {})
else
key = sanitize_filename(File.basename(entry, ".*"))
data[key] = read_data_file(path)
end
end
end
end
end
end
end

View file

@ -50,11 +50,6 @@ class Deploy < ApplicationRecord
site.path site.path
end end
# XXX: Ver DeployLocal#bundle
def gems_dir
@gems_dir ||= Rails.root.join('_storage', 'gems', site.name)
end
# Corre un comando, lo registra en la base de datos y devuelve el # Corre un comando, lo registra en la base de datos y devuelve el
# estado. # estado.
# #

View file

@ -7,6 +7,18 @@ class DeployLocal < Deploy
before_destroy :remove_destination! before_destroy :remove_destination!
def git_lfs(output: false)
run %(git lfs fetch), output: output
run %(git lfs checkout), output: output
end
def bundle(output: false)
# XXX: Desde que ya no compartimos el directorio de gemas, tenemos
# que hacer limpieza después de instalar.
run %(bundle install #{'--deployment' if site.gemfile_lock_path?} --no-cache --path="#{site.bundle_path}" --clean --without test development), output: output
end
# Realizamos la construcción del sitio usando Jekyll y un entorno # Realizamos la construcción del sitio usando Jekyll y un entorno
# limpio para no pasarle secretos # limpio para no pasarle secretos
# #
@ -55,7 +67,7 @@ class DeployLocal < Deploy
# #
# @return [nil] # @return [nil]
def cleanup! def cleanup!
FileUtils.rm_rf(gems_dir) FileUtils.rm_rf(site.bundle_path)
FileUtils.rm_rf(yarn_cache_dir) FileUtils.rm_rf(yarn_cache_dir)
FileUtils.rm_rf(File.join(site.path, 'node_modules')) FileUtils.rm_rf(File.join(site.path, 'node_modules'))
FileUtils.rm_rf(File.join(site.path, '.sass-cache')) FileUtils.rm_rf(File.join(site.path, '.sass-cache'))
@ -121,11 +133,6 @@ class DeployLocal < Deploy
run 'pnpm install --production', output: output run 'pnpm install --production', output: output
end end
def git_lfs(output: false)
run %(git lfs fetch), output: output
run %(git lfs checkout), output: output
end
def gem(output: false) def gem(output: false)
run %(gem install bundler --no-document), output: output run %(gem install bundler --no-document), output: output
end end
@ -137,13 +144,6 @@ class DeployLocal < Deploy
run 'yarn install --production', output: output run 'yarn install --production', output: output
end end
def bundle(output: false)
# XXX: Desde que ya no compartimos el directorio de gemas, tenemos
# que hacer limpieza después de instalar.
run %(bundle install --deployment --no-cache --path="#{gems_dir}" --clean --without test development), output: output
end
def jekyll_build(output: false) def jekyll_build(output: false)
run %(bundle exec jekyll build --trace --profile --destination "#{escaped_destination}"), output: output run %(bundle exec jekyll build --trace --profile --destination "#{escaped_destination}"), output: output
end end

View file

@ -212,10 +212,8 @@ class Site < ApplicationRecord
# Trae los datos del directorio _data dentro del sitio # Trae los datos del directorio _data dentro del sitio
def data def data
unless jekyll.data.present? unless jekyll.data.present?
run_in_path do jekyll.reader.read_data
jekyll.reader.read_data jekyll.data['layouts'] ||= {}
jekyll.data['layouts'] ||= {}
end
end end
jekyll.data jekyll.data
@ -225,9 +223,7 @@ class Site < ApplicationRecord
# colecciones. # colecciones.
def collections def collections
unless @read unless @read
run_in_path do jekyll.reader.read_collections
jekyll.reader.read_collections
end
@read = true @read = true
end end
@ -322,9 +318,7 @@ class Site < ApplicationRecord
# #
# @return [Hash] # @return [Hash]
def theme_layouts def theme_layouts
run_in_path do jekyll.reader.read_layouts
jekyll.reader.read_layouts
end
end end
# Trae todos los valores disponibles para un campo # Trae todos los valores disponibles para un campo
@ -375,9 +369,7 @@ class Site < ApplicationRecord
begin begin
install_gems install_gems
Jekyll::Site.new(configuration).tap do |site| Jekyll::Site.new(configuration)
site.reader = JekyllData::Reader.new(site) if site.theme
end
end end
end end
@ -461,6 +453,15 @@ class Site < ApplicationRecord
@docs = nil @docs = nil
end end
# @return [Pathname]
def bundle_path
@bundle_path ||= Rails.root.join('_storage', 'gems', name)
end
def gemfile_lock_path?
File.exist? gemfile_lock_path
end
private private
# Asegurarse que el sitio tenga una llave privada # Asegurarse que el sitio tenga una llave privada
@ -552,10 +553,6 @@ class Site < ApplicationRecord
I18n.t('activerecord.errors.models.site.attributes.design_id.layout_incompatible.error')) I18n.t('activerecord.errors.models.site.attributes.design_id.layout_incompatible.error'))
end end
def run_in_path(&block)
Dir.chdir path, &block
end
# Instala las gemas cuando es necesario: # Instala las gemas cuando es necesario:
# #
# * El sitio existe # * El sitio existe
@ -565,17 +562,28 @@ class Site < ApplicationRecord
def install_gems def install_gems
return unless persisted? return unless persisted?
deploys.find_by_type('DeployLocal').send(:git_lfs) deploy_local = deploys.find_by_type('DeployLocal')
deploy_local.git_lfs
if !gem_dir? || gemfile_updated? || gemfile_lock_updated? if !gems_installed? || gemfile_updated? || gemfile_lock_updated?
deploys.find_by_type('DeployLocal').send(:bundle) deploy_local.bundle
touch touch
end end
end end
def gem_path
@gem_path ||=
begin
ruby_version = Gem::Version.new(RUBY_VERSION)
ruby_version.canonical_segments[2] = 0
bundle_path.join('ruby', ruby_version.canonical_segments.join('.'))
end
end
# Detecta si el repositorio de gemas existe # Detecta si el repositorio de gemas existe
def gem_dir? def gems_installed?
Rails.root.join('_storage', 'gems', name).directory? gem_path.directory? && !gem_path.empty?
end end
# Detecta si el Gemfile fue modificado # Detecta si el Gemfile fue modificado
@ -583,8 +591,15 @@ class Site < ApplicationRecord
updated_at < File.mtime(File.join(path, 'Gemfile')) updated_at < File.mtime(File.join(path, 'Gemfile'))
end end
# @return [String]
def gemfile_lock_path
@gemfile_lock_path ||= File.join(path, 'Gemfile.lock')
end
# Detecta si el Gemfile.lock fue modificado # Detecta si el Gemfile.lock fue modificado
def gemfile_lock_updated? def gemfile_lock_updated?
updated_at < File.mtime(File.join(path, 'Gemfile.lock')) return false unless gemfile_lock_path?
updated_at < File.mtime(gemfile_lock_path)
end end
end end

View file

@ -2,6 +2,7 @@
String.include CoreExtensions::String::StripTags String.include CoreExtensions::String::StripTags
Jekyll::Document.include CoreExtensions::Jekyll::Document::Path Jekyll::Document.include CoreExtensions::Jekyll::Document::Path
Jekyll::DataReader.include Jekyll::Readers::DataReaderDecorator
# Definir tags de Liquid que provienen de complementos para que siempre # Definir tags de Liquid que provienen de complementos para que siempre
# devuelvan contenido vacío. # devuelvan contenido vacío.
@ -37,6 +38,19 @@ end
# #
# TODO: Aplicar monkey patches en otro lado... # TODO: Aplicar monkey patches en otro lado...
module Jekyll module Jekyll
Configuration.class_eval do
# No agregar colecciones por defecto, solo las que digamos en base a
# los idiomas. Esto remueve la colección "posts".
#
# Las colecciones de idiomas son agregadas por Site.
#
# @see Site#configuration
# @return [Jekyll::Configuration]
def add_default_collections
self
end
end
Site.class_eval do Site.class_eval do
def configure_theme def configure_theme
self.theme = nil self.theme = nil
@ -57,9 +71,27 @@ module Jekyll
# No necesitamos los archivos estáticos # No necesitamos los archivos estáticos
def retrieve_static_files(_, _); end def retrieve_static_files(_, _); end
# Solo lee los datos # Solo lee los datos, desde la plantilla y luego desde el sitio,
# usando rutas absolutas, para evitar el uso confuso de Dir.chdir.
#
# Reemplaza jekyll-data también!
#
# @return [Hash]
def read_data def read_data
@site.data = DataReader.new(site).read(site.config['data_dir']) @site.data =
begin
reader = DataReader.new(site)
theme_dir = site.in_theme_dir('_data')
data_dir = site.in_source_dir(site.config['data_dir'])
if theme_dir
reader.read_data_to(theme_dir, reader.content)
reader.read_data_to(data_dir, reader.content)
reader.content
else
reader.read data_dir
end
end
end end
# Lee los layouts # Lee los layouts
@ -161,14 +193,3 @@ module PgSearch
end end
end end
end end
# JekyllData::Reader del plugin jekyll-data modifica Jekyll::Site#reader
# para también leer los datos que vienen en el theme.
module JekyllData
Reader.class_eval do
def read_data
super
read_theme_data
end
end
end