Skip to content

Commit 8293b57

Browse files
committed
gotta pad those strings people
1 parent a3f88d7 commit 8293b57

3 files changed

Lines changed: 15 additions & 9 deletions

File tree

lib/mix/tasks/publish_post.ex

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,32 @@ defmodule Mix.Tasks.PublishPost do
33

44
@impl Mix.Task
55
def run(_args) do
6-
{:ok, drafts} = File.ls("./drafts")
6+
{:ok, drafts} = File.ls("./drafts")
77

88
indexed_drafts = Enum.with_index(drafts, 1) |> Enum.map(fn {path, i} -> "#{i}. #{path}" end)
99

10-
IO.puts """
11-
Listing Draft posts:
12-
#{Enum.join(indexed_drafts, "\n")}
13-
"""
10+
IO.puts("""
11+
Listing Draft posts:
12+
#{Enum.join(indexed_drafts, "\n")}
13+
""")
1414

1515
index = get_draft()
1616
draft = Enum.at(drafts, index - 1)
1717

18-
IO.puts "Publishing #{draft}"
18+
IO.puts("Publishing #{draft}")
1919

2020
today = Date.utc_today()
2121

22-
File.cp!("./drafts/#{draft}", "./posts/#{today.year}/#{today.month}-#{today.day}-#{draft}")
22+
month = today.month |> to_string() |> String.pad_leading(2, "0")
23+
day = today.day |> to_string() |> String.pad_leading(2, "0")
24+
25+
File.cp!("./drafts/#{draft}", "./posts/#{today.year}/#{month}-#{day}-#{draft}")
2326
File.rm!("./drafts/#{draft}")
2427
end
2528

2629
def get_draft do
27-
IO.gets("Which draft post would you like to publish?: ") |> String.trim() |> String.to_integer()
30+
IO.gets("Which draft post would you like to publish?: ")
31+
|> String.trim()
32+
|> String.to_integer()
2833
end
29-
3034
end

lib/personal/post.ex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ defmodule Personal.Post do
1717
[year, month_day_id] = path |> Path.split() |> Enum.take(-2)
1818
path = path <> ".html"
1919
[month, day, id] = String.split(month_day_id, "-", parts: 3)
20+
month = String.pad_leading(month, 2, "0")
21+
day = String.pad_leading(day, 2, "0")
2022
date = Date.from_iso8601!("#{year}-#{month}-#{day}")
2123
struct!(__MODULE__, [id: id, date: date, body: body, path: path] ++ Map.to_list(attrs))
2224
end
File renamed without changes.

0 commit comments

Comments
 (0)