mirror of
https://0xacab.org/sutty/sutty
synced 2025-03-16 07:38:19 +00:00
32 lines
986 B
Ruby
32 lines
986 B
Ruby
![]() |
# frozen_string_literal: true
|
||
|
|
||
|
# Lleva un registro de los permalinks de cada sitio y artículo
|
||
|
class Permalink < ApplicationRecord
|
||
|
belongs_to :permalinkeable, polymorphic: true
|
||
|
belongs_to :site
|
||
|
|
||
|
# La URL no se puede repetir dentro del sitio, pero puede existir la
|
||
|
# misma dentro de otro.
|
||
|
validates :url, presence: true, uniqueness: { scope: :site }
|
||
|
|
||
|
# Para poder traer todas las visitas de este post necesitamos filtrar
|
||
|
# primero por los hosts del sitio.
|
||
|
#
|
||
|
# TODO: Cambiar a request_uri para no tener que usar path
|
||
|
# TODO: Esto necesita que mergeemos origin-referer para tener acceso
|
||
|
# a los hostnames.
|
||
|
#
|
||
|
# @return [ActiveRecord::Relation]
|
||
|
def access_logs
|
||
|
AccessLog.where(host: site.hostnames).where(uri: [url, path])
|
||
|
end
|
||
|
|
||
|
# XXX: Esto podría servir para traer propiedades del archivo final en
|
||
|
# el sitio? Como espacio ocupado, tasa de compresión...
|
||
|
#
|
||
|
# @return [String]
|
||
|
def path
|
||
|
url.end_with?('/') ? "#{url}index.html" : url
|
||
|
end
|
||
|
end
|