diff --git a/app/models/communication/website/permalink.rb b/app/models/communication/website/permalink.rb index bbf449be5f1c053b7c40c9995690538968f45a32..9cd67412359b19b16418b75d0ca17e88d8476ae8 100644 --- a/app/models/communication/website/permalink.rb +++ b/app/models/communication/website/permalink.rb @@ -83,12 +83,20 @@ class Communication::Website::Permalink < ApplicationRecord } end + def published_path + p = pattern + substitutions.each do |key, value| + p.gsub! ":#{key}", value + end + p + end + def published? # Can be overwritten true end - def published_path + def substitutions raise NotImplementedError end diff --git a/app/models/communication/website/permalink/post.rb b/app/models/communication/website/permalink/post.rb index f7dbdaa96e7861375fdc0296e277fa2fb359a117..812cb8439217ba79f2a770b2d41a1838e8ad0c86 100644 --- a/app/models/communication/website/permalink/post.rb +++ b/app/models/communication/website/permalink/post.rb @@ -19,9 +19,12 @@ class Communication::Website::Permalink::Post < Communication::Website::Permalin website.id == about.communication_website_id && about.published && about.published_at end - def published_path - pattern - .gsub(":year/:month/:day", about.published_at.strftime("%Y/%m/%d")) - .gsub(":slug", about.slug) + def substitutions + { + year: about.published_at.year, + month: about.published_at.month, + day: about.published_at.day, + slug: about.slug + } end end