mirror of
https://0xacab.org/sutty/sutty
synced 2025-02-21 11:01:47 +00:00
esconder el contenido si la ficha es solo metadatos #51
This commit is contained in:
parent
1219bd2ff1
commit
7e7b7e7450
2 changed files with 18 additions and 7 deletions
|
@ -22,7 +22,7 @@ class Post
|
||||||
# datos que no tienen que terminar en el front matter
|
# datos que no tienen que terminar en el front matter
|
||||||
REJECT_FROM_FRONT_MATTER = %w[date slug draft ext].freeze
|
REJECT_FROM_FRONT_MATTER = %w[date slug draft ext].freeze
|
||||||
# datos que no traemos del template
|
# datos que no traemos del template
|
||||||
REJECT_FROM_TEMPLATE = %w[date draft categories layout title ext tags date slug].freeze
|
REJECT_FROM_TEMPLATE = %w[has_content date draft categories layout title ext tags date slug].freeze
|
||||||
DEFAULT_PARAMS = [:title, :date, :content, :slug, :cover,
|
DEFAULT_PARAMS = [:title, :date, :content, :slug, :cover,
|
||||||
:layout, :permalink, :dir,
|
:layout, :permalink, :dir,
|
||||||
{ lang: {} }, { tags: [] }, { categories: [] }]
|
{ lang: {} }, { tags: [] }, { categories: [] }]
|
||||||
|
@ -185,6 +185,11 @@ class Post
|
||||||
@content ||= @post.try(:content) || template.try(:content)
|
@content ||= @post.try(:content) || template.try(:content)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Determina si el post lleva contenido o es solo front_matter
|
||||||
|
def content?
|
||||||
|
template.fetch_front_matter('has_content', true)
|
||||||
|
end
|
||||||
|
|
||||||
# imita Model.update_attributes de ActiveRecord
|
# imita Model.update_attributes de ActiveRecord
|
||||||
def update_attributes(attrs)
|
def update_attributes(attrs)
|
||||||
# el cuerpo se maneja por separado
|
# el cuerpo se maneja por separado
|
||||||
|
@ -225,6 +230,11 @@ class Post
|
||||||
@front_matter.dig(name.to_s)
|
@front_matter.dig(name.to_s)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Como get_front_matter pero con un valor por defecto
|
||||||
|
def fetch_front_matter(name, default)
|
||||||
|
@front_matter.fetch(name, default)
|
||||||
|
end
|
||||||
|
|
||||||
# Trae el template a partir del layout
|
# Trae el template a partir del layout
|
||||||
def template_from_layout
|
def template_from_layout
|
||||||
@site.templates.find do |t|
|
@site.templates.find do |t|
|
||||||
|
|
|
@ -28,12 +28,13 @@
|
||||||
.form-group
|
.form-group
|
||||||
= label_tag 'post_title', t('posts.title')
|
= label_tag 'post_title', t('posts.title')
|
||||||
= text_field 'post', 'title', value: @post.title, class: field_class, required: true
|
= text_field 'post', 'title', value: @post.title, class: field_class, required: true
|
||||||
.form-group{class: direction}
|
- if @post.content?
|
||||||
= render 'layouts/help', help: [ t('help.markdown.intro'),
|
.form-group{class: direction}
|
||||||
t('help.distraction_free_html'),
|
= render 'layouts/help', help: [ t('help.markdown.intro'),
|
||||||
t('help.preview_html') ]
|
t('help.distraction_free_html'),
|
||||||
= text_area_tag 'post[content]', @post.content, autofocus: true,
|
t('help.preview_html') ]
|
||||||
class: 'post-content'
|
= text_area_tag 'post[content]', @post.content, autofocus: true,
|
||||||
|
class: 'post-content'
|
||||||
.form-group
|
.form-group
|
||||||
= label_tag 'post_date', t('posts.date')
|
= label_tag 'post_date', t('posts.date')
|
||||||
= date_field 'post', 'date', value: @post.date.try(:strftime, '%F'),
|
= date_field 'post', 'date', value: @post.date.try(:strftime, '%F'),
|
||||||
|
|
Loading…
Reference in a new issue