5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-16 20:36:21 +00:00

Merge branch 'paginacion' into staging

This commit is contained in:
f 2021-09-15 21:06:40 -03:00
commit b978f2a689
9 changed files with 71 additions and 39 deletions

View file

@ -69,6 +69,7 @@ gem 'terminal-table'
gem 'validates_hostname'
gem 'webpacker'
gem 'yaml_db', git: 'https://0xacab.org/sutty/yaml_db.git'
gem 'kaminari'
# database
gem 'hairtrigger'

View file

@ -309,6 +309,18 @@ GEM
jekyll-write-and-commit-changes (0.2.0)
jekyll (~> 4)
rugged (~> 1)
kaminari (1.2.1)
activesupport (>= 4.1.0)
kaminari-actionview (= 1.2.1)
kaminari-activerecord (= 1.2.1)
kaminari-core (= 1.2.1)
kaminari-actionview (1.2.1)
actionview
kaminari-core (= 1.2.1)
kaminari-activerecord (1.2.1)
activerecord
kaminari-core (= 1.2.1)
kaminari-core (1.2.1)
kramdown (2.3.1)
rexml
kramdown-parser-gfm (1.1.0)
@ -669,6 +681,7 @@ DEPENDENCIES
jekyll-data!
jekyll-images
jekyll-include-cache
kaminari
letter_opener
listen (>= 3.0.5, < 3.2)
loaf

View file

@ -21,7 +21,7 @@ class PostsController < ApplicationController
# más simple saber si hubo cambios.
if stale?([current_usuarie, site, filter_params])
# Todos los artículos de este sitio para el idioma actual
@posts = site.indexed_posts.where(locale: locale)
@posts = site.indexed_posts.where(locale: locale).page(filter_params.delete(:page))
# De este tipo
@posts = @posts.where(layout: filter_params[:layout]) if filter_params[:layout]
# Que estén dentro de la categoría
@ -151,7 +151,7 @@ class PostsController < ApplicationController
#
# @return [Hash]
def filter_params
@filter_params ||= params.permit(:q, :category, :layout).to_h.select { |_, v| v.present? }
@filter_params ||= params.permit(:q, :category, :layout, :page).to_h.select { |_, v| v.present? }
end
def site

View file

@ -56,7 +56,7 @@ class MetadataContent < MetadataTemplate
uri = URI element['src']
# No permitimos recursos externos
element.remove unless uri.hostname.end_with? Site.domain
element.remove unless uri.scheme == 'https' && uri.hostname.end_with?(Site.domain)
rescue URI::Error
element.remove
end

View file

@ -54,8 +54,7 @@ class Site < ApplicationRecord
# Guardar la configuración si hubo cambios
after_save :sync_attributes_with_config!
# El sitio en Jekyll
attr_reader :jekyll
accepts_nested_attributes_for :deploys, allow_destroy: true
# XXX: Es importante incluir luego de los callbacks de :load_jekyll
include Site::Index
@ -126,29 +125,28 @@ class Site < ApplicationRecord
# Trae los datos del directorio _data dentro del sitio
def data
unless @jekyll.data.present?
@jekyll.reader.read_data
# Define los valores por defecto según la llave buscada
@jekyll.data.default_proc = proc do |data, key|
data[key] = case key
when 'layout' then {}
end
unless jekyll.data.present?
run_in_path do
jekyll.reader.read_data
jekyll.data['layouts'] ||= {}
end
end
@jekyll.data
jekyll.data
end
# Traer las colecciones. Todos los artículos van a estar dentro de
# colecciones.
def collections
unless @read
@jekyll.reader.read_collections
run_in_path do
jekyll.reader.read_collections
end
@read = true
end
@jekyll.collections
jekyll.collections
end
# Traer la configuración de forma modificable
@ -236,7 +234,9 @@ class Site < ApplicationRecord
#
# @return [Hash]
def theme_layouts
@jekyll.reader.read_layouts
run_in_path do
jekyll.reader.read_layouts
end
end
# Trae todos los valores disponibles para un campo
@ -278,6 +278,12 @@ class Site < ApplicationRecord
status == 'building'
end
def jekyll
run_in_path do
@jekyll ||= Jekyll::Site.new(configuration)
end
end
# Cargar el sitio Jekyll
#
# TODO: En lugar de leer todo junto de una vez, extraer la carga de
@ -291,10 +297,7 @@ class Site < ApplicationRecord
def reload_jekyll!
reset
Dir.chdir(path) do
@jekyll = Jekyll::Site.new(configuration)
end
jekyll
end
def reload
@ -457,4 +460,8 @@ class Site < ApplicationRecord
errors.add(:design_id,
I18n.t('activerecord.errors.models.site.attributes.design_id.layout_incompatible.error'))
end
def run_in_path(&block)
Dir.chdir path, &block
end
end

View file

@ -40,7 +40,7 @@
%section.col
= render 'layouts/flash'
.d-flex.justify-content-between.align-items-center.pl-2-plus.pr-2-plus.mb-2
%form
%form{ action: site_posts_path }
- @filter_params.each do |param, value|
- next if param == 'q'
%input{ type: 'hidden', name: param, value: value }
@ -72,6 +72,8 @@
%thead
%tr
%th.border-0.background-white.position-sticky{ style: 'top: 0; z-index: 2', colspan: '4' }
.d-flex.flex-row.justify-content-between
%div
= submit_tag t('posts.reorder.submit'), class: 'btn'
%button.btn{ data: { action: 'reorder#unselect' } }
= t('posts.reorder.unselect')
@ -80,6 +82,10 @@
%button.btn{ data: { action: 'reorder#down' } }= t('posts.reorder.down')
%button.btn{ data: { action: 'reorder#top' } }= t('posts.reorder.top')
%button.btn{ data: { action: 'reorder#bottom' } }= t('posts.reorder.bottom')
%div
= link_to_prev_page @posts, t('posts.prev'), class: 'btn'
= link_to_next_page @posts, t('posts.next'), class: 'btn'
%tbody
- dir = t("locales.#{@locale}.dir")
- size = @posts.size
@ -104,19 +110,19 @@
%span{ lang: post.locale, dir: dir }= post.title
- if post.front_matter['draft'].present?
%span.badge.badge-primary= I18n.t('posts.attributes.draft.label')
- if post.front_matter['categories'].present?
%br
%small
- post.front_matter['categories'].each do |category|
= link_to @site.layouts[post.layout].humanized_name, site_posts_path(@site, **@filter_params.merge(layout: post.layout))
- post.front_matter['categories']&.each do |category|
= link_to site_posts_path(@site, **@filter_params.merge(category: category)) do
%span{ lang: post.locale, dir: dir }= category
= '/' unless post.front_matter['categories'].last == category
%td
%td.text-nowrap
= post.created_at.strftime('%F')
%br/
= post.order
%td
%td.text-nowrap
- if @usuarie || policy(post).edit?
= link_to t('posts.edit'), edit_site_post_path(@site, post.path), class: 'btn btn-block'
- if @usuarie || policy(post).destroy?

View file

@ -383,6 +383,8 @@ en:
en: 'English'
ar: 'Arabic'
posts:
prev: Previous page
next: Next page
empty: "There are no results for those search parameters."
caption: Post list
attribute_ro:

View file

@ -391,6 +391,8 @@ es:
en: 'inglés'
ar: 'árabe'
posts:
prev: Página anterior
next: Página siguiente
empty: No hay artículos con estos parámetros de búsqueda.
caption: Lista de artículos
attribute_ro:

View file

@ -61,6 +61,7 @@ Rails.application.routes.draw do
scope '(:locale)' do
post :'posts/reorder', to: 'posts#reorder'
resources :posts do
get 'p/:page', action: :index, on: :collection
get :preview, to: 'posts#preview'
end
end