Skip to content
Snippets Groups Projects
Commit d54c9aa1 authored by pabois's avatar pabois
Browse files

regeneration pages

parent beb9b8a2
No related branches found
No related tags found
No related merge requests found
Showing with 55 additions and 30 deletions
......@@ -89,12 +89,14 @@ class Communication::Website::Page < ApplicationRecord
end
def git_dependencies(website)
[self] +
website.menus +
descendents +
active_storage_blobs +
siblings +
git_block_dependencies
dependencies = [self] +
website.menus +
descendents +
active_storage_blobs +
siblings +
git_block_dependencies
dependencies += website.education_programs if kind_education_programs?
dependencies
end
def git_destroy_dependencies(website)
......
......@@ -25,7 +25,7 @@ module Communication::Website::Page::WithKind
kind != nil
end
def is_not_special_page?
def is_regular_page?
!is_special_page?
end
......
......@@ -94,7 +94,7 @@ class Communication::Website::Post < ApplicationRecord
def url
return unless published
return if website.url.blank?
"#{website.url}#{website.index_for(:communication_posts).path}#{path}"
"#{website.url}#{website.special_page(:communication_posts).path}#{path}"
end
def to_s
......
......@@ -76,6 +76,22 @@ module Communication::Website::WithDependencies
end
# those tests has_xxx? should match the special page kind
def has_home?
true
end
def has_legal_terms?
true
end
def has_sitemap?
true
end
def has_privacy_policy?
true
end
def has_communication_posts?
posts.published.any?
end
......
......@@ -3,14 +3,17 @@ module Communication::Website::WithSpecialPages
included do
after_create :create_missing_special_pages
after_touch :create_missing_special_pages, :manage_special_pages_publication
def special_page(kind)
pages.where(kind: kind).first
end
def create_missing_special_pages
homepage = create_special_page('home')
# first level generic pages
['legal_terms', 'sitemap', 'privacy_policy'].each do |kind|
create_special_page(kind, homepage.id)
end
# first level pages with test
['communication_posts', 'education_programs', 'research_articles', 'research_volumes'].each do |kind|
['legal_terms', 'sitemap', 'privacy_policy', 'communication_posts', 'education_programs', 'research_articles', 'research_volumes'].each do |kind|
create_special_page(kind, homepage.id) if public_send("has_#{kind}?")
end
# team pages
......@@ -21,13 +24,11 @@ module Communication::Website::WithSpecialPages
end
end
end
# handle_async
def manage_special_pages_publication
current_special_pages_keys = pages.where.not(kind: nil).pluck(:kind).uniq
current_special_pages_keys.each do |kind|
state = !(respond_to?("has_#{kind}?") && !public_send("has_#{kind}?"))
pages.where(kind: kind).update_all(published: state)
special_pages_keys.each do |kind|
published = public_send("has_#{kind}?")
special_page(kind).update(published: published)
end
end
......@@ -37,6 +38,7 @@ module Communication::Website::WithSpecialPages
def create_special_page(kind, parent_id = nil)
i18n_key = "communication.website.pages.defaults.#{kind}"
# TODO: tmp should retrieve index_page (warning persons -> people) ,+ images/text
pages.where(kind: kind).first_or_create(
title: I18n.t("#{i18n_key}.title"),
slug: I18n.t("#{i18n_key}.slug"),
......@@ -47,5 +49,9 @@ module Communication::Website::WithSpecialPages
)
end
def special_pages_keys
@special_pages_keys ||= pages.where.not(kind: nil).pluck(:kind).uniq
end
end
......@@ -37,6 +37,7 @@ module WithGit
def sync_with_git
websites_for_self.each do |website|
website.touch
next unless website.git_repository.valid?
dependencies = git_dependencies(website).to_a.flatten.uniq.compact
dependencies.each do |object|
......
<% if @website.has_communication_posts? %>
posts: /<%= @website.index_for(:communication_posts).path %>/:year/:month/:day/:slug/
posts: <%= @website.special_page(:communication_posts).path %>/:year/:month/:day/:slug/
<% end %>
<% if @website.has_communication_categories? %>
categories: /<%= @website.index_for(:communication_posts).path %>/:slug/
categories: <%= @website.special_page(:communication_posts).path %>/:slug/
<% end %>
<% if @website.has_people? %>
persons: /<%= @website.index_for(:persons).path %>/:slug/
persons: <%= @website.special_page(:people).path %>/:slug/
<% end %>
<% if @website.has_authors? %>
authors: /<%= @website.index_for(:persons).path %>/:slug/<%= @website.index_for(:communication_posts).path %>/
authors: /<%= @website.special_page(:people).path %>/:slug/<%= @website.special_page(:communication_posts).slug %>/
<% end %>
<%# ces paths complémentaires sont nécessairesà Hugo mais on ne les utilise pas %>
<% if @website.has_administrators? %>
administrators: /<%= @website.index_for(:persons).path %>/:slug/roles/
administrators: /<%= @website.special_page(:people).path %>/:slug/roles/
<% end %>
<% if @website.has_teachers? %>
teachers: /<%= @website.index_for(:persons).path %>/:slug/programs/
teachers: /<%= @website.special_page(:people).path %>/:slug/programs/
<% end %>
<% if @website.has_researchers? %>
researchers: /<%= @website.index_for(:persons).path %>/:slug/articles/
researchers: /<%= @website.special_page(:people).path %>/:slug/articles/
<% end %>
......@@ -18,7 +18,7 @@
<%= f.association :related_category,
collection: collection_tree(@website.categories),
label_method: ->(p) { sanitize p[:label] },
value_method: ->(p) { p[:id] } if @website.categories.any? && page.is_not_special_page? %>
value_method: ->(p) { p[:id] } if @website.categories.any? && page.is_regular_page? %>
</div>
</div>
</div>
......@@ -36,7 +36,7 @@
class: 'js-slug-input',
data: { source: '#communication_website_page_title' }
} unless page.kind_home? %>
<%= f.input :published if page.is_not_special_page? %>
<%= f.input :published if page.is_regular_page? %>
<%= f.association :parent,
collection: collection_tree(@website.pages, page),
include_blank: false,
......
......@@ -25,7 +25,7 @@
<% end %>
<div class="btn-group ms-auto" role="group">
<%= edit_link page %>
<%= destroy_link page, confirm_message: page.children.any? ? t('please_confirm_with_children') : t('please_confirm') if page.is_not_special_page? %>
<%= destroy_link page, confirm_message: page.children.any? ? t('please_confirm_with_children') : t('please_confirm') if page.is_regular_page? %>
</div>
</div>
<ul class="list-unstyled treeview__children js-treeview-children <%= 'js-treeview-sortable-container' if can?(:reorder, page) %> ms-4" data-id="<%= page.id %>">
......
......@@ -90,7 +90,7 @@
<% end %>
<% content_for :action_bar_left do %>
<%= destroy_link @page if @page.is_not_special_page? %>
<%= destroy_link @page if @page.is_regular_page? %>
<%= link_to t('static'),
static_admin_communication_website_page_path(@page),
class: button_classes('btn-light') if current_user.server_admin? %>
......
......@@ -3,7 +3,7 @@
<% administrator_involvements = @about.involvements_through_roles.includes(:person).ordered_by_name %>
title: >
<%= @about.name %>
url: /<%= @website.index_for(:education_programs).path %><%= @about.path %>/
url: <%= @website.special_page(:education_programs).path %><%= @about.path %>/
description: >
<%= prepare_text_for_static @about.description %>
position: <%= @about.position %>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment