wip
This commit is contained in:
parent
f26733fa46
commit
7c4f7f2042
|
|
@ -587,12 +587,39 @@ module JamRuby
|
|||
end
|
||||
|
||||
# http://stackoverflow.com/questions/4308377/ruby-post-title-to-slug
|
||||
def sluggarize(field)
|
||||
field.downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '')
|
||||
#def sluggarize(field)
|
||||
# field.downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '')
|
||||
#end
|
||||
|
||||
|
||||
def sluggarize(text)
|
||||
# Convert to ASCII-friendly format
|
||||
text = Unicode.normalize_KD(text).encode("ASCII", replace: "").downcase
|
||||
|
||||
text.gsub!(/\s+/, "-") # Replace whitespace with '-'
|
||||
text.gsub!(/[:]+/, "-") # Replace : with '-'
|
||||
text.gsub!(/[&\+]+/, "and") # Replace & and + with 'and'
|
||||
text.gsub!(/['\",!?\(\)\=\#\+\*\.]/, "") # Remove quotes, commas, ?, and !
|
||||
text.gsub!(/[\-]+/, "-") # Replace consecutive dashes with a single '-'
|
||||
|
||||
# Ensure the slug doesn't start or end with a '-'
|
||||
if text.start_with?("-") || text.end_with?("-")
|
||||
text = text.gsub(/^-+|-+$/, "")
|
||||
end
|
||||
|
||||
# Warn if double dashes exist
|
||||
if text.include?("--")
|
||||
puts "Warning: Consecutive dashes found in slug '#{text}'"
|
||||
end
|
||||
|
||||
text
|
||||
end
|
||||
|
||||
def generate_slug
|
||||
self.slug = sluggarize(original_artist) + '-' + sluggarize(name)
|
||||
self.original_artist_slug = sluggarize(original_artist);
|
||||
self.name_slug = sluggarize(name)
|
||||
|
||||
|
||||
if licensor && licensor.slug.present?
|
||||
#raise "no slug on licensor #{licensor.id}" if licensor.slug.nil?
|
||||
|
|
|
|||
|
|
@ -1,13 +1,17 @@
|
|||
class AddNumResultsSeen < ActiveRecord::Migration
|
||||
def self.up
|
||||
execute("ALTER TABLE public.jam_tracks ADD COLUMN original_artist_slug VARCHAR UNIQUE;")
|
||||
execute("ALTER TABLE public.jam_tracks ADD COLUMN original_artist_slug VARCHAR;")
|
||||
execute("CREATE INDEX jam_tracks_original_artist_slug_index ON public.jam_tracks USING btree (original_artist_slug);");
|
||||
execute("ALTER TABLE public.jam_tracks ADD COLUMN name_slug VARCHAR;")
|
||||
execute("CREATE INDEX jam_tracks_name_slug_index ON public.jam_tracks USING btree (name_slug);");
|
||||
execute("ALTER TABLE public.jam_tracks ADD COLUMN origin_s3_path VARCHAR UNIQUE;")
|
||||
execute("ALTER TABLE public.jam_tracks ADD COLUMN origin_s3_bucket VARCHAR;")
|
||||
execute("ALTER TABLE public.jam_tracks ADD COLUMN s3_audio_dir VARCHAR;")
|
||||
|
||||
ALTER TABLE public.jam_tracks ADD COLUMN original_artist_slug VARCHAR UNIQUE;
|
||||
ALTER TABLE public.jam_tracks ADD COLUMN original_artist_slug VARCHAR;
|
||||
CREATE INDEX jam_tracks_original_artist_slug_index ON public.jam_tracks USING btree (original_artist_slug);
|
||||
ALTER TABLE public.jam_tracks ADD COLUMN name_slug VARCHAR;
|
||||
CREATE INDEX jam_tracks_name_slug_index ON public.jam_tracks USING btree (name_slug);
|
||||
ALTER TABLE public.jam_tracks ADD COLUMN origin_s3_path VARCHAR UNIQUE;
|
||||
ALTER TABLE public.jam_tracks ADD COLUMN origin_s3_bucket VARCHAR;
|
||||
ALTER TABLE public.jam_tracks ADD COLUMN s3_audio_dir VARCHAR;
|
||||
|
|
|
|||
Loading…
Reference in New Issue