Skip to content

Commit

Permalink
Editable slugs (SpinaCMS#570)
Browse files Browse the repository at this point in the history
* Add support for editable slugs

Make sure to run the migration
  • Loading branch information
Bramjetten authored Jun 23, 2020
1 parent 1a336eb commit ebcd144
Show file tree
Hide file tree
Showing 21 changed files with 211 additions and 20 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Spina CMS Changelog

## Unreleased
* Added support for custom slugs (remember to install the new migration)

## 1.1

### 1.1.4 (May 8, 2020)
Expand Down
10 changes: 5 additions & 5 deletions app/models/spina/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Page < ApplicationRecord

translates :title, fallbacks: true
translates :description, :materialized_path
translates :menu_title, :seo_title, default: -> { title }
translates :menu_title, :seo_title, :url_title, default: -> { title }

def to_s
name
Expand All @@ -51,8 +51,8 @@ def page_id
id
end

def url_title
title.try(:parameterize)
def slug
url_title&.parameterize
end

def custom_page?
Expand Down Expand Up @@ -115,9 +115,9 @@ def localized_materialized_path

def generate_materialized_path
if root?
name == 'homepage' ? '' : "#{url_title}"
name == 'homepage' ? '' : "#{slug}"
else
ancestors.collect(&:url_title).append(url_title).join('/')
ancestors.collect(&:slug).append(slug).join('/')
end
end

Expand Down
7 changes: 7 additions & 0 deletions app/views/spina/admin/pages/_form_page_seo.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
.horizontal-form-content
= f.text_field :description, placeholder: Spina::Page.human_attribute_name(:description_placeholder)

.horizontal-form-group
.horizontal-form-label
= Spina::Page.human_attribute_name :url_title
%small= Spina::Page.human_attribute_name :url_title_description
.horizontal-form-content
= f.text_field :url_title, placeholder: Spina::Page.human_attribute_name(:url_title_placeholder), value: f.object.url_title(fallback: false, default: nil)&.parameterize

- unless @page.new_record?
.horizontal-form-group
.horizontal-form-label
Expand Down
9 changes: 9 additions & 0 deletions config/locales/TH.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ th:
skip_to_first_child_description: ส่งต่อไปยังหน้าแรก
title: ชื่อเรื่อง
title_placeholder: ชื่อเรื่องของหน้า
url_title:
url_title_description:
url_title_placeholder:
view_template: เทมเพลตของเพจ
spina/resource:
label:
Expand Down Expand Up @@ -93,6 +96,7 @@ th:
spina:
ago: อายุ
attachments:
choose_attachment:
insert: แทรกเอกสาร
insert_multiple: แทรกเอกสาร
cancel: ยกเลิก
Expand All @@ -111,14 +115,17 @@ th:
success: คุณสามารถใช้รหัสผ่านใหม่ได้
unknown_user: ไม่มีผู้ใช้รายนี้
images:
all_images:
back:
cannot_be_created:
choose_image:
choose_images:
confirm_selection:
delete:
delete_confirmation:
delete_folder:
done_organizing:
insert_image:
insert_photo:
insert_photos:
link:
Expand Down Expand Up @@ -159,6 +166,8 @@ th:
information: ข้อมูล
login: คุณต้องเข้าสู่ระบบก่อน
wrong_username_or_password: อีเมลหรือรหัสผ่านไม่ถูกต้อง
options:
choose_option:
pages:
advanced: ขั้นสูง
change_order: เปลี่ยนออเดอร์
Expand Down
9 changes: 9 additions & 0 deletions config/locales/bg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ bg:
skip_to_first_child_description: Пренасочи към първата дъщерна страница
title: Заглавие
title_placeholder: Заглавие на страницата
url_title:
url_title_description:
url_title_placeholder:
view_template: Темплейт на страницата
spina/resource:
label: Етикет
Expand Down Expand Up @@ -93,6 +96,7 @@ bg:
spina:
ago: преди
attachments:
choose_attachment:
insert: Добавете документ
insert_multiple: Добавете документи
cancel: Спри
Expand All @@ -111,14 +115,17 @@ bg:
success: Вече може да използвате новата си парола
unknown_user: Този потребител не съществува
images:
all_images:
back:
cannot_be_created:
choose_image:
choose_images:
confirm_selection:
delete:
delete_confirmation:
delete_folder:
done_organizing:
insert_image:
insert_photo:
insert_photos:
link:
Expand Down Expand Up @@ -159,6 +166,8 @@ bg:
information: Информация
login: Трябва първо да влезете в системата
wrong_username_or_password: Грешен email или парола
options:
choose_option:
pages:
advanced: Разширени
change_order: Смяна на подредба
Expand Down
9 changes: 9 additions & 0 deletions config/locales/de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ de:
skip_to_first_child_description: Zur ersten Seite
title: Titel
title_placeholder: Seiten-Titel
url_title:
url_title_description:
url_title_placeholder:
view_template: Seiten-Template
spina/resource:
label:
Expand Down Expand Up @@ -93,6 +96,7 @@ de:
spina:
ago: vor
attachments:
choose_attachment:
insert: Dokument einfügen
insert_multiple: Dokumente einfügen
cancel: Abbrechen
Expand All @@ -111,14 +115,17 @@ de:
success: Du kannst dein neues Passwort verwenden
unknown_user: Dieser Nutzer existiert nicht
images:
all_images:
back:
cannot_be_created:
choose_image:
choose_images:
confirm_selection:
delete:
delete_confirmation:
delete_folder:
done_organizing:
insert_image:
insert_photo:
insert_photos:
link:
Expand Down Expand Up @@ -159,6 +166,8 @@ de:
information: Information
login: Du musst dich zuerst einloggen
wrong_username_or_password: Falsche E-Mail oder Passwort
options:
choose_option:
pages:
advanced: Erweitert
change_order: Reihenfolge ändern
Expand Down
9 changes: 9 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ en:
skip_to_first_child_description: Forward to first child page
title: Title
title_placeholder: Page title
url_title: Override slug
url_title_description: Optional
url_title_placeholder: Slug
view_template: Page template
spina/resource:
label: Label
Expand Down Expand Up @@ -93,6 +96,7 @@ en:
spina:
ago: ago
attachments:
choose_attachment: Choose attachment
insert: Insert document
insert_multiple: Insert documents
cancel: Cancel
Expand All @@ -111,14 +115,17 @@ en:
success: You can use your new password
unknown_user: This user does not exist
images:
all_images: All images
back: Back
cannot_be_created: Cannot be created
choose_image: Choose image
choose_images: Choose images
confirm_selection: Confirm selection
delete: Delete
delete_confirmation: Are you sure you want to delete this <strong>image</strong>?
delete_folder: Delete folder
done_organizing: Done organizing
insert_image: Insert image
insert_photo: Insert photo
insert_photos: Insert photos
link: Link
Expand Down Expand Up @@ -159,6 +166,8 @@ en:
information: Information
login: You have to login first
wrong_username_or_password: Wrong email or password
options:
choose_option: Choose option
pages:
advanced: Advanced
change_order: Change order
Expand Down
9 changes: 9 additions & 0 deletions config/locales/es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ es:
skip_to_first_child_description: Reenviar a la primera página hija
title: Título
title_placeholder: Título de la página
url_title:
url_title_description:
url_title_placeholder:
view_template: Plantilla de página
spina/resource:
label: Etiqueta
Expand Down Expand Up @@ -93,6 +96,7 @@ es:
spina:
ago: atrás
attachments:
choose_attachment:
insert: Insertar documento
insert_multiple: Insertar documentos
cancel: Cancelar
Expand All @@ -111,14 +115,17 @@ es:
success: Puede utilizar su nueva contraseña
unknown_user: Este usuario no existe
images:
all_images:
back: Regresar
cannot_be_created: No puede ser creada
choose_image: Elegir imagen
choose_images: Elegir imágenes
confirm_selection:
delete: Borrar
delete_confirmation: Esta seguro que desea borrar esta <strong>imagen</strong>?
delete_folder: Borrar carpeta
done_organizing:
insert_image:
insert_photo: Insertar foto
insert_photos: Insertar fotos
link: Enlace
Expand Down Expand Up @@ -159,6 +166,8 @@ es:
information: Información
login: Primero debes ingresar
wrong_username_or_password: Email o password incorrecto
options:
choose_option:
pages:
advanced: Avanzado
change_order: Cambiar orden
Expand Down
9 changes: 9 additions & 0 deletions config/locales/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ fr:
skip_to_first_child_description: Renvoyer vers la première page enfant
title: Titre
title_placeholder: Titre de la page
url_title:
url_title_description:
url_title_placeholder:
view_template: Modèle de page
spina/resource:
label:
Expand Down Expand Up @@ -93,6 +96,7 @@ fr:
spina:
ago: Il y a
attachments:
choose_attachment:
insert: Insérer un document
insert_multiple: Insérer des documents
cancel: Annuler
Expand All @@ -111,14 +115,17 @@ fr:
success: Vous pouvez utiliser votre nouveau mot de passe
unknown_user: Cet utilisateur n'existe pas
images:
all_images:
back:
cannot_be_created:
choose_image:
choose_images:
confirm_selection:
delete:
delete_confirmation:
delete_folder:
done_organizing:
insert_image:
insert_photo:
insert_photos:
link:
Expand Down Expand Up @@ -159,6 +166,8 @@ fr:
information: Information
login: Vous devez d'abord vous identifier
wrong_username_or_password: Mauvais email ou mot de passe
options:
choose_option:
pages:
advanced: Avancé
change_order: Changer l'ordre
Expand Down
9 changes: 9 additions & 0 deletions config/locales/id.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ id:
skip_to_first_child_description: Maju ke halaman anak pertama
title: Judul
title_placeholder: Judul halaman
url_title:
url_title_description:
url_title_placeholder:
view_template: Template halaman
spina/resource:
label:
Expand Down Expand Up @@ -93,6 +96,7 @@ id:
spina:
ago: lalu
attachments:
choose_attachment:
insert: Masukan dokumen
insert_multiple: Masukan dokumen
cancel: Batal
Expand All @@ -111,14 +115,17 @@ id:
success: Anda dapat menggunakan sandi baru anda
unknown_user: Pengguna ini tidak ada
images:
all_images:
back:
cannot_be_created:
choose_image:
choose_images:
confirm_selection:
delete:
delete_confirmation:
delete_folder:
done_organizing:
insert_image:
insert_photo:
insert_photos:
link:
Expand Down Expand Up @@ -159,6 +166,8 @@ id:
information: Informasi
login: Anda harus login dahulu
wrong_username_or_password: Salah e-mail atau sandi
options:
choose_option:
pages:
advanced: Lanjutan
change_order: Ubah urutan
Expand Down
Loading

0 comments on commit ebcd144

Please sign in to comment.