5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2025-03-14 17:18:20 +00:00

Merge branch 'issue-3871' into 'rails'

permalinks #3871

See merge request sutty/sutty!290
This commit is contained in:
fauno 2025-01-27 18:35:41 +00:00
commit a4e687ebd5
5 changed files with 38 additions and 9 deletions

View file

@ -7,12 +7,25 @@ class MetadataPermalink < MetadataString
false
end
# Devuelve la URL actual del sitio
#
# @return [String, nil]
def default_value
if post.written?
super.presence || document.url
else
super.presence
end
end
private
# Al hacer limpieza, validamos la ruta. Eliminamos / multiplicadas,
# puntos suspensivos, la primera / para que siempre sea relativa y
# agregamos una / al final si la ruta no tiene extensión.
def sanitize(value)
return value.strip if value.blank?
value = value.strip.unicode_normalize.gsub('..', '/').gsub('./', '').squeeze('/')
value = value[1..-1] if value.start_with? '/'
value += '/' if File.extname(value).blank?

View file

@ -404,6 +404,19 @@ class Post
@usuaries ||= document_usuaries.empty? ? [] : Usuarie.where(id: document_usuaries).to_a
end
# Devuelve la URL absoluta
#
# @return [String, nil]
def absolute_url
return unless written?
@absolute_url ||=
URI.parse(site.url).tap do |uri|
uri.path = document.url
end.to_s
end
private
# Levanta un error si al construir el artículo no pasamos un atributo.

View file

@ -434,7 +434,9 @@ class Site < ApplicationRecord
# Si estamos usando nuestro propio plugin de i18n, los posts están
# en "colecciones"
locales.map(&:to_s).each do |i|
@configuration['collections'][i] = {}
@configuration['collections'][i] = {
'permalink' => configuration.send(:style_to_permalink, configuration['permalink'])
}
end
@configuration

View file

@ -1,3 +1,3 @@
%tr{ id: attribute }
%th= post_label_t(attribute, post: post)
%td{ dir: dir, lang: locale }= metadata.value
%td{ dir: dir, lang: locale }= link_to post.absolute_url, post.absolute_url, target: '_blank', rel: 'noopener'

View file

@ -1,7 +1,8 @@
.form-group
= label_tag "#{base}_#{attribute}", post_label_t(attribute, post: post)
= text_field base, attribute, value: metadata.value,
dir: dir, lang: locale,
**field_options(attribute, metadata)
= render 'posts/attribute_feedback',
post: post, attribute: attribute, metadata: metadata
- if post.written?
.form-group
= label_tag "#{base}_#{attribute}", post_label_t(attribute, post: post)
= text_field base, attribute, value: metadata.value,
dir: dir, lang: locale,
**field_options(attribute, metadata)
= render 'posts/attribute_feedback',
post: post, attribute: attribute, metadata: metadata