     end
   end
 
+  defp date_pattern(format) do
+    case format do
+      :org -> ~r/#\+date: (?<date>[^\n]+)/i
+      :md -> ~r/^% (?<date>[^\n]+)/
+      :other -> nil
+    end
+  end
+
   defp is_valid_content(content) do
     is_map(content) and content["encoding"] == "base64" and content["type"] == "file"
   end

  defp parse_title(body, path) do
    default = "Title"
    pattern = title_pattern Article.format(path)
    if pattern do
      captured = Regex.named_captures(pattern, body, capture: :first)
      if captured, do: captured["title"], else: default
    else
      default
    end

      |> Enum.map(&(elem(&1, 1)))
      |> Enum.join
      title = parse_title body, path
      date = parse_date body, path
      article_params = %{body: body, published_at: date, path: path, sha: content["sha"], title: title}
      article = Repo.get_by(Article, family_id: family.id, path: path)
      if is_nil(article), do: article = %Article{author_id: author.id, family_id: family.id}
      Article.changeset(article, article_params)
