~afontaine/home

e54bf56f3eb5daa1a2dbaac25ba687ec079c7e69 — Andrew Fontaine 8 months ago 4e6d71b
Add Slugging of Post Subjects

This will help to make nice vanity urls like /YY/MM/slugified-post-title
M apps/blog/lib/blog/blog/post.ex => apps/blog/lib/blog/blog/post.ex +4 -0
@@ 1,11 1,14 @@
defmodule Blog.Blog.Post do
  use Ecto.Schema
  import Ecto.Changeset
  import Slugy

  @derive {Phoenix.Param, key: :slug}
  schema "posts" do
    field :message_id, :string
    field :subject, :string
    field :text, :string
    field :slug, :string

    timestamps()
  end


@@ 15,5 18,6 @@ defmodule Blog.Blog.Post do
    post
    |> cast(attrs, [:subject, :text, :message_id])
    |> validate_required([:subject, :text, :message_id])
    |> slugify(:subject)
  end
end

M apps/blog/mix.exs => apps/blog/mix.exs +2 -1
@@ 39,7 39,8 @@ defmodule Blog.MixProject do
      {:phoenix_pubsub, "~> 2.0"},
      {:ecto_sql, "~> 3.4"},
      {:postgrex, ">= 0.0.0"},
      {:jason, "~> 1.0"}
      {:jason, "~> 1.0"},
      {:slugy, "~> 4.1"}
    ]
  end


A apps/blog/priv/repo/migrations/20210326032555_add_slug_to_posts.exs => apps/blog/priv/repo/migrations/20210326032555_add_slug_to_posts.exs +9 -0
@@ 0,0 1,9 @@
defmodule Blog.Repo.Migrations.AddSlugToPosts do
  use Ecto.Migration

  def change do
    alter table(:posts) do
      add :slug, :string
    end
  end
end

M mix.lock => mix.lock +1 -0
@@ 24,6 24,7 @@
  "plug_crypto": {:hex, :plug_crypto, "1.2.2", "05654514ac717ff3a1843204b424477d9e60c143406aa94daf2274fdd280794d", [:mix], [], "hexpm", "87631c7ad914a5a445f0a3809f99b079113ae4ed4b867348dd9eec288cecb6db"},
  "postgrex": {:hex, :postgrex, "0.15.8", "f5e782bbe5e8fa178d5e3cd1999c857dc48eda95f0a4d7f7bd92a50e84a0d491", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:db_connection, "~> 2.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm", "698fbfacea34c4cf22c8281abeb5cf68d99628d541874f085520ab3b53d356fe"},
  "ranch": {:hex, :ranch, "1.7.1", "6b1fab51b49196860b733a49c07604465a47bdb78aa10c1c16a3d199f7f8c881", [:rebar3], [], "hexpm", "451d8527787df716d99dc36162fca05934915db0b6141bbdac2ea8d3c7afc7d7"},
  "slugy": {:hex, :slugy, "4.1.0", "08dcc1c09937592d096a5625fe2644441eac00008c37a90d37f708a4fb8a86b7", [:mix], [{:ecto, "~> 3.5.7", [hex: :ecto, repo: "hexpm", optional: false]}], "hexpm", "d1d51741021ba459c1682f16f3f359f71ea09233c1e54dcf1ee67b3384d035db"},
  "telemetry": {:hex, :telemetry, "0.4.2", "2808c992455e08d6177322f14d3bdb6b625fbcfd233a73505870d8738a2f4599", [:rebar3], [], "hexpm", "2d1419bd9dda6a206d7b5852179511722e2b18812310d304620c7bd92a13fcef"},
  "telemetry_metrics": {:hex, :telemetry_metrics, "0.6.0", "da9d49ee7e6bb1c259d36ce6539cd45ae14d81247a2b0c90edf55e2b50507f7b", [:mix], [{:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "5cfe67ad464b243835512aa44321cee91faed6ea868d7fb761d7016e02915c3d"},
  "telemetry_poller": {:hex, :telemetry_poller, "0.5.1", "21071cc2e536810bac5628b935521ff3e28f0303e770951158c73eaaa01e962a", [:rebar3], [{:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "4cab72069210bc6e7a080cec9afffad1b33370149ed5d379b81c7c5f0c663fd4"},