2018-01-29 22:19:10 +00:00
|
|
|
# Controlador de sitios
|
2018-01-29 18:09:30 +00:00
|
|
|
class SitesController < ApplicationController
|
|
|
|
before_action :authenticate!
|
|
|
|
|
2018-01-29 22:19:10 +00:00
|
|
|
# Ver un listado de sitios
|
2018-01-29 18:09:30 +00:00
|
|
|
def index
|
2018-01-29 22:19:10 +00:00
|
|
|
@sites = current_user.sites
|
|
|
|
end
|
|
|
|
|
|
|
|
# No tenemos propiedades de un sitio aún, así que vamos al listado de
|
|
|
|
# artículos
|
|
|
|
def show
|
|
|
|
site = find_site
|
|
|
|
|
|
|
|
redirect_to site_posts_path(site)
|
2018-01-29 18:09:30 +00:00
|
|
|
end
|
2018-02-20 17:47:11 +00:00
|
|
|
|
2018-07-02 22:07:06 +00:00
|
|
|
# Envía un archivo del directorio público de Jekyll
|
|
|
|
def send_public_file
|
|
|
|
@site = find_site
|
|
|
|
file = [params[:basename], params[:format]].join('.')
|
|
|
|
path = Pathname.new(File.join(@site.path, 'public', params[:type], file))
|
|
|
|
|
|
|
|
# TODO Verificar que no nos estén sacando archivos del sistema, como
|
|
|
|
# /etc/passwd
|
|
|
|
#
|
|
|
|
# En sí el matcher de la ruta no admite .. así que estaríamos semi
|
|
|
|
# cubiertas.
|
|
|
|
|
|
|
|
if path.exist?
|
|
|
|
send_file path, 'x-sendfile': true
|
|
|
|
else
|
|
|
|
render status: 404
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-02-20 17:47:11 +00:00
|
|
|
def enqueue
|
|
|
|
@site = find_site
|
|
|
|
@site.enqueue!
|
|
|
|
|
|
|
|
redirect_to sites_path
|
|
|
|
end
|
|
|
|
|
|
|
|
def build_log
|
|
|
|
@site = find_site
|
|
|
|
|
2018-04-30 18:51:39 +00:00
|
|
|
# TODO eliminar ANSI
|
2018-02-20 17:47:11 +00:00
|
|
|
render file: @site.build_log,
|
|
|
|
layout: false,
|
2018-04-30 17:22:31 +00:00
|
|
|
content_type: 'text/plain; charset=utf-8'
|
2018-02-20 17:47:11 +00:00
|
|
|
end
|
2018-04-30 18:51:39 +00:00
|
|
|
|
|
|
|
def reorder_posts
|
|
|
|
@site = find_site
|
|
|
|
lang = params.require(:posts).require(:lang)
|
|
|
|
|
2018-05-02 17:23:45 +00:00
|
|
|
if params[:posts][:force].present?
|
|
|
|
result = @site.reorder_collection! lang
|
|
|
|
else
|
|
|
|
result = @site.reorder_collection(lang, params.require(:posts).require(:order))
|
|
|
|
end
|
|
|
|
|
|
|
|
if result
|
2018-04-30 18:51:39 +00:00
|
|
|
flash[:info] = I18n.t('info.posts.reorder')
|
|
|
|
else
|
|
|
|
flash[:danger] = I18n.t('errors.posts.reorder')
|
|
|
|
end
|
|
|
|
|
|
|
|
redirect_to site_posts_path @site
|
|
|
|
end
|
2018-04-30 20:50:29 +00:00
|
|
|
|
2018-01-29 18:09:30 +00:00
|
|
|
end
|