Tagged: elixir

Break Up String and Grab first 3 lines

test.ex
%{body: body} = BigSnips.Repo.get(BigSnips.Snippet, 2)
String.split(body, "\n")  |> 
Enum.take(3) |> 
Enum.join("\n")

an Elixir module to archive pages

archiver.ex
defmodule Archiver do                                                                                           
  def archive(url, user_id, bookmark_id) do                                                                                                       
    summary = Readability.summarize(url)                                                                                                          
    page = summary.article_html                                                                                                                   
    path = "priv/static/archive/#{user_id}"                                                                                                       
    unless File.exists?(path) do                                                                                                                  
      File.mkdir(path)                                                                                                                            
    end                                                                                                                                           
    File.write("#{path}/#{bookmark_id}.html", page)                                                                                               
  end                                                                                                                                             
end